Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

[BUG]JSONWriter.Feature.FieldBased导致@JSONField注解失效 #445

Closed
youandeanyou opened this issue Jun 8, 2022 · 2 comments
Closed
Labels
bug Something isn't working
Milestone

Comments

@youandeanyou
Copy link

引用版本:fastjson2-2.0.7-20220608.134803-35

配置信息:

    FastJsonConfig config = new FastJsonConfig();
    // 这里如果设置了FieldBased,@JSONField注解就生不效了
     config.setWriterFeatures(JSONWriter.Feature.FieldBased, JSONWriter.Feature.NullAsDefaultValue);
    // 如果去除JSONWriter.Feature.FieldBased,@JSONField注解就生效了
    // config.setWriterFeatures(JSONWriter.Feature.NullAsDefaultValue);

返回实体字段:
@JSONField(format = "yyyy-MM-dd HH")
private Date history;
@JSONField(format = "yyyy-MM-dd")
private LocalDate yesterday;
@JSONField(format = "yyyy-MM-dd HH:mm")
private java.sql.Date tomorrow;

期望:{"current":"2022-06-09 00:11:10","history":"2022-06-09 00","tomorrow":"2022-06-09 00:11","yesterday":"2022-06-09"}

实际 :{"current":"2022-06-09 00:19:35","history":"2022-06-09 00:19:35","tomorrow":"2022-06-09 00:19:35","yesterday":"2022-06-09 00:00:00"}

疑问:文档中对FieldBased的描述是,”FieldBased | 基于字段反序列化,如果不配置,会默认基于public的field和getter方法序列化。配置后,会基于非static的field(包括private)做反序列化“。

详情见:https://github.com/youandeanyou/springboot-demo

访问:http://localhost:8081/test 即可。

@youandeanyou youandeanyou added the bug Something isn't working label Jun 8, 2022
@wenshao wenshao added this to the 2.0.7 milestone Jun 9, 2022
@wenshao
Copy link
Member

wenshao commented Jun 9, 2022

@wenshao
Copy link
Member

wenshao commented Jun 11, 2022

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

@wenshao wenshao closed this as completed Jun 11, 2022
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants