Jackson JSON java类 - 字段被多次序列化

时间:2011-09-26 15:25:12

标签: java android json jackson resttemplate

我有以下类定义

@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;
}

}

问题在于,在使用Jackson JSON序列化程序对此类进行序列化后,字段在结果有效内容中嵌入了两次:一个以较低的字母开头,一个以大写字母开头:

... {“标题”:“aa”,“标题”:“aa”,...}

类型定义可能有什么问题?

此致

1 个答案:

答案 0 :(得分:5)

尝试在课堂上使用@JsonAutoDetect(getterVisibility=Visibility.NONE)