[RFC] Implement custom iterator for JSONArray to ensure fetched values are JSON compliant

未关闭
#673 3 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

还没有人认领这个 Issue。

评估

难度
5/5
预计耗时
一周以上
新手友好度
25/100
Issue 类型
缺陷
描述清晰度
需要澄清
活跃度
停滞
技术栈
java
领域
backend

调研方向

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.

由索引模型根据 Issue 内容生成。

描述

Active discussion Fix before the next release

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:

  1. Implement a private/internal JSONArrayIterator class that would ensure any fetched values are properly "wrapped" and thus suitable output to JSON processors.
  2. Update all of our put* operations to ensure that all values are properly "wrapped" in both JSONObject and JSONArray. This would also allow us to simplify our toString methods 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?

主要语言
Java
星标
4.7k
派生
2.6k
平均合并
11 天 18 分钟
30 天内合并 PR
1

贡献指南

打开贡献指南

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

stleary/JSON-java 的其他 Issue

查看 stleary/JSON-java 的全部 Issue

相似的 Issue

更多 Java Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。