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

[json]: Improve Handling of Empty JSON Arrays in JSON::ArrayType #1787

Open
wants to merge 2 commits into
base: R2
Choose a base branch
from

Conversation

arjun-tata
Copy link
Contributor

This PR refines JSON::ArrayType to ensure consistent handling of empty JSON arrays during both serialization and deserialization. The first enhancement introduces a Set method to serialize an empty array as "fieldName": [], indicating that a field is explicitly set, even if it contains no data. Additionally, this PR addresses an issue in deserialization where an empty array (someArray: []) was previously interpreted as null. With the new changes, the deserialization process now correctly identifies and preserves empty arrays, maintaining a clear distinction from null values. These improvements standardize empty array handling in JSON::ArrayType

pwielders and others added 2 commits October 30, 2024 11:11
…n. (rdkcentral#1112)

Using the new method Set on the JSON::ArrayType<> template, the array can be set to Serialize although there are
no elements available in the array. The Serialization will show like: "fieldName": []
This can be used to indicate that a field has been set but there is no data for this field.
…tral#1448)

 In the context of the JSON::ArrayType type, a previous change was
 added for the serialization of empty array ie: to differentiate
 between a set but empty and a null JSON array container. The
 resulting implementation, however, failed to deserialize properly,
 because when finding a empty JSON array (i.e. `someArray: []`), the
 resulting object would be equivalent to `someArray: null`, which is
 incorrect.

 To fix this, this commit adds the setting of the `_state` data member
 in the `Deserialize` method when a matching pair of square brackets are
 correctly parsed.
@pwielders pwielders added the R2 Pull request for R2 label Nov 1, 2024
@pwielders
Copy link
Contributor

I guess this is a backport from R4 to R2. For me good to go..

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
R2 Pull request for R2
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants