2

example dto generated:

{
  "id": 1,
  "name": "test",
  "attributes": null
}

expecting response:

{
  "id": 1,
  "name": "test"
}

here I have to ignore attributes while returning. I cannot use @JsonInclude(JsonInclude.Include.NON_NULL) in dto because it has to be auto generated for other reasons and I cannot give @NotNull in model because it can be null for some cases. Can someone please help me with this?

2 Answers2

3

You can easily add @JsonInclude(JsonInclude.Include.NON_NULL) to your Entity .

.@JsonInclude(JsonInclude.Include.NON_NULL) public class RealPerson implements Serializable {...

0

since attribute is a JSON field, including in the below part in map to json happens worked!

objectMapper.setSerializationInclusion(Include.NON_NULL)

tried this from https://stackoverflow.com/a/11761975/11125169