开发者

Jackson JSON java class - fields are serialized multiple times

开发者 https://www.devze.com 2023-04-07 10:10 出处:网络
I have a following class defined @JsonTypeName(\"PhotoSetUpdater\") public class PhotoSetUpdater { @JsonProperty(\"Title\")

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[] cat开发者_如何学运维egories) {
    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


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

0

精彩评论

暂无评论...
验证码 换一张
取 消