java - Jackson serialization: Ignore uninitialised int -


now first off, i've read other answers on site , others jackson serialisation provide methods ignoring null fields. in java, however, int cannot null.

i trying objectmap java object convert json ignore null fields. works strings ints end taking on value of 0 if uninitialised, , since 0 not null field not ignored.

    private objectwriter mapper = new objectmapper().writer();     private myclass data = new myclass(); //class contains string , int variable     data.setnumber(someint); //set values     data.setstring(somestring);      string json = mapper.writevalueasstring(data); 

can shed light on please?

edit: clarify, have tried using integer class data type causes conversion json string throw jsonprocessingexception.

use int wrapper integer. way you'll able use null value.

alternatively can use jackson's jsoninclude annotation ignore null value when serializing.

@jsoninclude(include.non_null)   public class myclass{     ... } 

Comments

Popular posts from this blog

javascript - Chart.js (Radar Chart) different scaleLineColor for each scaleLine -

apache - Error with PHP mail(): Multiple or malformed newlines found in additional_header -

java - Android – MapFragment overlay button shadow, just like MyLocation button -