我想用代码替换注解配置,这是我的代码
ObjectMapper mapper = new ObjectMapper();
mapper.setDefaultTyping(type);
mapper.getSubtypeResolver().registerSubtypes(new NamedType(Node.class, "Node"));
mapper.getSubtypeResolver().registerSubtypes(new NamedType(SubNode.class, "SubNode"));
mapper.getSubtypeResolver().registerSubtypes(new NamedType(Attr.class, "Attr"));
mapper.getSubtypeResolver().registerSubtypes(new NamedType(SubAttr.class, "SubAttr"));
我知道
@JsonSubTypes({ @JsonSubTypes.Type(value = SubNode.class, name = "SubNode")})
,这是工作,但我没有使用它,我想使用代码来配置它