Ok. done! https://github.com/FasterXML/jackson-databind/issues/1676
On Saturday, 24 June 2017 07:16:16 UTC+8, Tatu Saloranta wrote: > > That sounds like a bug, make sure to file, along with version it's > reproduced with. > I recall there being some practical challenges in making defaulting work > in pluggable manner (the only other types for which this differs from > 'empty' are primitives and wrappers for them), but as per javadocs these > date/time types should be supported as expected. > > -+ Tatu +- > > > On Fri, Jun 23, 2017 at 10:10 AM, uber_stud_87 via jackson-user < > [email protected] <javascript:>> wrote: > >> Hi, >> >> I tried using @JsonInclude(Include.NON_DEFAULT) on a Date but it doesn't >> work. >> >> >> https://fasterxml.github.io/jackson-annotations/javadoc/2.8/com/fasterxml/jackson/annotation/JsonInclude.Include.html#NON_DEFAULT >> >> When NOT used for a POJO (that is, as a global default, or as property >>> override), definition is such that: >>> All values considered "empty" (as per NON_EMPTY) are excluded >>> Primitive/wrapper default values are excluded >>> Date/time values that have timestamp (`long` value of milliseconds since >>> epoch, see Date) of `0L` are excluded >> >> >> It still serializes the Date as 0 instead of excluding it. I have >> included my code below. >> >> import com.fasterxml.jackson.annotation.JsonInclude; >> import com.fasterxml.jackson.annotation.JsonInclude.Include; >> import com.fasterxml.jackson.databind.ObjectMapper; >> import java.util.Date; >> >> public class NewClass { >> >> public static void main(String[] args) throws Exception { >> >> ObjectMapper objectMapper = new ObjectMapper(); >> >> DTO dto = new DTO(); >> System.out.println(objectMapper.writeValueAsString(dto)); >> // prints out {"date":0} when it should print out {} >> >> } >> >> } >> >> class DTO { >> >> @JsonInclude(Include.NON_DEFAULT) >> private Date date = new Date(0); >> >> public DTO() { >> } >> >> public Date getDate() { >> return date; >> } >> >> public void setDate(Date date) { >> this.date = date; >> } >> >> } >> >> >> -- >> You received this message because you are subscribed to the Google Groups >> "jackson-user" group. >> To unsubscribe from this group and stop receiving emails from it, send an >> email to [email protected] <javascript:>. >> To post to this group, send email to [email protected] >> <javascript:>. >> For more options, visit https://groups.google.com/d/optout. >> > > -- You received this message because you are subscribed to the Google Groups "jackson-user" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To post to this group, send email to [email protected]. For more options, visit https://groups.google.com/d/optout.
