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

修复在ParserConfig中指定String.class(及一些较基础类型class)的自定义反序列化器无效的问题 #2670

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

Omega-Ariston
Copy link
Collaborator

@Omega-Ariston Omega-Ariston commented Aug 29, 2019

修复 #2624 #1875 中提到的通过ParserConfig自定义反序列化String.class不起作用的问题。
根因是fastjson针对String.class, Long.class这类比较基础的类型做了优化,有提供默认的反序列化器,但在判断用户是否针对这些类型自定义了反序列化器的逻辑上有缺陷(只判断了通过注解指定的方式,而没有判断通过ParserConfig配置的方式)
这里在DefaultFieldDeserializer的构造函数中对ParserConfig中取出的反序列化器进行了额外判断,如果不是默认的反序列化器(而是用户自己定义的),则把DefaultFieldDeserializer.customDeserializer属性设置为true,触发使用自定义反序列化器的逻辑。而在此之前,用户只能通过注解的方式将这个属性设置为true。
为了判断当前反序列化器是否为默认反序列化器,在ParserConfig中存储了一个静态的Map,用于存储各个基础类型的默认反序列化器,方便进行比较。

@codecov-io
Copy link

codecov-io commented Aug 29, 2019

Codecov Report

Merging #2670 into master will decrease coverage by 1.13%.
The diff coverage is 41.36%.

Impacted file tree graph

@@             Coverage Diff             @@
##             master   #2670      +/-   ##
===========================================
- Coverage     81.14%     80%   -1.14%     
- Complexity     7021    7059      +38     
===========================================
  Files           143     145       +2     
  Lines         26258   26713     +455     
  Branches       6276    6373      +97     
===========================================
+ Hits          21307   21373      +66     
- Misses         3129    3499     +370     
- Partials       1822    1841      +19
Impacted Files Coverage Δ Complexity Δ
...baba/fastjson/serializer/ASMSerializerFactory.java 96.05% <ø> (ø) 198 <0> (ø) ⬇️
...com/alibaba/fastjson/parser/JSONReaderScanner.java 72.61% <0%> (ø) 44 <2> (ø) ⬇️
...m/alibaba/fastjson/serializer/BigDecimalCodec.java 89.74% <0%> (ø) 18 <0> (ø) ⬇️
.../main/java/com/alibaba/fastjson/JSONValidator.java 0% <0%> (ø) 0 <0> (?)
...json/parser/deserializer/JavaBeanDeserializer.java 78.57% <100%> (+0.3%) 293 <0> (+2) ⬆️
...com/alibaba/fastjson/serializer/MapSerializer.java 75% <100%> (ø) 49 <0> (+1) ⬆️
.../main/java/com/alibaba/fastjson/util/ASMUtils.java 81.44% <100%> (-2.07%) 33 <0> (ø)
...fastjson/parser/deserializer/EnumDeserializer.java 90.32% <100%> (ø) 29 <0> (ø) ⬇️
src/main/java/com/alibaba/fastjson/JSONObject.java 86.05% <100%> (ø) 94 <0> (ø) ⬇️
...main/java/com/alibaba/fastjson/util/FieldInfo.java 86.94% <100%> (ø) 79 <0> (ø) ⬇️
... and 32 more

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 003a19e...701a897. Read the comment docs.

@codecov-commenter
Copy link

Codecov Report

Merging #2670 into master will decrease coverage by 0.12%.
The diff coverage is 98.76%.

Impacted file tree graph

@@             Coverage Diff              @@
##             master    #2670      +/-   ##
============================================
- Coverage     80.13%   80.00%   -0.13%     
+ Complexity     7071     7059      -12     
============================================
  Files           145      145              
  Lines         26704    26713       +9     
  Branches       6372     6373       +1     
============================================
- Hits          21399    21373      -26     
- Misses         3473     3499      +26     
- Partials       1832     1841       +9     
Impacted Files Coverage Δ Complexity Δ
.../parser/deserializer/DefaultFieldDeserializer.java 87.50% <80.00%> (+0.73%) 24.00 <0.00> (+2.00)
...java/com/alibaba/fastjson/parser/ParserConfig.java 83.44% <100.00%> (-0.03%) 204.00 <4.00> (+1.00) ⬇️
...json/parser/deserializer/JavaBeanDeserializer.java 78.57% <100.00%> (-1.61%) 293.00 <0.00> (-7.00)
...ava/com/alibaba/fastjson/serializer/DateCodec.java 87.58% <0.00%> (-1.97%) 37.00% <0.00%> (-1.00%)
...com/alibaba/fastjson/parser/JSONReaderScanner.java 72.61% <0.00%> (-1.28%) 44.00% <0.00%> (-1.00%)
...ava/com/alibaba/fastjson/parser/JSONLexerBase.java 70.90% <0.00%> (-0.44%) 822.00% <0.00%> (-4.00%)
...n/java/com/alibaba/fastjson/util/JavaBeanInfo.java 87.88% <0.00%> (-0.19%) 197.00% <0.00%> (-1.00%)
...com/alibaba/fastjson/serializer/SerialContext.java 77.08% <0.00%> (+4.16%) 19.00% <0.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 182859f...701a897. Read the comment docs.

@llsi4275
Copy link

llsi4275 commented Jun 18, 2020

@Omega-Ariston 在1.2.69+的版本中,这个全局的功能又失效了...
#3279

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.

4 participants