diff --git a/src/test/java/com/fasterxml/jackson/datatype/joda/JodaSerializationTest.java b/src/test/java/com/fasterxml/jackson/datatype/joda/JodaSerializationTest.java index 1b707504..71f909ea 100644 --- a/src/test/java/com/fasterxml/jackson/datatype/joda/JodaSerializationTest.java +++ b/src/test/java/com/fasterxml/jackson/datatype/joda/JodaSerializationTest.java @@ -1,7 +1,10 @@ package com.fasterxml.jackson.datatype.joda; import java.io.IOException; +import java.util.HashMap; +import java.util.Map; +import com.fasterxml.jackson.annotation.JsonInclude; import org.joda.time.*; import com.fasterxml.jackson.annotation.JsonTypeInfo; @@ -70,8 +73,14 @@ public void testLocalDateSer() throws IOException ObjectMapper mapper = jodaMapper(); mapper.configure(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS, false); assertEquals(quote("2001-05-25"), mapper.writeValueAsString(date)); + + // We can also configure beans to not include empty values. In this case, + // JodaDateSerializerBase#isEmpty is called to check if the value is empty. + mapper = jodaMapper(); + mapper.setSerializationInclusion(JsonInclude.Include.NON_EMPTY); + assertEquals("{\"contents\":[2001,5,25]}", mapper.writeValueAsString(new Container(date))); } - + public void testLocalDateSerWithTypeInfo() throws IOException { LocalDate date = new LocalDate(2001, 5, 25); @@ -229,4 +238,16 @@ public void testYearMonthSer() throws Exception assertEquals(quote("2013-08"), json); } + private static class Container { + T contents; + + public Container(T contents) { + this.contents = contents; + } + + public T getContents() { + return contents; + } + } + }