I have a parent DTO in which we have many nested objects. Is there a way i can ignore unknown properties on all the nested object as well as on the parent DTO.
If i add JsonIgnore on parent DTO, it ignores on parent class but not on nested classes. In order to make it work i have to add JsonIgnore on all the nested objects too.
Is there a way i could achieve this, without having it to write on all DTOs ?
@JsonInclude(JsonInclude.Include.NON_NULL)
@JsonIgnoreProperties(ignoreUnknown = true)
public class RegistrationRequest implements Cloneable {
private Subject subject;
private CaseDetail caseDetail;
private CaseEvent caseEvent;
private List<CaseRace> caseRaces;
private List<SubjectReference> subjectReferences;
I have to consume a endpoint and pass this as a payload to that endpoint so thats where it is failing.
ObjectMapper mapper = new ObjectMapper(); //TODO inject through constructor
mapper.disable(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES);
Properties properties = propertiesFactory.getProperties(); //TODO inject through constructor
url = properties.getProperty("regCore.patientInfo");
restclient.addHeader("userId", registrationRequest.getDataEntryPersonCtepId());
String registrationRequestInJsonString = mapper.writeValueAsString(registrationRequest);
response = restclient.put(url, registrationRequestInJsonString);
RestClient put request is our custom class :
public Response put(String url, String payload){
Builder acceptInvocationBuilder = createBuilder(url);
acceptInvocationBuilder.accept(MediaType.APPLICATION_JSON);
return acceptInvocationBuilder.put(Entity.json(payload));
}
The endpoint which am consuming look like below :
@Path("/patient-demography")
@PUT
@Produces(MediaType.APPLICATION_JSON)
@Consumes(MediaType.APPLICATION_JSON)
@ApiOperation(value = "Update patient demography", response = RegistrationRequest.class, tags = "Registration")
public Response updatePatientDemography(Registration registration) {
It is not able to unmarshall, as it is complaining about properties doesnt match
Failed : HTTP error code : 400 Unrecognized field