Skip to content

Commit 3712808

Browse files
authored
Merge datetime#376 (from 2.21 branch) (minimal, no tests) (#5400)
1 parent 2d06526 commit 3712808

File tree

2 files changed

+30
-19
lines changed

2 files changed

+30
-19
lines changed

src/main/java/tools/jackson/databind/ext/javatime/deser/InstantDeserializer.java

Lines changed: 9 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -206,37 +206,27 @@ protected InstantDeserializer(InstantDeserializer<T> base,
206206
_readTimestampsAsNanosOverride = readTimestampsAsNanosOverride;
207207
}
208208

209-
/*
210-
@SuppressWarnings("unchecked")
211-
protected InstantDeserializer(InstantDeserializer<T> base,
212-
DatatypeFeatures features)
213-
{
214-
super((Class<T>) base.handledType(), base._formatter);
215-
parsedToValue = base.parsedToValue;
216-
fromMilliseconds = base.fromMilliseconds;
217-
fromNanoseconds = base.fromNanoseconds;
218-
adjust = base.adjust;
219-
replaceZeroOffsetAsZ = base.replaceZeroOffsetAsZ;
220-
_adjustToContextTZOverride = base._adjustToContextTZOverride;
221-
_readTimestampsAsNanosOverride = base._readTimestampsAsNanosOverride;
222-
}
223-
*/
224-
209+
/**
210+
* NOTE: {@code public} since 2.21 / 3.1
211+
*/
225212
@Override
226-
protected InstantDeserializer<T> withDateFormat(DateTimeFormatter dtf) {
213+
public InstantDeserializer<T> withDateFormat(DateTimeFormatter dtf) {
227214
if (dtf == _formatter) {
228215
return this;
229216
}
230217
return new InstantDeserializer<>(this, dtf);
231218
}
232219

220+
/**
221+
* NOTE: {@code public} since 2.21 / 3.1
222+
*/
233223
@Override
234-
protected InstantDeserializer<T> withLeniency(Boolean leniency) {
224+
public InstantDeserializer<T> withLeniency(Boolean leniency) {
235225
return new InstantDeserializer<>(this, _formatter, leniency);
236226
}
237227

238228
@SuppressWarnings("unchecked")
239-
@Override // @since 2.12.1
229+
@Override
240230
protected JSR310DateTimeDeserializerBase<?> _withFormatOverrides(DeserializationContext ctxt,
241231
BeanProperty property, JsonFormat.Value formatOverrides)
242232
{

src/main/java/tools/jackson/databind/ext/javatime/ser/OffsetDateTimeSerializer.java

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,27 @@ protected OffsetDateTimeSerializer(OffsetDateTimeSerializer base,
2727
super(base, formatter, useTimestamp, useNanoseconds, shape);
2828
}
2929

30+
/**
31+
* Method for constructing a new {@code OffsetDateTimeSerializer} with settings
32+
* of this serializer but with custom {@link DateTimeFormatter} overrides.
33+
* Commonly used on {@code INSTANCE} like so:
34+
*<pre>
35+
* DateTimeFormatter dtf = new DateTimeFormatterBuilder()
36+
* .append(DateTimeFormatter.ISO_LOCAL_DATE)
37+
* .appendLiteral('T')
38+
* // and so on
39+
* .toFormatter();
40+
* OffsetDateTimeSerializer ser = OffsetDateTimeSerializer.INSTANCE
41+
* .withFormatter(dtf);
42+
* // register via Module
43+
*</pre>
44+
*
45+
* @since 2.21 / 3.1
46+
*/
47+
public OffsetDateTimeSerializer withFormatter(DateTimeFormatter formatter) {
48+
return new OffsetDateTimeSerializer(this, _useTimestamp, formatter, _shape);
49+
}
50+
3051
@Override
3152
protected JSR310FormattedSerializerBase<?> withFormat(DateTimeFormatter formatter,
3253
Boolean useTimestamp,

0 commit comments

Comments
 (0)