There was a requirment formating java.util.Date
into string rather than timestamp in json.
{
"partyName": "Lifecare Pharmaceuticals",
"partyShortName": null,
"lastUpdateDate": 1486639814590, // replace with dd-mm-yyyy hh:mm:ss
}
To achive the date formatting I added the following ObjectMapperProvider
@Provider
@Component
public class ObjectMapperProvider implements ContextResolver<ObjectMapper> {
@Override
public ObjectMapper getContext(Class<?> type) {
ObjectMapper objectMapper = new ObjectMapper();
objectMapper.enable(SerializationConfig.Feature.USE_ANNOTATIONS);
objectMapper.configure(SerializationConfig.Feature.WRITE_DATES_AS_TIMESTAMPS, false);
return objectMapper;
}
}
The above solution worked but creates another issue ignoring XmlTransient annotation. In model classes Party
has collection of PartyContacts
and PartyContact
mapped like
@Column(name = "PARTY_ID", referencedColumnName = "PARTY_ID", insertable = false, updatable = false)
@ManyToOne(cascade = CascadeType.ALL, optional = false, fetch =FetchType.LAZY)
private Party party;
and getter method
@XmlTransient
public Party getParty() {
return party;
}
Here the XmlTransient annotation didnt work hence json loading recursively. I've seen onemore @JsonIgnore annotation but cant make it work with XmlTransient.