Skip to content

Commit

Permalink
Fix #70
Browse files Browse the repository at this point in the history
  • Loading branch information
cowtowncoder committed Jul 28, 2015
1 parent c9340a9 commit a24ccc2
Show file tree
Hide file tree
Showing 8 changed files with 40 additions and 9 deletions.
4 changes: 4 additions & 0 deletions release-notes/CREDITS
Original file line number Diff line number Diff line change
Expand Up @@ -40,3 +40,7 @@ Jerry Yang (islanerman@github)
* Contributed #68: TimeZone in DeserializationContext is ignored with
`SerializationFeature.WRITE_DATES_WITH_ZONE_ID`
(2.6.0)

jamesmcmillan@github
* Reported #70: Default DateTime parser format is stricter than
previous versions, causing incompatibility
6 changes: 6 additions & 0 deletions release-notes/VERSION
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,12 @@ Project: jackson-datatype-joda
=== Releases ===
------------------------------------------------------------------------

2.6.1 (not released yet)

#70: Default DateTime parser format is stricter than previous versions,
causing incompatibility
(reported by jamesmcmillan@github)

2.6.0 (19-Jul-2015)

#49: testDateMidnightSerWithTypeInfo test dependent on $TZ
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,22 @@ public class FormatConfig
public final static JacksonJodaDateFormat DEFAULT_TIMEONLY_FORMAT
= new JacksonJodaDateFormat(ISODateTimeFormat.time().withZoneUTC());

public final static JacksonJodaDateFormat DEFAULT_DATETIME_FORMAT
= new JacksonJodaDateFormat(ISODateTimeFormat.dateTime().withZoneUTC());
/* 28-Jul-2015, tatu: As per [datatype-joda#70], there is difference between
* "dateTime()" and "dateTimeParser()"... so we need to differentiate between
* parser/generator it seems.
*/
public final static JacksonJodaDateFormat DEFAULT_DATETIME_PARSER
= new JacksonJodaDateFormat(ISODateTimeFormat.dateTimeParser().withZoneUTC());

public final static JacksonJodaDateFormat DEFAULT_DATETIME_PRINTER
= new JacksonJodaDateFormat(ISODateTimeFormat.dateTime().withZoneUTC());

/**
* @deprecated Since 2.6.1
*/
@Deprecated
public final static JacksonJodaDateFormat DEFAULT_DATETIME_FORMAT = DEFAULT_DATETIME_PRINTER;

public final static JacksonJodaPeriodFormat DEFAULT_PERIOD_FORMAT
= new JacksonJodaPeriodFormat(ISOPeriodFormat.standard());

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public DateTimeDeserializer(Class<?> cls, JacksonJodaDateFormat format) {
public static <T extends ReadableInstant> JsonDeserializer<T> forType(Class<T> cls)
{
return (JsonDeserializer<T>) new DateTimeDeserializer(cls,
FormatConfig.DEFAULT_DATETIME_FORMAT);
FormatConfig.DEFAULT_DATETIME_PARSER);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public class IntervalDeserializer extends JodaDateDeserializerBase<Interval>

public IntervalDeserializer() {
// NOTE: not currently used, but must pass something
this(FormatConfig.DEFAULT_DATETIME_FORMAT);
this(FormatConfig.DEFAULT_DATETIME_PARSER);
}

public IntervalDeserializer(JacksonJodaDateFormat format) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public final class DateTimeSerializer
{
private static final long serialVersionUID = 1L;

public DateTimeSerializer() { this(FormatConfig.DEFAULT_DATETIME_FORMAT); }
public DateTimeSerializer() { this(FormatConfig.DEFAULT_DATETIME_PRINTER); }
public DateTimeSerializer(JacksonJodaDateFormat format) {
// false -> no arrays (numbers)
super(DateTime.class, format, false,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public class IntervalSerializer extends JodaDateSerializerBase<Interval>
{
private static final long serialVersionUID = 1L;

public IntervalSerializer() { this(FormatConfig.DEFAULT_DATETIME_FORMAT); }
public IntervalSerializer() { this(FormatConfig.DEFAULT_DATETIME_PRINTER); }
public IntervalSerializer(JacksonJodaDateFormat format) {
super(Interval.class, format, false,
SerializationFeature.WRITE_DURATIONS_AS_TIMESTAMPS);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,9 +91,10 @@ public void testSerializationDefaultAsTimestamp() throws IOException

public void testSerializationFeatureNoTimestamp() throws IOException
{
ObjectMapper m = jodaMapper();
m.configure(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS, false);
assertEquals(quote("1970-01-01T00:00:00.000Z"), m.writeValueAsString(DATE_JAN_1_1970_UTC));
String json = MAPPER.writer()
.without(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS)
.writeValueAsString(DATE_JAN_1_1970_UTC);
assertEquals(quote("1970-01-01T00:00:00.000Z"), json);
}

public void testAnnotationAsText() throws IOException
Expand All @@ -105,6 +106,13 @@ public void testAnnotationAsText() throws IOException
m.writeValueAsString(new DateAsText(DATE_JAN_1_1970_UTC)));
}

// for [datatype-joda#70]
public void testAsTextNoMilliseconds() throws Exception
{
DateTime value = MAPPER.readValue(quote("2015-07-27T08:11:07-07:00"), DateTime.class);
assertNotNull(value);
}

public void testCustomPatternStyle() throws IOException
{
// or, using annotations
Expand Down

0 comments on commit a24ccc2

Please sign in to comment.