Search code examples
javajsonpojo

How to Restrict unassigned variable to not get from POJO to JSON?


I have a class A, with two variable varOne, varTwo, While assigning I only assigned varTwo, but when converting to JSON I'm getting both the value one which was unassigned is as null. What can I do to restrict varOne. if varOne is unassigned the I don't want it at all in Json.

I tried reconstruct the JSON. but feels like could do better.


Solution

  • You can put @JsonInclude(JsonInclude.Include.NON_NULL) above the class