Dynamically ignore json properties based on condition

stefan.stt :

I have a POJO object with a List<Integer> stores for example. Is it possible to ignore it with @JsonIgrnore based on the condition to be empty or null when returning this object to the frontend?

Maciej Kowalski :

There is annotation called @JsonInclude accepting various configs.

In your case it would be:

@JsonInclude(JsonInclude.Include.NON_EMPTY)
List<Integer> stores

Javadoc says:

NON_EMPTY
Value that indicates that only properties with null value, 
or what is considered empty, are not to be included.

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=420462&siteId=1