1
다음 클래스를 정의했습니다.Jackson JSON 자바 클래스 - 필드가 여러 번 직렬화됩니다.
@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;
}
문제는 잭슨 JSON serializer로이 클래스를 직렬화하면 해당 필드가 결과 페이로드에서 두 번 삽입됩니다.
... { "캡션": "aa", "캡션": "aa", ...}
형식 정의가 잘못되었을 수 있습니까?
감사합니다
매력처럼 작동합니다!. 감사. – cubesoft
이것은 작동합니다 - 또는 getter에 @JsonProperty를 방금 추가했을 수 있습니다. 1.8 및 이전 버전에서는 중복이 발생하지만 (getter 및 setter 모두에 있어야합니다.) Jackson 1.9는 (마지막으로!) 주석을 병합하므로 getter에 추가하면 getter와 setter 모두에서 작동합니다. – StaxMan