Jackson JSON java 类 - 字段被序列化多次
我定义了以下类
@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 序列化器序列化此类后,这些字段在结果有效负载中插入两次:一个以小写字母开头,一个以大写字母开头:
... {“Caption”: "aa","caption":"aa",...}
类型定义可能有什么问题?
问候
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
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
尝试在类上使用
@JsonAutoDetect(getterVisibility=Visibility.NONE)
。Try using
@JsonAutoDetect(getterVisibility=Visibility.NONE)
on the class.