java - Stop Jackson custom Date Serializer writing nulls -


i'm using jackson handle json, have custom date serializer formatting dates in way want doesn't abide @jsonserialize(include = inclusion.non_null) annotations. serializer below.

if date null still gets written. if don't use custom serializer fine, null values don't written. question is, there in jsonserializer class needs done stop null values being written?

public class dateserializer extends jsonserializer<date> {     @override     public final void serialize(date date, jsongenerator jgen, serializerprovider provider) throws ioexception, jsonprocessingexception     {         simpledateformat sdf = new simpledateformat(my_format);         jgen.writestring(sdf.format(date));     } } 

turns out wasn't serializer @ all, @jsonserialize annotation defaults include=always overrides include=non_null on class. changing annotation of getter works:

changed:

@jsonserialize(using = dateserializer.class) public date getdate() {     return date; } 

to:

@jsonserialize(using = dateserializer.class,         include=jsonserialize.inclusion.non_null) public date getdate() {     return date; } 

Comments

Popular posts from this blog

jquery - How can I dynamically add a browser tab? -

node.js - Getting the socket id,user id pair of a logged in user(s) -

keyboard - C++ GetAsyncKeyState alternative -