Skip to content

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

@deadpoolssr

Description

@deadpoolssr

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingfixedquestionFurther information is requested

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions