I have an service that talks to backend servers and front-end clients. The backend apps are expecting JSON in one format and the front-end apps are expecting it in a different format.
If I try to using @JsonProperty I end up with a situation where either Jackson can't deserialize the data from the client or it can't serialize the data to the service because the annotations don't match. For example: I need this to properly send my JSON to the backend servers:
@JsonProperty("createDate")
public void setCreationDate(Date creationDate) {
this.creationDate = creationDate;
}
However, this fails to deserialize the the JSON coming from the clients. If I remove @JsonProperty then the outcome is reserved.
Any suggestions on how to solve this? I think I have the following options:
- Use different models for the front end and backend.
- Perhaps use different ObjectMapper instances?
- Use @JsonView somehow?
- Custom serializer?
- JSON Schema?
Any pointers?
Thanks!
Edit:
I don't think its a duplicate because I need different names based on where the JSON is coming from or going to. Its contextually instead of being a global rename which is what it appears @JsonProperty is really good at.