我使用 Java 9、Jackson-core 和 jackson-databind 2.5.5 我想使用带有 DefaultTyping.NON_FINAL 选项的自定义序列化来在 Json 中编写类名。
如果我删除默认输入 NON_FINAL,一切正常。
当我添加 NON_FINAL 选项时,我的自定义序列化程序“MySerializer”被调用,并且出现异常 JsonMappingException:类型 id 处理未实现
public class Main {
public static void main(String[] args) throws JsonProcessingException {
ObjectMapper objectMapper = new ObjectMapper();
objectMapper.enableDefaultTyping();
objectMapper.enableDefaultTyping(ObjectMapper.DefaultTyping.NON_FINAL);
SimpleModule simpleModule = new SimpleModule();
simpleModule.addSerializer(new MySerializer());
objectMapper.registerModule(simpleModule);
System.out.println(objectMapper.writeValueAsString(new MyObject(1)));
}
}
public class MyObject {
private int a = 0;
public MyObject() {
}
public MyObject(int a) {
this.a = a;
}
public int getA() {
return a;
}
public void …Run Code Online (Sandbox Code Playgroud)