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

fastjson2 与jackson注解存在冲突 #716

Closed
beliefsky opened this issue Aug 29, 2022 · 6 comments
Closed

fastjson2 与jackson注解存在冲突 #716

beliefsky opened this issue Aug 29, 2022 · 6 comments
Labels
bug Something isn't working fixed
Milestone

Comments

@beliefsky
Copy link

beliefsky commented Aug 29, 2022

问题描述

当类中字段使用注解类 com.fasterxml.jackson.annotation.JsonIgnore,及@.JsonIgnore 时 转换成json时字段也会忽略该字段;如果父级使用了改注解 @JsonIgnore(value = false) 也无法恢复该字段的json序列化

环境信息

  • JDK信息: Openjdk 1.8
  • 版本信息:Fastjson2 2.0.6~2.0.8

重现步骤

  1. maven 引入jackson库和fastjson2库
  2. 创建类 Test

import com.fasterxml.jackson.annotation.JsonIgnore;
@DaTa
public class Test {

    @JsonIgnore(value = false)
    private Long id;
}

image

  1. json 序列化
    Test conf = new Test();
    conf.setId(1L);
    System.out.println(JSON.toJSONString(conf));

期待的正确结果

{“id”:1}
注解不应该受其他库干扰

实际结果

{}

@beliefsky beliefsky added the bug Something isn't working label Aug 29, 2022
@wenshao wenshao added this to the 2.0.13 milestone Aug 29, 2022
@wenshao
Copy link
Member

wenshao commented Aug 30, 2022

https://oss.sonatype.org/content/repositories/snapshots/com/alibaba/fastjson2/fastjson2/2.0.13-SNAPSHOT/
请用2.0.13-SNAPSHOT版本验证,2.0.13版本预计在9月12日前发布

如果要禁用JacksonAnnotation识别,需要显式配置,有两种方法:

1. 通过JVM启动参数配置

-Dfastjson2.useJacksonAnnotation=false

2. 通过直接调用JSONFactory#setUseJacksonAnnotation方法

JSONFactory.setUseJacksonAnnotation(false);

@wenshao wenshao added the fixed label Aug 30, 2022
@beliefsky
Copy link
Author

thank you

@beliefsky
Copy link
Author

经过验证在使用 JSONFactory.setUseJacksonAnnotation(false) 之后,已经不再忽略JsonIgnore相关字段; JacksonAnnotation的识别似乎对 @JsonIgnore(value = false) 的行为和Jackson不一致,value为false时表示不再忽略该字段,不过目前并不需要fastjson去识别Jackson的注解,已满足需求

@wenshao
Copy link
Member

wenshao commented Aug 31, 2022

https://oss.sonatype.org/content/repositories/snapshots/com/alibaba/fastjson2/fastjson2/2.0.13-SNAPSHOT/
请用最新的2.0.13-SNAPSHOT版本验证,已经能识别@JsonIgnore(value=false)的情况,不需要设置JSONFactory.setUseJacksonAnnotation(false)

@wenshao
Copy link
Member

wenshao commented Sep 10, 2022

https://github.com/alibaba/fastjson2/releases/tag/2.0.13
2.0.13版本已经发布,请用帮忙用新版本验证

@wenshao wenshao closed this as completed Sep 10, 2022
@beliefsky
Copy link
Author

已经解决了

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working fixed
Projects
None yet
Development

No branches or pull requests

2 participants