Skip to content
This repository has been archived by the owner on Oct 23, 2024. It is now read-only.

修复以$和_开头的属性名无法正确序列化和反序列化的问题 #2762

Merged
merged 2 commits into from
Sep 23, 2019

Conversation

Omega-Ariston
Copy link
Collaborator

@Omega-Ariston Omega-Ariston commented Sep 20, 2019

fix #2488 #2385 #2722

修复两个问题

  1. 以美元符号($)开头的属性,序列化和反序列都不解析,因为当前的逻辑是通过get/set/is方法名来解析propertyName,其中只对大写字母开头、'_'开头和'f'开头的属性做了特殊判断,但没有考虑到去掉get/set/is前缀后方法名与属性名称相同的场景,比如setage()对应age属性(此前只能识别setAge())
    修复方案:在所有解析propertyName的逻辑中,若匹配大写字母开头、'_'开头和'f'开头失败时(进入else分支),尝试直接去掉get\set\is前缀,并且不做任何大小写转换去获取field

  2. 以下划线符号(_)开头,序列化出来的字符串丢失了下划线符号(_),因为解析propertyName逻辑中为了支持get_set_Test.java用例中的特殊下划线场景,直接去掉了下划线。
    修复方案:在下划线开头的特殊处理分支中增加逻辑,如果去掉下划线获取不到field,就尝试加上下划线去获取(如果还是获取不到就还原回去掉下划线的属性名,以减少本次改动带来的影响)

@codecov-io
Copy link

Codecov Report

Merging #2762 into master will decrease coverage by <.01%.
The diff coverage is 82.22%.

Impacted file tree graph

@@             Coverage Diff              @@
##             master    #2762      +/-   ##
============================================
- Coverage     80.12%   80.11%   -0.01%     
- Complexity     7084     7091       +7     
============================================
  Files           145      145              
  Lines         26728    26770      +42     
  Branches       6383     6395      +12     
============================================
+ Hits          21417    21448      +31     
- Misses         3478     3482       +4     
- Partials       1833     1840       +7
Impacted Files Coverage Δ Complexity Δ
...n/java/com/alibaba/fastjson/util/JavaBeanInfo.java 87.47% <73.33%> (-0.59%) 199 <0> (+2)
...main/java/com/alibaba/fastjson/util/TypeUtils.java 80.15% <86.66%> (+0.14%) 634 <0> (+6) ⬆️
...ava/com/alibaba/fastjson/serializer/DateCodec.java 85.71% <0%> (-1.95%) 36% <0%> (-1%)
...java/com/alibaba/fastjson/parser/ParserConfig.java 83.3% <0%> (-0.17%) 202% <0%> (-1%)
...json/parser/deserializer/JavaBeanDeserializer.java 80.28% <0%> (+0.1%) 301% <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 bdc0fe5...d5ec03c. Read the comment docs.

@wenshao wenshao merged commit bfabcc8 into alibaba:master Sep 23, 2019
@Omega-Ariston Omega-Ariston deleted the fix-$attribute branch September 23, 2019 09:40
@zouyx
Copy link

zouyx commented Sep 25, 2019

是哪个版本能发布? @wenshao ?

@Omega-Ariston Omega-Ariston mentioned this pull request Sep 25, 2019
@toolhubcn
Copy link

这个问题害死了,可以提供兼容之前版本的选项吗 @wenshao

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

Successfully merging this pull request may close these issues.

JSONObject转JavaBean时,当字段名为$符开头时,无法识别。
5 participants