0

The object I am trying to convert to json has a number of attributes but I would like to print attributes with not null values only.

{ "ZIPCODE" : "45869", "TYPE2" : null, "POSTDIR2" : null, "PREDIR" : null, "LON" : null, "NUMBER" : null, "PREDIR2" : null, "LAT" : null, "POSTDIR" : null, "TLID" : null, "STREET" : null, "STREET2" : null, "ZIP" : "45869", "LINE2" : null, "STATE" : null, "ZIPEXTN" : null, "CITY" : null, "COUNTY" : null, "NAME" : null, "TYPE" : null } 

where I would like only:

{ "ZIPCODE" : "45869", "ZIP" : "45869" } 

I am trying to use jackson to do this without any success, any hints?

2 Answers 2

2

If you use "Jackson lib", you can use @JsonInclude

@JsonInclude(value=Include.NON_NULL) 

or

@JsonInclude(value=Include.NON_EMPTY) 

Read more

Sign up to request clarification or add additional context in comments.

Comments

2

Here is a good example to read Jason string and iterate through the elements. You can put a null value check before printing the values while iterating them.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.