From 5329b0011d20bf2e7624ab79089c33ecd35a5221 Mon Sep 17 00:00:00 2001 From: Charlie La Mothe Date: Mon, 12 Jan 2015 17:50:36 +0700 Subject: [PATCH] Added a failing test case for issue #51. --- .../datatype/joda/JodaSerializationTest.java | 23 ++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) 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; + } + } + }