Skip to content

Commit f8af119

Browse files
committed
Merge branch 'master' into ng-3.0
2 parents 5c48390 + 8fda858 commit f8af119

File tree

6 files changed

+209
-84
lines changed

6 files changed

+209
-84
lines changed

release-notes/VERSION

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ Project: jackson-databind
1111
(reported by ctytgat@github)
1212
#1730: InvalidFormatException` for `JsonToken.VALUE_EMBEDDED_OBJECT`
1313
(reported by zigzago@github)
14+
#1744: StdDateFormat: add option to serialize timezone offset with a colon
15+
(contributed by Bertrand R)
1416
#1745: StdDateFormat: accept and truncate millis larger than 3 digits
1517
(suggested by Bertrand R)
1618
#1749: StdDateFormat: performance improvement of '_format(..)' method

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -945,7 +945,7 @@ public ObjectMapper registerModules(Module... modules)
945945
*
946946
* @since 2.2
947947
*/
948-
public ObjectMapper registerModules(Iterable<Module> modules)
948+
public ObjectMapper registerModules(Iterable<? extends Module> modules)
949949
{
950950
for (Module module : modules) {
951951
registerModule(module);

src/main/java/com/fasterxml/jackson/databind/introspect/AnnotatedMember.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import java.lang.annotation.Annotation;
44
import java.lang.reflect.Member;
5+
import java.util.Collections;
56

67
import com.fasterxml.jackson.databind.util.ClassUtil;
78

@@ -84,6 +85,10 @@ public boolean hasOneOf(Class<? extends Annotation>[] annoClasses) {
8485
return _annotations.hasOneOf(annoClasses);
8586
}
8687

88+
/**
89+
* @deprecated Since 3.0
90+
*/
91+
@Deprecated
8792
public AnnotationMap getAllAnnotations() { // alas, used by at least one module, hence public
8893
return _annotations;
8994
}

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

Lines changed: 77 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,13 @@ public class StdDateFormat
143143

144144
private transient DateFormat _formatRFC1123;
145145

146+
/**
147+
* Whether the TZ offset must be formatted with a colon between hours and minutes ({@code HH:mm} format)
148+
*
149+
* @since 2.9.1
150+
*/
151+
private boolean _tzSerializedWithColon = false;
152+
146153
/*
147154
/**********************************************************
148155
/* Life cycle, accessing singleton "standard" formats
@@ -154,9 +161,18 @@ public StdDateFormat() {
154161
}
155162

156163
protected StdDateFormat(TimeZone tz, Locale loc, Boolean lenient) {
164+
this(tz, loc, lenient, false);
165+
}
166+
167+
/**
168+
* @since 2.9.1
169+
*/
170+
protected StdDateFormat(TimeZone tz, Locale loc, Boolean lenient,
171+
boolean formatTzOffsetWithColon) {
157172
_timezone = tz;
158173
_locale = loc;
159174
_lenient = lenient;
175+
_tzSerializedWithColon = formatTzOffsetWithColon;
160176
}
161177

162178
public static TimeZone getDefaultTimeZone() {
@@ -174,31 +190,61 @@ public StdDateFormat withTimeZone(TimeZone tz) {
174190
if ((tz == _timezone) || tz.equals(_timezone)) {
175191
return this;
176192
}
177-
return new StdDateFormat(tz, _locale, _lenient);
193+
return new StdDateFormat(tz, _locale, _lenient, _tzSerializedWithColon);
178194
}
179195

196+
/**
197+
* "Mutant factory" method that will return an instance that uses specified
198+
* {@code Locale}:
199+
* either {@code this} instance (if setting would not change), or newly
200+
* constructed instance with different {@code Locale} to use.
201+
*/
180202
public StdDateFormat withLocale(Locale loc) {
181203
if (loc.equals(_locale)) {
182204
return this;
183205
}
184-
return new StdDateFormat(_timezone, loc, _lenient);
206+
return new StdDateFormat(_timezone, loc, _lenient, _tzSerializedWithColon);
185207
}
186208

187209
/**
210+
* "Mutant factory" method that will return an instance that has specified leniency
211+
* setting: either {@code this} instance (if setting would not change), or newly
212+
* constructed instance.
213+
*
188214
* @since 2.9
189215
*/
190216
public StdDateFormat withLenient(Boolean b) {
191217
if (_equals(b, _lenient)) {
192218
return this;
193219
}
194-
return new StdDateFormat(_timezone, _locale, b);
220+
return new StdDateFormat(_timezone, _locale, b, _tzSerializedWithColon);
195221
}
196222

223+
/**
224+
* "Mutant factory" method that will return an instance that has specified
225+
* handling of colon when serializing timezone (timezone either written
226+
* like {@code +0500} or {@code +05:00}):
227+
* either {@code this} instance (if setting would not change), or newly
228+
* constructed instance with desired setting for colon inclusion.
229+
*<p>
230+
* NOTE: does NOT affect deserialization as colon is optional accepted
231+
* but not required -- put another way, either serialization is accepted
232+
* by this class.
233+
*
234+
* @since 2.9.1
235+
*/
236+
public StdDateFormat withColonInTimeZone(boolean b) {
237+
if (_tzSerializedWithColon == b) {
238+
return this;
239+
}
240+
return new StdDateFormat(_timezone, _locale, _lenient, b);
241+
}
242+
197243
@Override
198244
public StdDateFormat clone() {
199245
// Although there is that much state to share, we do need to
200246
// orchestrate a bit, mostly since timezones may be changed
201-
return new StdDateFormat(_timezone, _locale, _lenient);
247+
return new StdDateFormat(_timezone, _locale, _lenient, _tzSerializedWithColon);
202248
}
203249

204250
/*
@@ -245,6 +291,24 @@ public boolean isLenient() {
245291
return (_lenient == null) || _lenient.booleanValue();
246292
}
247293

294+
/**
295+
* Accessor for checking whether this instance would include colon
296+
* within timezone serialization or not: if {code true}, timezone offset
297+
* is serialized like {@code -06:00}; if {code false} as {@code -0600}.
298+
*<p>
299+
* NOTE: only relevant for serialization (formatting), as deserialization
300+
* (parsing) always accepts optional colon but does not require it, regardless
301+
* of this setting.
302+
*
303+
* @return {@code true} if a colon is to be inserted between the hours and minutes
304+
* of the TZ offset when serializing as String; otherwise {@code false}
305+
*
306+
* @since 2.9.1
307+
*/
308+
public boolean isColonIncludedInTimeZone() {
309+
return _tzSerializedWithColon;
310+
}
311+
248312
/*
249313
/**********************************************************
250314
/* Public API, parsing
@@ -363,15 +427,20 @@ protected void _format(TimeZone tz, Locale loc, Date date,
363427
int minutes = Math.abs((offset / (60 * 1000)) % 60);
364428
buffer.append(offset < 0 ? '-' : '+');
365429
pad2(buffer, hours);
366-
// 24-Jun-2017, tatu: To add colon or not to add colon? Both are legal...
367-
// tests appear to expect no colon so let's go with that.
368-
// formatted.append(':');
430+
if( _tzSerializedWithColon ) {
431+
buffer.append(':');
432+
}
369433
pad2(buffer, minutes);
370434
} else {
371435
// 24-Jun-2017, tatu: While `Z` would be conveniently short, older specs
372436
// mandate use of full `+0000`
373437
// formatted.append('Z');
374-
buffer.append("+0000");
438+
if( _tzSerializedWithColon ) {
439+
buffer.append("+00:00");
440+
}
441+
else {
442+
buffer.append("+0000");
443+
}
375444
}
376445
}
377446

0 commit comments

Comments
 (0)