Templatized serializer and deserializer