1

在我的 JsonSerializer 中,我有以下代码:

// Variable needs to be of type Object
Object object = new Person("John Doe");
...
JsonSerializer<Object> serializer = serializers.findTypedValueSerializer(object.getClass(), true, null);
serializer.serialize(object, generator, serializers);

这很好地序列化为这个 JSON:

{"@class":"org.foo.Person","name":"John Doe"}

因为我的班级是这样注释的:

@JsonTypeInfo(use=JsonTypeInfo.Id.CLASS, include=JsonTypeInfo.As.PROPERTY, property="@class")
public class Person {
    private String name;
    ...
}

如何使用我的反序列化 JSON 文本JsonDeserializer


此代码引发空指针异常:

JsonDeserializer<Object> deserializer = context.findNonContextualValueDeserializer(context.constructType(Object.class));
TypeDeserializer typeDeserializer = context.getFactory().findTypeDeserializer(context.getConfig(), context.constructType(Object.class));
Object object = deserializer.deserializeWithType(parser, context, typeDeserializer);
4

0 回答 0