Instagram / ig-json-parser

Fast JSON parser for java projects
https://instagram-engineering.com/fast-auto-generated-streaming-json-parsing-for-android-ab8e7be21033
MIT License
1.32k stars 125 forks source link

Add subobject name serializer param #53

Closed jingibus closed 6 years ago

jingibus commented 6 years ago

Adds a ${subobject} parameter for serializeCodeFormatter. For objects, this parameter is equivalent to ${object_varname}.${field_varname} in a field context, or ${iterator} in a collection context.

This is much needed by the interface PR; without a feature like this, it's impossible to write one serializeCodeFormatter that can be used in both collections and field references.

If a better name is possible for this parameter, it can easily be extended to scalars, since the idea is the same. But with the name ${subobject}, those did not seem to be appropriate semantics.

This PR also includes a fix in import generation in JsonParserClassData.getJsonCode that was breaking list references in the test code.

kangzhang commented 6 years ago

Looks good! Per offline discussion, we may want to differentiate the serializeCodeFormatter's behavior in JsonType and JsonField to avoid some potential confusion. It can be tracked separately.