Getting both java obejct as will jsonproperty is getting generated whilc I convert java object to JSON.
Can you please confirm where I have made mistake.
Getting both java obejct as will jsonproperty is getting generated whilc I convert java object to JSON.
Can you please confirm where I have made mistake.
Add @JsonAutoDetect(getterVisibility= JsonAutoDetect.Visibility.NONE)
to your class:
@JsonAutoDetect(getterVisibility= JsonAutoDetect.Visibility.NONE)
@JsonInclude(JsonInclude.Include.NON_EMPTY)
public class FalconidePersonalizationVO {
By default Jackson follow java bean convention to output json properties. As result, it founds your getX
method and output xapiheader
property.
But you also annotate your field with @JsonProperty
so another property named x-apiheader
is also ouputed.
Disable getterX
detection method will prevent jackson output getter fields.
**************** Solution 1 ****************
Annotate getter / setter with @JsonProperty as well (now annotating field is not mandatory)
public class FalconidePersonalizationVO {
@JsonProperty("x-apiheader-cc")
private String xApiheaderCc;
@JsonProperty("x-apiheader")
private String xApiheader;
@JsonProperty("x-apiheader-cc")
public String getXApiheaderCc() {
return xApiheaderCc;
}
@JsonProperty("x-apiheader-cc")
public void setXApiheaderCc(String xApiheaderCc) {
this.xApiheaderCc = xApiheaderCc;
}
@JsonProperty("x-apiheader")
public String getXApiheader() {
return xApiheader;
}
@JsonProperty("x-apiheader")
public void setXApiheader(String xApiheader) {
this.xApiheader = xApiheader;
}
}
**************** Solution 2 ****************
Follow setter / getter naming convention. In normal naming convention first letter of field name is capitalized prepending it with set / get. But in this case since second char is capital so, first char is not capitalized. See https://stackoverflow.com/a/16146215/3295987
public class FalconidePersonalizationVO {
@JsonProperty("x-apiheader-cc")
private String xApiheaderCc;
@JsonProperty("x-apiheader")
private String xApiheader;
/*
* Setter / getter auto generated in eclipse
*/
// getXApiheaderCc -> getxApiheaderCc
public String getxApiheaderCc() {
return xApiheaderCc;
}
public void setxApiheaderCc(String xApiheaderCc) {
this.xApiheaderCc = xApiheaderCc;
}
public String getxApiheader() {
return xApiheader;
}
public void setxApiheader(String xApiheader) {
this.xApiheader = xApiheader;
}
}