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.
I would suggest to use a
list<string, Json>
instead of aMap<string, Json>
. The usage is simpler by not having to useMap.ofList
: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.