有没有办法在映射器配置上指定 @JsonTypeIdResolver 而不是注释目标类?例如,而不是:
@JsonTypeInfo(
use = JsonTypeInfo.Id.CUSTOM,
include = JsonTypeInfo.As.PROPERTY,
property = "@type")
@JsonTypeIdResolver(FooTypeIdResolver.class)
public class Foo {
}
只有
@JsonTypeInfo(
use = JsonTypeInfo.Id.CUSTOM,
include = JsonTypeInfo.As.PROPERTY,
property = "@type")
public class Foo {
}
并在映射器上执行以下操作
mapper.getSerializationConfig()
.with(new JacksonAnnotationIntrospector())
.without(SerializationFeature.INDENT_OUTPUT);
...
// something like this :
.addTypeIdResolver(Foo.class, FooTypeIdResolver.class)
我问这个是因为 FooTypeIdResolver 位于 Foo 库不能依赖的不同“库”上......