默认的jackon行为似乎使用两个属性(getter和setter)和字段来序列化和反序列化为json.
我想使用这些字段作为序列化配置的规范来源,因此不希望jackson完全查看属性.
我可以使用注释在单个类的基础上执行此操作:
@JsonAutoDetect(fieldVisibility = Visibility.ANY, getterVisibility = Visibility.NONE, setterVisibility = Visibility.NONE)
Run Code Online (Sandbox Code Playgroud)
但我不想把它放在每一堂课......
是否可以在全球范围内进行配置?喜欢在Object Mapper中加一些?
我正在使用Jackson与Spring一起进行JSON(de)序列化.但是,在某些情况下,我遇到了两次字段的问题.
我有一个抽象类:
@JsonTypeInfo(use = JsonTypeInfo.Id.NAME, include = JsonTypeInfo.As.PROPERTY, property = "mimeType")
@JsonSubTypes({
@JsonSubTypes.Type(value = ImageBookmarkJsonModel.class, name = "image/jpeg"),
@JsonSubTypes.Type(value = EpubBookmarkJsonModel.class, name = "application/epub+zip")
})
public abstract class AbstractBookmarkJsonModel extends AbstractJsonModel {
protected String mimeType;
// Removed other fields for brevity
public String getMimeType() {
return mimeType;
}
public void setMimeType(String mimeType) {
this.mimeType = mimeType;
}
@Override
public String toString() {
ObjectMapper mapper = new ObjectMapper();
try {
return mapper.writeValueAsString(this);
} catch (IOException e) {
throw new IllegalStateException("Cannot convert …Run Code Online (Sandbox Code Playgroud)