i know there's lots of questions skipping fields null value when serializing objects json. want skip / ignore fields null values when deserializing json object.
consider class
public class user { long id = 42l; string name = "john"; }
and json string
{"id":1,"name":null}
when doing
user user = gson.fromjson(json, user.class)
i want user.id
'1' , user.name
'john'.
is possible either gson or jackson in general fashion (without special typeadapter
s or similar)?
to skip using typeadapters, i'd make pojo null check when setter method called.
or @
@jsoninclude(value = include.non_null)
the annotation needs @ class level, not method level.
@jsoninclude(include.non_null) //or include.non_empty, if fits use case public static class requestpojo { ... }
for deserialise can use following @ class level.
@jsonignoreproperties(ignoreunknown = true)
Comments
Post a Comment