Skip to content

Commit

Permalink
Merge pull request #52 from clamothe/master
Browse files Browse the repository at this point in the history
Fix for #51
  • Loading branch information
cowtowncoder committed Jan 13, 2015
2 parents f75ec11 + aff2c7f commit 2f6dd16
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,12 @@ protected JodaDateSerializerBase(Class<T> type, JacksonJodaDateFormat format,
public final boolean isEmpty(T value) {
return isEmpty(null, value);
}


@Override
public boolean isEmpty(SerializerProvider prov, T value) {
return value == null;
}

@Override
public JsonSerializer<?> createContextual(SerializerProvider prov,
BeanProperty property) throws JsonMappingException
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -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<LocalDate>(date)));
}

public void testLocalDateSerWithTypeInfo() throws IOException
{
LocalDate date = new LocalDate(2001, 5, 25);
Expand Down Expand Up @@ -229,4 +238,16 @@ public void testYearMonthSer() throws Exception
assertEquals(quote("2013-08"), json);
}

private static class Container<T> {
T contents;

public Container(T contents) {
this.contents = contents;
}

public T getContents() {
return contents;
}
}

}

0 comments on commit 2f6dd16

Please sign in to comment.