Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Object serialization: do not use a Map<string, Json> #90

Open
toburger opened this issue Sep 8, 2017 · 0 comments
Open

Object serialization: do not use a Map<string, Json> #90

toburger opened this issue Sep 8, 2017 · 0 comments

Comments

@toburger
Copy link

toburger commented Sep 8, 2017

I would suggest to use a list<string, Json> instead of a Map<string, Json>.
The usage is simpler by not having to use Map.ofList:

[ "id", String "user/42"
  "firstName", String "John"
  "lastName", String "Doe" ]
|> Object

The biggest problem with a Map is, that the field names get sorted alphabetically. This shouldn't be a big problem for the deserialization of the generated Json object, but you can't enforce the order of your object fields. So in the above example, "firstName" becomes the first field.

Drawback of a list is, that you could provide by accident a second field name with the exact same name (in a map, the last one wins), but as the writer of the serializer you are responsible for a correct serialization of your object anyways.

@toburger toburger changed the title Object serialization: do not use a Map<string, Json> Object deserialization: do not use a Map<string, Json> Sep 8, 2017
@toburger toburger changed the title Object deserialization: do not use a Map<string, Json> Object serialization: do not use a Map<string, Json> Sep 8, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant