-
Notifications
You must be signed in to change notification settings - Fork 496
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
[BUG]@JSONType(serializeFeatures = JSONWriter.Feature.WriteNonStringValueAsString)对于List<Long> 类型的属性序列化时不生效 #2431
Comments
我想咨询一下有关安全的问题。 @带有jsontype的邮件好像被发送到外部(我)。
***@***.*** 。 因为是个人电子邮件,所以我认为最好防止邮件发到这边的问题。 请多多关照。
2024년 4월 12일 (금) 오전 10:27, Bruce-Lin318 ***@***.***>님이 작성:
… 问题描述
@jsontype <https://github.com/jsontype>(serializeFeatures =
JSONWriter.Feature.WriteNonStringValueAsString)对于List 类型的属性序列化时不生效
对于非字符串类型的数据可以正常序列化为字符串,但是List类型解析后,数组内仍为数字类型。
***@***.*** <https://github.com/jsontype>,而是使用JSON.toJSONString(obj,
JSONWriter.Feature.WriteNonStringValueAsString)则无此问题
环境信息
- OS信息: Win11
- JDK信息:jdk 17.0.8.7.1
- 版本信息:Fastjson2 2.0.41
重现步骤
1.
***@***.*** <https://github.com/jsontype>(serializeFeatures =
JSONWriter.Feature.WriteNonStringValueAsString)
2.
接口给前端返参时,Long id 的属性可以按照预期展示为字符类型,List ids 序列化后,数组内仍为数字类型
@DaTa
@jsontype(serializeFeatures = JSONWriter.Feature.WriteNonStringValueAsString)
public static class TestClass {
private Long id;
private List<Long> ids;
}
@test
public void testJson() {
TestClass testClass = new TestClass();
testClass.setId(1L);
testClass.setIds(List.of(1L, 2L));
System.out.println(JSON.toJSONString(testClass));
}
期待的正确结果
期待的正确结果为:
{"id":"1","ids":["1","2"]}
现在的结果为:
{"id":"1","ids":[1,2]}
附加信息
***@***.*** <https://github.com/jsontype>,
***@***.***与
@jsontype <https://github.com/jsontype>均测试过,效果相同)
@DaTa
public static class TestClass {
private Long id;
private List<Long> ids;
}
@test
public void testJson() {
TestClass testClass = new TestClass();
testClass.setId(1L);
testClass.setIds(List.of(1L, 2L));
System.out.println(JSON.toJSONString(testClass, JSONWriter.Feature.WriteNonStringValueAsString));
}
打印结果:
{"id":"1","ids":["1","2"]}
—
Reply to this email directly, view it on GitHub
<#2431>, or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AZ3TDXLJRC7EZ4RB7WRDIYTY44Z7ZAVCNFSM6AAAAABGDI2FEGVHI2DSMVQWIX3LMV43ASLTON2WKOZSGIZTQOBWGQZTAMQ>
.
You are receiving this because you were mentioned.Message ID:
***@***.***>
|
不好意思!之前确实没注意到这个事情,之后会注意的,对带来的不便给您道歉。 |
yanxutao89
added a commit
that referenced
this issue
Apr 12, 2024
wenshao
added a commit
that referenced
this issue
Apr 13, 2024
wenshao
added a commit
that referenced
this issue
Apr 13, 2024
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
问题描述
@jsontype(serializeFeatures = JSONWriter.Feature.WriteNonStringValueAsString)对于List 类型的属性序列化时不生效
对于非字符串类型的数据可以正常序列化为字符串,但是List类型解析后,数组内仍为数字类型。
如果不适用@jsontype,而是使用JSON.toJSONString(obj, JSONWriter.Feature.WriteNonStringValueAsString)则无此问题
环境信息
重现步骤
实体类上增加@jsontype(serializeFeatures = JSONWriter.Feature.WriteNonStringValueAsString)
接口给前端返参时,Long id 的属性可以按照预期展示为字符类型,List ids 序列化后,数组内仍为数字类型
期待的正确结果
期待的正确结果为:
现在的结果为:
附加信息
如果不适用@jsontype, 序列化时指定JSONWriter.Feature.WriteNonStringValueAsString,可以实现预期效果,所以猜测是对于List类型解析时注解未生效(@JSONField与@jsontype均测试过,效果相同)
打印结果:
The text was updated successfully, but these errors were encountered: