Serialize primitives to json
Refactor serializer