Skip to content

Commit

Permalink
Fix for FasterXML#1154
Browse files Browse the repository at this point in the history
Partially roll back to pre-FasterXML#1111 behavior.
We just make sure that the STRING shape is chosen when Shape.ANY (the default) is set on the annotation, but some other annotation attribute was also set (pattern, locale or timezone).
This way of fixing the issue has the added benefit of respecting the user config regarding the default serialization of strings when @jsonformat(shape = Shape.ANY) is set on a property.
  • Loading branch information
yrodiere committed Mar 8, 2016
1 parent ae5695c commit 0251069
Showing 1 changed file with 15 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -59,20 +59,21 @@ public JsonSerializer<?> createContextual(SerializerProvider serializers,
return withFormat(Boolean.TRUE, null);
}

if (format.getShape() == JsonFormat.Shape.STRING) {
TimeZone tz = format.getTimeZone();
final String pattern = format.hasPattern()
? format.getPattern()
: StdDateFormat.DATE_FORMAT_STR_ISO8601;
final Locale loc = format.hasLocale()
? format.getLocale()
: serializers.getLocale();
SimpleDateFormat df = new SimpleDateFormat(pattern, loc);
if (tz == null) {
tz = serializers.getTimeZone();
}
df.setTimeZone(tz);
return withFormat(Boolean.FALSE, df);
if (format.getShape() == JsonFormat.Shape.STRING || format.hasPattern()
|| format.hasLocale() || format.hasTimeZone()) {
TimeZone tz = format.getTimeZone();
final String pattern = format.hasPattern()
? format.getPattern()
: StdDateFormat.DATE_FORMAT_STR_ISO8601;
final Locale loc = format.hasLocale()
? format.getLocale()
: serializers.getLocale();
SimpleDateFormat df = new SimpleDateFormat(pattern, loc);
if (tz == null) {
tz = serializers.getTimeZone();
}
df.setTimeZone(tz);
return withFormat(Boolean.FALSE, df);
}
}
}
Expand Down

0 comments on commit 0251069

Please sign in to comment.