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 int
s 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
Post a Comment