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

JSONB进行序列化/反序列化时,类的兼容性是不是不太好 #2823

Closed
deadpoolssr opened this issue Jul 22, 2024 · 1 comment
Closed
Labels
bug Something isn't working fixed question Further information is requested
Milestone

Comments

@deadpoolssr
Copy link

server端使用JSONB.toBytes序列化,client端反序列化时,如果类的字段比server端的类少,在JSONB.parseObject的时候可能会抛出异常。
String jsonString = JSONB.toJSONString(bytes); Response tppResponse1 = JSON.parseObject(jsonString, Response.class, JSONReader.Feature.FieldBased); Response tppResponse = JSONB.parseObject(bytes, Response.class, JSONReader.Feature.FieldBased);
样例代码如上,其中 JSON.parseObject不报错,JSONB.parseObject抛异常
com.alibaba.fastjson2.JSONException: name not support input : DOUBLE -77

at com.alibaba.fastjson2.JSONReaderJSONB.notSupportType(JSONReaderJSONB.java:2633)
at com.alibaba.fastjson2.JSONReaderJSONB.skipValue(JSONReaderJSONB.java:2594)
at com.alibaba.fastjson2.reader.ObjectReaderBean.processExtra(ObjectReaderBean.java:134)
at com.alibaba.fastjson2.reader.ORG_1_1_TppResponse.readJSONBObject(Unknown Source)
at com.alibaba.fastjson2.JSONB.parseObject(JSONB.java:799)

Response类定义如下:
@Data public class Response implements Serializable { SpResponse mini; }

其中server返回的数据除了mini字段还有其他的field

@deadpoolssr deadpoolssr added the question Further information is requested label Jul 22, 2024
@wenshao wenshao added the bug Something isn't working label Jul 23, 2024
@wenshao wenshao added this to the 2.0.53 milestone Jul 23, 2024
@wenshao wenshao added the fixed label Jul 23, 2024
@wenshao wenshao closed this as completed Sep 16, 2024
@wenshao
Copy link
Member

wenshao commented Sep 16, 2024

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

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 question Further information is requested
Projects
None yet
Development

No branches or pull requests

2 participants