我正在处理一个以这种方式定义的类:
@Data
@NoArgsConstructor
@JsonTypeName("classA")
public class A implements B {
private String name;
private List<String> list;
public A(String name, List<String> list) {
this.name = name;
this.list = list;
}
}
B类是这样定义的:
@JsonTypeInfo(use = JsonTypeInfo.Id.NAME, include = JsonTypeInfo.As.PROPERTY, property = "type")
@JsonSubTypes({ @JsonSubTypes.Type(value = C.class, name = "classC"),
@JsonSubTypes.Type(value = A.class, name = "classA")})
public interface B {
public String getName();
}
我想以这种方式反序列化InputStream:
objectMapper.readValue(stream, A.class)
但是我收到以下错误:
Caused by: org.codehaus.jackson.map.JsonMappingException: Unexpected token (END_OBJECT), expected FIELD_NAME: missing property 'type' that is to contain type id (for class A)
现在,我明白我可以注射&#39;类型属性,但问题是流非常庞大,我无法将其转换为字符串然后操纵它。
我有什么选择?
PS:这个类使用lombok作为getter,setter和默认构造函数。