I've tested a few ways to remove Null values in my java object from my output file (Json). However, there seems to be some that are missed. I'm using 2.9.6
I've tried the following:
objectMapper.setSerializationInclusion(Include.NON_NULL);
objectMapper.setSerializationInclusion(Include.NON_EMPTY);
@JsonInclude(Include.NON_NULL);
Here is my code:
public static String convertToJson(Hospital patient) {
try {
if (patient != null) {
String json = objectMapper.writeValueAsString(patient);
return json;
}
} catch (IOException e) {
throw new RuntimeException("Error converting person to Json " + e);
}
return null;
}
These have removed around 2150 nulls from the output file. However, the results still have some that are present in the form of:
"patient" : {
"corporateEntityCode" : "OH",
"groupNumber" : "123ABCD",
"patientIdentifier" : 12345678,
"patientPreexistingDiagnosticCode" : [ null, null, null, null, null, null ],
"patientPreexistingEffectiveDate" : [ null, null, null, null, null, null ],
"patientSubscriptNumber" : "01",
"subscriberNumber" : "0000000123456789"
}
Is this an existing issue? Or have I not implemented this correctly?