Jackson JSON java class - fields are serialized multiple times

限于喜欢 提交于 2020-01-05 07:47:04

问题


I have a following class defined

@JsonTypeName("PhotoSetUpdater")
public class PhotoSetUpdater {
@JsonProperty("Title")
private String title;
@JsonProperty("Caption")
private String caption;
@JsonProperty("Keywords")
private String[] keywords;
@JsonProperty("Categories")
private int[] categories;
@JsonProperty("CustomReference")
    private String customReference;      // new in version 1.1


public String getTitle() {
    return title;
}

public void setTitle(String title) {
    this.title = title;
}

public String getCaption() {
    return caption;
}

public void setCaption(String caption) {
    this.caption = caption;
}


public String getCustomReference() {
    return customReference;
}


public void setCustomReference(String customReference) {
    this.customReference = customReference;
}


public void setKeywords(String[] keywords) {
    this.keywords = keywords;
}

public String[] getKeywords() {
    return keywords;
}


public void setCategories(int[] categories) {
    this.categories = categories;
}


public int[] getCategories() {
    return categories;
}

}

The problem is that after I serialize this class with Jackson JSON serializer, the fields are insetrted twice in the result payload: one starting with lower letter, one with capital letter:

... {"Caption":"aa","caption":"aa",...}

What may be wrong with type definition?

Regards


回答1:


Try using @JsonAutoDetect(getterVisibility=Visibility.NONE) on the class.



来源:https://stackoverflow.com/questions/7557397/jackson-json-java-class-fields-are-serialized-multiple-times

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!