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

完善DateFormat配置优先级 #2706

Merged
merged 5 commits into from
Jun 14, 2020
Merged

Conversation

Omega-Ariston
Copy link
Collaborator

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

fix issue #1868 #1968 #2029 #2452
正常的配置优先级应该是从小到大的,目前fastjson支持四种方式配置dateFormat,按照优先级从高到低分别为:

  1. 通过JSON.toJSONStringWithDateFormat()函数传参
  2. 通过在属性上添加@JSONField(format="yyyy-MM-dd")注解
  3. 通过xml配置或FastJsonConfig.setDateFormat()函数传参
  4. 通过修改JSON.DEFFAULT_DATE_FORMAT变量值

但是目前通过1和3方式配置的dateFormat存储到同一个变量里的,导致提升方式2的优先级时会同时覆盖1和3的优先级。所以用了不同的变量fastJsonConfigDateFormatPattern来存储方式3配置的dateFormat,并把与FastJsonConfig相关的setDateFormat方法统一到了这个变量上。

另外为了避免冲突, 场景3中使用FastJsonConfig设置的dateFormat的一些方法进行了调整,并已全部通过测试。

@Omega-Ariston Omega-Ariston reopened this Sep 5, 2019
@Omega-Ariston Omega-Ariston force-pushed the fix-issue1868 branch 3 times, most recently from 760442b to c99628e Compare September 9, 2019 10:41
where a null format is passed to writeWithFormat()
@codecov-io
Copy link

codecov-io commented Sep 9, 2019

Codecov Report

Merging #2706 into master will decrease coverage by 0.05%.
The diff coverage is 76.47%.

Impacted file tree graph

@@             Coverage Diff              @@
##             master    #2706      +/-   ##
============================================
- Coverage     80.12%   80.07%   -0.06%     
- Complexity     7141     7143       +2     
============================================
  Files           145      145              
  Lines         26964    27000      +36     
  Branches       6449     6458       +9     
============================================
+ Hits          21605    21620      +15     
- Misses         3497     3508      +11     
- Partials       1862     1872      +10
Impacted Files Coverage Δ Complexity Δ
...ibaba/fastjson/support/jaxrs/FastJsonProvider.java 86.4% <100%> (ø) 41 <0> (ø) ⬇️
...ing/messaging/MappingFastJsonMessageConverter.java 78.57% <100%> (ø) 11 <0> (ø) ⬇️
...stjson/support/spring/FastJsonRedisSerializer.java 84.61% <100%> (ø) 8 <0> (ø) ⬇️
...n/support/spring/FastJsonHttpMessageConverter.java 70.54% <100%> (ø) 29 <0> (ø) ⬇️
...ava/com/alibaba/fastjson/serializer/DateCodec.java 87.28% <100%> (+0.22%) 41 <0> (+1) ⬆️
...baba/fastjson/support/spring/FastJsonJsonView.java 90.52% <100%> (ø) 33 <0> (ø) ⬇️
...on/support/retrofit/Retrofit2ConverterFactory.java 89.09% <100%> (ø) 18 <0> (ø) ⬇️
src/main/java/com/alibaba/fastjson/JSON.java 82.53% <60%> (-2.34%) 149 <4> (+1)
...om/alibaba/fastjson/serializer/JSONSerializer.java 84.79% <87.5%> (-0.38%) 77 <3> (+4)
...com/alibaba/fastjson/parser/JSONReaderScanner.java 72.61% <0%> (-1.28%) 44% <0%> (-1%)
... and 3 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 7f41acc...ec88477. Read the comment docs.

@timandy
Copy link
Contributor

timandy commented Oct 25, 2019

应该是这个的优先级 2通过在属性上添加@JSONField(format="yyyy-MM-dd")注解 最高吧

@Omega-Ariston
Copy link
Collaborator Author

应该是这个的优先级 2通过在属性上添加@JSONField(format="yyyy-MM-dd")注解 最高吧

我的理解是影响粒度越小优先级越高,toJSONStringWithDateFormat()只会影响调用函数的这一次转换的结果,所以优先级最高

@timandy
Copy link
Contributor

timandy commented Oct 28, 2019

@Omega-Ariston toJsonString 时传入了 时间格式的情况呢?

toJsonString 传入时间格式时. 我想这个格式只应用到 没有加 @JsonFiled(format) 的字段.但是其他的字段我想用传入的..这种用例是否支持?

@timandy
Copy link
Contributor

timandy commented Oct 29, 2019

#696 #2832

@wenshao
Copy link
Member

wenshao commented Jun 27, 2020

https://github.com/alibaba/fastjson/releases/tag/1.2.72
问题已修复,请用新版本

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.

None yet

4 participants