Is there a way to specify different serialized/deserialized JSON field names without having to write out both getter and setter methods explicitly, perhaps using lombok getters and setters?
As similar to this example, the following code permits incoming JSON to be deserialized to a different POJO field name. It also causes the POJO field name to be serialized as is:
public class PrivacySettings {
private String chiefDataOfficerName;
@JsonProperty("CDO_Name__c")
private void setChiefDataOfficerName(String chiefDataOfficerName) {
this.chiefDataOfficerName = chiefDataOfficerName;
}
@JsonProperty("chiefDataOfficerName")
private String getChiefDataOfficerName() {
return chiefDataOfficerName;
}
}
This seems verbose, but I haven't been able to get this to work with @Getter and @Setter. I did see that Jackson supports @JsonAlias which would probably help in this particular example, but I also have need to serialize with a different name.
Seems like this should be very simple, something like:
@Getter
@Setter
public class PrivacySettings {
@JsonSetter("CDO_Name__c")
@JsonGetter("chiefDataOfficerName")
private String chiefDataOfficerName;
}
But of course this is not valid.