amazon-ion / ion-c

A C implementation of Amazon Ion.
https://amazon-ion.github.io/ion-docs/
Apache License 2.0
166 stars 43 forks source link

Fix two issues with JSON downconversion. #328

Closed nirosys closed 1 year ago

nirosys commented 1 year ago

Issue #, if available: N/A

Description of changes: This PR fixes two issues with JSON downconversion that were found while conducting performance comparison with JSON parsers.

The first issue presented when converting ion data with type annotations to JSON. While writing data with annotations, the writer would track the annotations for write but would never write them (as intended), which resulted in the annotations never being cleared. If enough annotations were contained in the original data to exceed the max annotations configured, further writes would result in an error.

This PR addresses this issue by not tracking annotations if we are in a JSON downconversion mode. Since we discard type annotations in this mode, there is no reason to track them in the writer.

The second issue presented when serializing a double in a container, while in JSON downconversion mode. The function implemented to serialize doubles into a json format did not account for the separator required in containers which would result in an invalid serialization like: [1.01.0], rather than [1.0,1.0].

Unit tests have been added for both fixes.


By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.