We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
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
当 Java Bean 中存在一个 public 关键字修饰的 枚举类型属性时,Fastjson 2 将忽略 对应 getter 方法的输出,并强制使用该枚举属性直接输出。 只有去掉 public 关键字,才能优先使用 getter 的返回值作为属性输出。
public
参考如下代码:
public static enum Color { RED(1), YELLOW(3), BLUE(5), ; final Integer value; Color(Integer value) { this.value = value; } } @Getter public static class Bean { public Color color; public Integer getColor() { return color.value; } } @Test public void test() { final Bean bean = new Bean(); bean.color = Color.BLUE; // 当 Bean.color 有 public 关键字修饰时,将输出 {"color":"BLUE"} // 去掉 Bean.color 的 public 关键字后,将输出 {"color":5} System.out.println(JSON.toJSONString(bean)); }
除非指定了 JSONReader.Feature.FieldBased ,否则都应该默认优先基于 getter 的返回值进行序列化输出。
JSONReader.Feature.FieldBased
无
The text was updated successfully, but these errors were encountered:
https://oss.sonatype.org/content/repositories/snapshots/com/alibaba/fastjson2/fastjson2/2.0.39-SNAPSHOT/ 问题已修复,请帮忙用2.0.39-SNAPSHOT版本验证,2.0.39版本预计在8月27日前发布
Sorry, something went wrong.
fix serialize field priority, for issue #1727
6602de9
https://github.com/alibaba/fastjson2/releases/tag/2.0.39 请用新版本
No branches or pull requests
问题描述
当 Java Bean 中存在一个
public
关键字修饰的 枚举类型属性时,Fastjson 2 将忽略 对应 getter 方法的输出,并强制使用该枚举属性直接输出。只有去掉
public
关键字,才能优先使用 getter 的返回值作为属性输出。环境信息
重现步骤
参考如下代码:
期待的正确结果
除非指定了
JSONReader.Feature.FieldBased
,否则都应该默认优先基于 getter 的返回值进行序列化输出。相关日志输出
无
附加信息
无
The text was updated successfully, but these errors were encountered: