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

issue #1780 (支持org.json.JSONObject )的两种解决方案 #2702

Merged
merged 1 commit into from
Sep 4, 2019

Conversation

Omega-Ariston
Copy link
Collaborator

关于issue #1780,感觉有两个思路

  1. fastjson内部支持org.json.JSONObject序列化,添加相应的Codec,涉及的文件有:
    pom.xml
    src/main/java/com/alibaba/fastjson/serializer/JSONObjectCodec.java
    src/main/java/com/alibaba/fastjson/serializer/SerializeConfig.java
    测试用例是:
    src/test/java/com/alibaba/json/bvt/issue_1700/Issue1780_JSONObject.java

  2. 使用现有的Module功能来自定义解析器,而不是框架去兼容,只要修改:
    pom.xml添加 org.json.JSONObject支持
    使用示例是:
    src/test/java/com/alibaba/json/bvt/issue_1700/Issue1780_Module.java

个人建议这种特殊场景让用户自定义就好了,采用方案二 0-0
@wenshao PTAL

@Omega-Ariston Omega-Ariston changed the title issue #1780 的两种解决方案 issue #1780 (支持org.json.JSONObject )的两种解决方案 Sep 4, 2019
@codecov-io
Copy link

Codecov Report

Merging #2702 into master will decrease coverage by <.01%.
The diff coverage is 68.42%.

Impacted file tree graph

@@             Coverage Diff              @@
##             master    #2702      +/-   ##
============================================
- Coverage     80.43%   80.42%   -0.01%     
- Complexity     7084     7089       +5     
============================================
  Files           144      145       +1     
  Lines         26683    26702      +19     
  Branches       6368     6370       +2     
============================================
+ Hits          21462    21475      +13     
- Misses         3386     3390       +4     
- Partials       1835     1837       +2
Impacted Files Coverage Δ Complexity Δ
...m/alibaba/fastjson/serializer/SerializeConfig.java 79.36% <50%> (-0.41%) 133 <0> (+1)
...m/alibaba/fastjson/serializer/JSONObjectCodec.java 76.92% <76.92%> (ø) 3 <3> (?)
...com/alibaba/fastjson/serializer/SerialContext.java 72.91% <0%> (-4.17%) 19% <0%> (ø)
...main/java/com/alibaba/fastjson/util/TypeUtils.java 79.81% <0%> (+0.11%) 622% <0%> (+1%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update ed7bf6e...22abbf7. Read the comment docs.

@wenshao wenshao merged commit 90998d5 into alibaba:master Sep 4, 2019
@Omega-Ariston Omega-Ariston deleted the fix-issue1780 branch September 4, 2019 11:00
@lotosbin
Copy link

lotosbin commented Sep 9, 2024

JSONObjectCodec.java is not working on android,
org.json.JSONObject do not have map field in android sdk,
we should not use reflect to implement JSONObjectCodec.

In addition, we should not catch exception and only write null, which will cause a very serious problem.

ref: #1780

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

Successfully merging this pull request may close these issues.

4 participants