[RFC] Implement custom iterator for JSONArray to ensure fetched values are JSON compliant
Nobody has claimed this yet.
Assessment
- Difficulty
- 5/5
- Estimated time
- Over a week
- Newbie friendliness
- 25/100
Research direction
Start with JSONArray.iterator and review the related behavior in JSONObject, JSONArray put* operations, and toString methods; issue #672 provides the referenced context. Decide between lazy iterator wrapping and proactive wrapping during insertion, then verify that code-built values exposed to JSON processors are compliant without changing parsed objects.
Written by the indexing model from the issue text.
Description
This has been a "known" issue for some time, but as mentioned in #672, the JSONArray.iterator method is exposing the raw values from the backing array instead of JSON-compliant values.
We should do 1 of 2 things:
- Implement a private/internal
JSONArrayIteratorclass that would ensure any fetched values are properly "wrapped" and thus suitable output to JSON processors. - Update all of our
put*operations to ensure that all values are properly "wrapped" in bothJSONObjectandJSONArray. This would also allow us to simplify ourtoStringmethods and remove the wrapping from there as all values should be proper JSON.
Option 1 keeps the wrapping "lazy" and thus would only guarantee JSON compliance on values that are fetched. Fetching a non-wrapped value multiple times would cause wrapping to happen each time.
Option 2 makes the wrapping more proactive; guaranteeing that our JSON compliance happens up-front even if the value is not fetched later. Fetching an initially non-wrapped value multiple times would cause NO wrapping to happen at fetch as it would have been pre-wrapped by the put operation.
Both options only affect code-built JSONObjects/Arrays. Parsed objects would be unaffected as the parser is only placing JSON-compliant values in the backing collections.
Thoughts on whether we should implement either option, something else, or neither?
- Dominant language
- Java
- Stars
- 4.7k
- Forks
- 2.6k
- Avg merge
- 11d 18m
- Merged PRs (30d)
- 1
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from stleary/JSON-java
-
Fix before the next release
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
-
Difficulty 2/5 1-3 hours Newbie friendliness 76/100
-
Difficulty 2/5 1-3 hours Newbie friendliness 88/100
-
Difficulty 2/5 1-3 hours Newbie friendliness 82/100
-
Fix before the next release
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
All issues in stleary/JSON-java
Similar issues
-
Bug Java Platform: Java
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
getsentry/sentry-java#6138 · 1 comment ·
-
bug needs triage p2
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
GoogleCloudPlatform/DataflowTemplates#4273 · 1 comment ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
-
Difficulty 2/5 1-3 hours Newbie friendliness 76/100
-
bug needs triage
Difficulty 2/5 1-3 hours Newbie friendliness 76/100