0
我有註釋是這樣的:ObjectMapper避免註釋
@Valid
@NotNull
@JsonTypeResolver(com.rsqtechnologies.sioms.shared.JsonTypeResolver.class)
@JsonTypeInfo(
use = JsonTypeInfo.Id.NAME,
include = JsonTypeInfo.As.PROPERTY,
property = "type",
visible = true)
@JsonSubTypes({
@JsonSubTypes.Type(value = HandballPlayerTO.class, name = "handballPlayerTO"),
@JsonSubTypes.Type(value = FootballPlayerTO.class, name = "footballPlayerTO")
})
而且想使用objectMapper期間避免@JsonTypeResolver。
我已經試過這樣:
ObjectMapper mapper = new ObjectMapper();
JacksonAnnotationIntrospector ignoreJsonTypeInfoIntrospector = new JacksonAnnotationIntrospector() {
@Override
protected TypeResolverBuilder<?> _findTypeResolver(
MapperConfig<?> config, Annotated ann, JavaType baseType) {
if (!ann.hasAnnotation(JsonTypeResolver.class)) {
return super._findTypeResolver(config, ann, baseType);
}
return null;
}
};
mapper.setAnnotationIntrospector(ignoreJsonTypeInfoIntrospector);
但正如我注意到它刪除了旁邊顯示的所有註釋。
真棒多數民衆贊成正是我一直在尋找。 – MrNetroful