Skip to content

Commit 2a9808c

Browse files
committed
Fix #939
1 parent ed7d416 commit 2a9808c

File tree

9 files changed

+71
-77
lines changed

9 files changed

+71
-77
lines changed

release-notes/CREDITS

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -328,3 +328,7 @@ Sadayuki Furuhashi (frsyuki@github)
328328
Sergio Mira (Sergio-Mira@github)
329329
* Contributed #940: Add missing `hashCode()` implementations for `JsonNode` types that did not have them
330330
(2.6.3)
331+
332+
Andreas Piebe (anpieber@github)
333+
* Reported #939: Regression: DateConversionError in 2.6.x
334+
(2.6.3)

release-notes/VERSION

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ Project: jackson-databind
1010
(reported by scubasau@github)
1111
#938: Regression: `StackOverflowError` with recursive types that contain `Map.Entry`
1212
(reported by jloisel@github)
13+
#939: Regression: DateConversionError in 2.6.x
14+
(reported by Andreas P, anpieber@github)
1315
#940: Add missing `hashCode()` implementations for `JsonNode` types that did not have them
1416
(contributed by Sergio M)
1517
#941: Deserialization from "{}" to ObjectNode field causes "out of END_OBJECT token" error

src/main/java/com/fasterxml/jackson/databind/ObjectMapper.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -276,8 +276,7 @@ public boolean useForType(JavaType t)
276276
STD_VISIBILITY_CHECKER, null, TypeFactory.defaultInstance(),
277277
null, StdDateFormat.instance, null,
278278
Locale.getDefault(),
279-
// TimeZone.getDefault()
280-
TimeZone.getTimeZone("GMT"),
279+
null, // to indicate "use default TimeZone"
281280
Base64Variants.getDefaultVariant() // 2.1
282281
);
283282

src/main/java/com/fasterxml/jackson/databind/SerializerProvider.java

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -997,14 +997,13 @@ public final void defaultSerializeField(String fieldName, Object value, JsonGene
997997
* Note: date here means "full" date, that is, date AND time, as per
998998
* Java convention (and not date-only values like in SQL)
999999
*/
1000-
public final void defaultSerializeDateValue(long timestamp, JsonGenerator jgen)
1000+
public final void defaultSerializeDateValue(long timestamp, JsonGenerator gen)
10011001
throws IOException
10021002
{
1003-
// [JACKSON-87]: Support both numeric timestamps and textual
10041003
if (isEnabled(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS)) {
1005-
jgen.writeNumber(timestamp);
1004+
gen.writeNumber(timestamp);
10061005
} else {
1007-
jgen.writeString(_dateFormat().format(new Date(timestamp)));
1006+
gen.writeString(_dateFormat().format(new Date(timestamp)));
10081007
}
10091008
}
10101009

@@ -1015,10 +1014,8 @@ public final void defaultSerializeDateValue(long timestamp, JsonGenerator jgen)
10151014
* Note: date here means "full" date, that is, date AND time, as per
10161015
* Java convention (and not date-only values like in SQL)
10171016
*/
1018-
public final void defaultSerializeDateValue(Date date, JsonGenerator gen)
1019-
throws IOException
1017+
public final void defaultSerializeDateValue(Date date, JsonGenerator gen) throws IOException
10201018
{
1021-
// [JACKSON-87]: Support both numeric timestamps and textual
10221019
if (isEnabled(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS)) {
10231020
gen.writeNumber(date.getTime());
10241021
} else {
@@ -1031,8 +1028,7 @@ public final void defaultSerializeDateValue(Date date, JsonGenerator gen)
10311028
* based on {@link SerializationFeature#WRITE_DATE_KEYS_AS_TIMESTAMPS}
10321029
* value (and if using textual representation, configured date format)
10331030
*/
1034-
public void defaultSerializeDateKey(long timestamp, JsonGenerator gen)
1035-
throws IOException
1031+
public void defaultSerializeDateKey(long timestamp, JsonGenerator gen) throws IOException
10361032
{
10371033
if (isEnabled(SerializationFeature.WRITE_DATE_KEYS_AS_TIMESTAMPS)) {
10381034
gen.writeFieldName(String.valueOf(timestamp));
@@ -1242,11 +1238,14 @@ protected final DateFormat _dateFormat()
12421238
*/
12431239
DateFormat df = _config.getDateFormat();
12441240
_dateFormat = df = (DateFormat) df.clone();
1245-
// 11-Jun-2015, tatu: Plus caller may have actually changed default TimeZone to use
1241+
// [databind#939]: 26-Sep-2015, tatu: With 2.6, formatter has been (pre)configured
1242+
// with TimeZone, so we should NOT try overriding it unlike with earlier versions
1243+
/*
12461244
TimeZone tz = getTimeZone();
12471245
if (tz != df.getTimeZone()) {
12481246
df.setTimeZone(tz);
12491247
}
1248+
*/
12501249
return df;
12511250
}
12521251
}

src/main/java/com/fasterxml/jackson/databind/cfg/BaseSettings.java

Lines changed: 53 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,16 @@ public final class BaseSettings
2626
// for 2.6
2727
private static final long serialVersionUID = 1L;
2828

29+
/**
30+
* We will use a default TimeZone as the baseline.
31+
*/
32+
private static final TimeZone DEFAULT_TIMEZONE =
33+
// TimeZone.getDefault()
34+
/* [databind#915] 26-Sep-2015, tatu: Should be UTC, plan to change
35+
* it so for 2.7
36+
*/
37+
TimeZone.getTimeZone("GMT");
38+
2939
/*
3040
/**********************************************************
3141
/* Configuration settings; introspection, related
@@ -109,11 +119,11 @@ public final class BaseSettings
109119
protected final Locale _locale;
110120

111121
/**
112-
* Default {@link java.util.TimeZone} used with serialization formats.
113-
* Default value is {@link TimeZone#getDefault()}, which is typically the
114-
* local time zone (unless overridden for JVM).
122+
* Default {@link java.util.TimeZone} used with serialization formats,
123+
* if (and only if!) explicitly set by use; otherwise `null` to indicate
124+
* "use default", which currently (Jackson 2.6) means "GMT"
115125
*<p>
116-
* Note that if a new value is set, time zone is also assigned to
126+
* Note that if a new value is set, timezone is also assigned to
117127
* {@link #_dateFormat} of this object.
118128
*/
119129
protected final TimeZone _timeZone;
@@ -231,6 +241,11 @@ public BaseSettings withDateFormat(DateFormat df) {
231241
if (_dateFormat == df) {
232242
return this;
233243
}
244+
// 26-Sep-2015, tatu: Related to [databind#939], let's try to force TimeZone if
245+
// (but only if!) it has been set explicitly.
246+
if ((df != null) && hasExplicitTimeZone()) {
247+
df = _force(df, _timeZone);
248+
}
234249
return new BaseSettings(_classIntrospector, _annotationIntrospector, _visibilityChecker, _propertyNamingStrategy, _typeFactory,
235250
_typeResolverBuilder, df, _handlerInstantiator, _locale,
236251
_timeZone, _defaultBase64);
@@ -264,14 +279,11 @@ public BaseSettings with(TimeZone tz)
264279
if (tz == null) {
265280
throw new IllegalArgumentException();
266281
}
267-
DateFormat df = _dateFormat;
268-
if (df instanceof StdDateFormat) {
269-
df = ((StdDateFormat) df).withTimeZone(tz);
270-
} else {
271-
// we don't know if original format might be shared; better create a clone:
272-
df = (DateFormat) df.clone();
273-
df.setTimeZone(tz);
282+
if (tz == _timeZone) {
283+
return this;
274284
}
285+
286+
DateFormat df = _force(_dateFormat, tz);
275287
return new BaseSettings(_classIntrospector, _annotationIntrospector,
276288
_visibilityChecker, _propertyNamingStrategy, _typeFactory,
277289
_typeResolverBuilder, df, _handlerInstantiator, _locale,
@@ -334,10 +346,39 @@ public Locale getLocale() {
334346
}
335347

336348
public TimeZone getTimeZone() {
337-
return _timeZone;
349+
TimeZone tz = _timeZone;
350+
return (tz == null) ? DEFAULT_TIMEZONE : tz;
338351
}
339352

353+
/**
354+
* Accessor that may be called to determine whether this settings object
355+
* has been explicitly configured with a TimeZone (true), or is still
356+
* relying on the default settings (false).
357+
*
358+
* @since 2.7
359+
*/
360+
public boolean hasExplicitTimeZone() {
361+
return (_timeZone != null);
362+
}
363+
340364
public Base64Variant getBase64Variant() {
341365
return _defaultBase64;
342366
}
367+
368+
/*
369+
/**********************************************************
370+
/* Helper methods
371+
/**********************************************************
372+
*/
373+
374+
private DateFormat _force(DateFormat df, TimeZone tz)
375+
{
376+
if (df instanceof StdDateFormat) {
377+
return ((StdDateFormat) df).withTimeZone(tz);
378+
}
379+
// we don't know if original format might be shared; better create a clone:
380+
df = (DateFormat) df.clone();
381+
df.setTimeZone(tz);
382+
return df;
383+
}
343384
}

src/main/java/com/fasterxml/jackson/databind/ser/std/StdKeySerializers.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,7 @@ public static JsonSerializer<Object> getStdKeySerializer(JavaType keyType) {
8383
/**
8484
* @deprecated since 2.7
8585
*/
86+
@Deprecated
8687
public static JsonSerializer<Object> getDefault() {
8788
return DEFAULT_KEY_SERIALIZER;
8889
}

src/main/java/com/fasterxml/jackson/databind/util/StdDateFormat.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@ public StdDateFormat withTimeZone(TimeZone tz) {
149149
if (tz == null) {
150150
tz = DEFAULT_TIMEZONE;
151151
}
152-
if (tz.equals(_timezone)) {
152+
if ((tz == _timezone) || tz.equals(_timezone)) {
153153
return this;
154154
}
155155
return new StdDateFormat(tz, _locale);

src/test/java/com/fasterxml/jackson/databind/deser/TestMapDeserialization.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111
import com.fasterxml.jackson.core.type.TypeReference;
1212
import com.fasterxml.jackson.databind.*;
1313
import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
14-
import com.fasterxml.jackson.databind.deser.TestCollectionDeserialization.XBean;
1514
import com.fasterxml.jackson.databind.deser.std.StdDeserializer;
1615

1716
@SuppressWarnings("serial")

src/test/java/com/fasterxml/jackson/failing/EnumMap749Test.java

Lines changed: 0 additions & 51 deletions
This file was deleted.

0 commit comments

Comments
 (0)