ref-refactoring: refactor JSON encoding/decoding to a separate serializer