made the typeserializer type-safe and eliminate need for casting

Signed-off-by: Andrew Grosner <andrew.grosner@raizlabs.com>