当我运行此代码时:
public void serialize(someInterface i, OutputStream o) throws Exception {
if(i == null || o == null){
throw new NullPointerException();
}
ObjectMapper mapper = new ObjectMapper();
mapper.writeValue(o, i);
}
我收到此错误:
com.fasterxml.jackson.databind.JsonMappingException: Can not construct instance of, problem: abstract types either need to be mapped to concrete types, have custom deserializer, or be instantiated with additional type information
我正在尝试序列化和反序列化接口i。我知道我必须将它转换为具有JSON注释的其他类型。这样杰克逊就能读懂它。但我不知道该怎么做。
我想在不修改界面的情况下这样做。代码如下:
@JsonSerialize(as=someInterface.class)