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

Fix #3672 #3675

Closed
wants to merge 7 commits into from
Closed

Fix #3672 #3675

wants to merge 7 commits into from

Conversation

Certseeds
Copy link
Contributor

@Certseeds Certseeds commented Mar 9, 2021

fix #3672
in ObjectArrayCodec.java if use PrettyFormat, Do not transferarray id to write(), so it will appear "null"
原有逻辑

for (int i = 0; i < size; ++i) {
    if (i != 0) {
        out.write(',');
        serializer.println();
    }
    serializer.write(array[i]);
}

没有传fieldName过去
现有逻辑

for (int i = 0; i < size; ++i) {
    if (i != 0) {
        out.write(',');
        serializer.println();
    }
    Object item = array[i];
    if (serializer.containsReference(item)) {
        serializer.writeReference(item);
    } else {
        serializer.writeWithFieldName(item, i);
    }
}

PS:
这里serializer.containsReference(item) == false内,改成

Class<?> clazz = item.getClass();
if (clazz != preClazz) {
    preClazz = clazz;
    preWriter = serializer.getObjectWriter(clazz);
}
    preWriter.write(serializer, item, i, null, 0);

是否会有性能提升?

… transfer

array id to write(), so it will appear null.

<type>:
- [x] Bug fix
- [x] This change requires a documentation update

Signed-off-by: Certseeds <51754303+Certseeds@users.noreply.github.com>
@codecov-io
Copy link

Codecov Report

Merging #3675 (c1a8acf) into master (e4308b7) will decrease coverage by 0.01%.
The diff coverage is 66.66%.

Impacted file tree graph

@@             Coverage Diff              @@
##             master    #3675      +/-   ##
============================================
- Coverage     80.32%   80.31%   -0.02%     
+ Complexity     7498     7495       -3     
============================================
  Files           157      157              
  Lines         28012    28014       +2     
  Branches       6762     6763       +1     
============================================
- Hits          22502    22500       -2     
- Misses         3487     3490       +3     
- Partials       2023     2024       +1     
Impacted Files Coverage Δ Complexity Δ
.../alibaba/fastjson/serializer/ObjectArrayCodec.java 81.25% <66.66%> (-1.29%) 30.00 <0.00> (ø)
...main/java/com/alibaba/fastjson/util/FieldInfo.java 85.76% <0.00%> (-0.34%) 96.00% <0.00%> (-1.00%)
...ava/com/alibaba/fastjson/parser/JSONLexerBase.java 69.97% <0.00%> (-0.04%) 812.00% <0.00%> (-1.00%)

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 e4308b7...c1a8acf. Read the comment docs.

The JSON.toJSONString(Object) and it's addition of PrettyFormat are
same.

Signed-off-by: Certseeds <51754303+Certseeds@users.noreply.github.com>
@Certseeds Certseeds changed the title Fix issue #3672 Fix #3672 Apr 11, 2021
</subject>

Branch:

<type>:
- [ ] Bug fix
- [ ] Bug fix (Test)
- [ ] New feature
- [ ] Breaking change
- [ ] Documentation update
- [ ] This change requires a documentation update

<body>

<footer>

Signed-off-by: Certseeds <51754303+Certseeds@users.noreply.github.com>
</subject>

Branch: issue3672

<type>:
- [x] Bug fix
- [ ] Bug fix (Test)
- [ ] New feature
- [ ] Breaking change
- [ ] Documentation update
- [ ] This change requires a documentation update

<body>

<footer>

Signed-off-by: Certseeds <51754303+Certseeds@users.noreply.github.com>
</subject>

Branch: issue3672

<type>:
- [ ] Bug fix
- [x] Bug fix (Test)
- [ ] New feature
- [ ] Breaking change
- [ ] Documentation update
- [ ] This change requires a documentation update

<body>

<footer>

Signed-off-by: Certseeds <51754303+Certseeds@users.noreply.github.com>
@wenshao
Copy link
Member

wenshao commented Jul 10, 2021

不要引入额外的代码格式化,导致行数更新太多,无法合并

@Certseeds Certseeds closed this Jul 10, 2021
@Certseeds Certseeds deleted the issue3672 branch July 10, 2021 14:41
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.

JSON.toJSONString(obj, SerializerFeature.PrettyFormat)导致循环引用path异常
3 participants