Skip to content

Commit

Permalink
Fix #939
Browse files Browse the repository at this point in the history
  • Loading branch information
cowtowncoder committed Sep 26, 2015
1 parent ed7d416 commit 2a9808c
Show file tree
Hide file tree
Showing 9 changed files with 71 additions and 77 deletions.
4 changes: 4 additions & 0 deletions release-notes/CREDITS
Original file line number Diff line number Diff line change
Expand Up @@ -328,3 +328,7 @@ Sadayuki Furuhashi (frsyuki@github)
Sergio Mira (Sergio-Mira@github)
* Contributed #940: Add missing `hashCode()` implementations for `JsonNode` types that did not have them
(2.6.3)

Andreas Piebe (anpieber@github)
* Reported #939: Regression: DateConversionError in 2.6.x
(2.6.3)
2 changes: 2 additions & 0 deletions release-notes/VERSION
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ Project: jackson-databind
(reported by scubasau@github)
#938: Regression: `StackOverflowError` with recursive types that contain `Map.Entry`
(reported by jloisel@github)
#939: Regression: DateConversionError in 2.6.x
(reported by Andreas P, anpieber@github)
#940: Add missing `hashCode()` implementations for `JsonNode` types that did not have them
(contributed by Sergio M)
#941: Deserialization from "{}" to ObjectNode field causes "out of END_OBJECT token" error
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -276,8 +276,7 @@ public boolean useForType(JavaType t)
STD_VISIBILITY_CHECKER, null, TypeFactory.defaultInstance(),
null, StdDateFormat.instance, null,
Locale.getDefault(),
// TimeZone.getDefault()
TimeZone.getTimeZone("GMT"),
null, // to indicate "use default TimeZone"
Base64Variants.getDefaultVariant() // 2.1
);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -997,14 +997,13 @@ public final void defaultSerializeField(String fieldName, Object value, JsonGene
* Note: date here means "full" date, that is, date AND time, as per
* Java convention (and not date-only values like in SQL)
*/
public final void defaultSerializeDateValue(long timestamp, JsonGenerator jgen)
public final void defaultSerializeDateValue(long timestamp, JsonGenerator gen)
throws IOException
{
// [JACKSON-87]: Support both numeric timestamps and textual
if (isEnabled(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS)) {
jgen.writeNumber(timestamp);
gen.writeNumber(timestamp);
} else {
jgen.writeString(_dateFormat().format(new Date(timestamp)));
gen.writeString(_dateFormat().format(new Date(timestamp)));
}
}

Expand All @@ -1015,10 +1014,8 @@ public final void defaultSerializeDateValue(long timestamp, JsonGenerator jgen)
* Note: date here means "full" date, that is, date AND time, as per
* Java convention (and not date-only values like in SQL)
*/
public final void defaultSerializeDateValue(Date date, JsonGenerator gen)
throws IOException
public final void defaultSerializeDateValue(Date date, JsonGenerator gen) throws IOException
{
// [JACKSON-87]: Support both numeric timestamps and textual
if (isEnabled(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS)) {
gen.writeNumber(date.getTime());
} else {
Expand All @@ -1031,8 +1028,7 @@ public final void defaultSerializeDateValue(Date date, JsonGenerator gen)
* based on {@link SerializationFeature#WRITE_DATE_KEYS_AS_TIMESTAMPS}
* value (and if using textual representation, configured date format)
*/
public void defaultSerializeDateKey(long timestamp, JsonGenerator gen)
throws IOException
public void defaultSerializeDateKey(long timestamp, JsonGenerator gen) throws IOException
{
if (isEnabled(SerializationFeature.WRITE_DATE_KEYS_AS_TIMESTAMPS)) {
gen.writeFieldName(String.valueOf(timestamp));
Expand Down Expand Up @@ -1242,11 +1238,14 @@ protected final DateFormat _dateFormat()
*/
DateFormat df = _config.getDateFormat();
_dateFormat = df = (DateFormat) df.clone();
// 11-Jun-2015, tatu: Plus caller may have actually changed default TimeZone to use
// [databind#939]: 26-Sep-2015, tatu: With 2.6, formatter has been (pre)configured
// with TimeZone, so we should NOT try overriding it unlike with earlier versions
/*
TimeZone tz = getTimeZone();
if (tz != df.getTimeZone()) {
df.setTimeZone(tz);
}
*/
return df;
}
}
65 changes: 53 additions & 12 deletions src/main/java/com/fasterxml/jackson/databind/cfg/BaseSettings.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,16 @@ public final class BaseSettings
// for 2.6
private static final long serialVersionUID = 1L;

/**
* We will use a default TimeZone as the baseline.
*/
private static final TimeZone DEFAULT_TIMEZONE =
// TimeZone.getDefault()
/* [databind#915] 26-Sep-2015, tatu: Should be UTC, plan to change
* it so for 2.7
*/
TimeZone.getTimeZone("GMT");

/*
/**********************************************************
/* Configuration settings; introspection, related
Expand Down Expand Up @@ -109,11 +119,11 @@ public final class BaseSettings
protected final Locale _locale;

/**
* Default {@link java.util.TimeZone} used with serialization formats.
* Default value is {@link TimeZone#getDefault()}, which is typically the
* local time zone (unless overridden for JVM).
* Default {@link java.util.TimeZone} used with serialization formats,
* if (and only if!) explicitly set by use; otherwise `null` to indicate
* "use default", which currently (Jackson 2.6) means "GMT"
*<p>
* Note that if a new value is set, time zone is also assigned to
* Note that if a new value is set, timezone is also assigned to
* {@link #_dateFormat} of this object.
*/
protected final TimeZone _timeZone;
Expand Down Expand Up @@ -231,6 +241,11 @@ public BaseSettings withDateFormat(DateFormat df) {
if (_dateFormat == df) {
return this;
}
// 26-Sep-2015, tatu: Related to [databind#939], let's try to force TimeZone if
// (but only if!) it has been set explicitly.
if ((df != null) && hasExplicitTimeZone()) {
df = _force(df, _timeZone);
}
return new BaseSettings(_classIntrospector, _annotationIntrospector, _visibilityChecker, _propertyNamingStrategy, _typeFactory,
_typeResolverBuilder, df, _handlerInstantiator, _locale,
_timeZone, _defaultBase64);
Expand Down Expand Up @@ -264,14 +279,11 @@ public BaseSettings with(TimeZone tz)
if (tz == null) {
throw new IllegalArgumentException();
}
DateFormat df = _dateFormat;
if (df instanceof StdDateFormat) {
df = ((StdDateFormat) df).withTimeZone(tz);
} else {
// we don't know if original format might be shared; better create a clone:
df = (DateFormat) df.clone();
df.setTimeZone(tz);
if (tz == _timeZone) {
return this;
}

DateFormat df = _force(_dateFormat, tz);
return new BaseSettings(_classIntrospector, _annotationIntrospector,
_visibilityChecker, _propertyNamingStrategy, _typeFactory,
_typeResolverBuilder, df, _handlerInstantiator, _locale,
Expand Down Expand Up @@ -334,10 +346,39 @@ public Locale getLocale() {
}

public TimeZone getTimeZone() {
return _timeZone;
TimeZone tz = _timeZone;
return (tz == null) ? DEFAULT_TIMEZONE : tz;
}

/**
* Accessor that may be called to determine whether this settings object
* has been explicitly configured with a TimeZone (true), or is still
* relying on the default settings (false).
*
* @since 2.7
*/
public boolean hasExplicitTimeZone() {
return (_timeZone != null);
}

public Base64Variant getBase64Variant() {
return _defaultBase64;
}

/*
/**********************************************************
/* Helper methods
/**********************************************************
*/

private DateFormat _force(DateFormat df, TimeZone tz)
{
if (df instanceof StdDateFormat) {
return ((StdDateFormat) df).withTimeZone(tz);
}
// we don't know if original format might be shared; better create a clone:
df = (DateFormat) df.clone();
df.setTimeZone(tz);
return df;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ public static JsonSerializer<Object> getStdKeySerializer(JavaType keyType) {
/**
* @deprecated since 2.7
*/
@Deprecated
public static JsonSerializer<Object> getDefault() {
return DEFAULT_KEY_SERIALIZER;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ public StdDateFormat withTimeZone(TimeZone tz) {
if (tz == null) {
tz = DEFAULT_TIMEZONE;
}
if (tz.equals(_timezone)) {
if ((tz == _timezone) || tz.equals(_timezone)) {
return this;
}
return new StdDateFormat(tz, _locale);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
import com.fasterxml.jackson.core.type.TypeReference;
import com.fasterxml.jackson.databind.*;
import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
import com.fasterxml.jackson.databind.deser.TestCollectionDeserialization.XBean;
import com.fasterxml.jackson.databind.deser.std.StdDeserializer;

@SuppressWarnings("serial")
Expand Down
51 changes: 0 additions & 51 deletions src/test/java/com/fasterxml/jackson/failing/EnumMap749Test.java

This file was deleted.

0 comments on commit 2a9808c

Please sign in to comment.