Skip to content

Commit

Permalink
Changes wrt databind/#3043: rename SerializerProvider as `Serializa…
Browse files Browse the repository at this point in the history
…tionContext` (#148)
  • Loading branch information
cowtowncoder authored Nov 29, 2024
1 parent 4673030 commit 02c872a
Show file tree
Hide file tree
Showing 16 changed files with 66 additions and 66 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@
import com.fasterxml.jackson.annotation.JsonFormat;
import tools.jackson.databind.DeserializationContext;
import tools.jackson.databind.DeserializationFeature;
import tools.jackson.databind.SerializationContext;
import tools.jackson.databind.SerializationFeature;
import tools.jackson.databind.SerializerProvider;

/**
* Simple container used to encapsulate (some of) gory details of
Expand Down Expand Up @@ -236,7 +236,7 @@ public DateTimeFormatter rawFormatter() {
return _formatter;
}

public DateTimeFormatter createFormatter(SerializerProvider ctxt)
public DateTimeFormatter createFormatter(SerializationContext ctxt)
{
DateTimeFormatter formatter = createFormatterWithLocale(ctxt);
if (!_explicitTimezone) {
Expand All @@ -248,7 +248,7 @@ public DateTimeFormatter createFormatter(SerializerProvider ctxt)
return formatter;
}

public DateTimeFormatter createFormatterWithLocale(SerializerProvider ctxt)
public DateTimeFormatter createFormatterWithLocale(SerializationContext ctxt)
{
DateTimeFormatter formatter = _formatter;
if (!_explicitLocale) {
Expand Down Expand Up @@ -296,7 +296,7 @@ public boolean shouldAdjustToContextTimeZone(DeserializationContext ctxt) {
/**
* @since 2.8
*/
public boolean shouldWriteWithZoneId(SerializerProvider ctxt) {
public boolean shouldWriteWithZoneId(SerializationContext ctxt) {
return (_writeZoneId != null) ? _writeZoneId :
ctxt.isEnabled(SerializationFeature.WRITE_DATES_WITH_ZONE_ID);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
import java.util.Locale;
import java.util.TimeZone;

import tools.jackson.databind.SerializationContext;
import tools.jackson.databind.SerializationFeature;
import tools.jackson.databind.SerializerProvider;

/**
* Base object for different formatters (date-time, period, ...)
Expand Down Expand Up @@ -78,11 +78,11 @@ protected JacksonJodaFormatBase(JacksonJodaFormatBase base, Locale locale)
/**********************************************************
*/

public boolean useTimestamp(SerializerProvider provider, SerializationFeature feat)
public boolean useTimestamp(SerializationContext ctxt, SerializationFeature feat)
{
if (_useTimestamp != null) {
return _useTimestamp.booleanValue();
}
return provider.isEnabled(feat);
return ctxt.isEnabled(feat);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import org.joda.time.format.PeriodFormatter;

import tools.jackson.databind.DeserializationContext;
import tools.jackson.databind.SerializerProvider;
import tools.jackson.databind.SerializationContext;

/**
* Simple container used to encapsulate (some of) gory details of
Expand Down Expand Up @@ -81,12 +81,12 @@ public JacksonJodaPeriodFormat withLocale(Locale locale) {
/**********************************************************
*/

public PeriodFormatter createFormatter(SerializerProvider provider)
public PeriodFormatter createFormatter(SerializationContext ctxt)
{
PeriodFormatter formatter = _formatter;

if (!_explicitLocale) {
Locale loc = provider.getLocale();
Locale loc = ctxt.getLocale();
if (loc != null && !loc.equals(_locale)) {
formatter = formatter.withLocale(loc);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,22 +36,22 @@ public DateTimeSerializer withFormat(JacksonJodaDateFormat formatter,
}

@Override
public boolean isEmpty(SerializerProvider prov, DateTime value) {
public boolean isEmpty(SerializationContext ctxt, DateTime value) {
return (value.getMillis() == 0L);
}

@Override
public void serialize(DateTime value, JsonGenerator gen, SerializerProvider provider)
public void serialize(DateTime value, JsonGenerator gen, SerializationContext ctxt)
throws JacksonException
{
boolean numeric = (_serializationShape(provider) != FORMAT_STRING);
boolean numeric = (_serializationShape(ctxt) != FORMAT_STRING);

// First: simple, non-timezone-included output
if (!writeWithZoneId(provider)) {
if (!writeWithZoneId(ctxt)) {
if (numeric) {
gen.writeNumber(value.getMillis());
} else {
gen.writeString(_format.createFormatter(provider).print(value));
gen.writeString(_format.createFormatter(ctxt).print(value));
}
} else {
// and then as per [datatype-joda#44], optional TimeZone inclusion
Expand All @@ -69,7 +69,7 @@ public void serialize(DateTime value, JsonGenerator gen, SerializerProvider prov
return;
}
StringBuilder sb = new StringBuilder(40)
.append(_format.createFormatter(provider).withOffsetParsed().print(value));
.append(_format.createFormatter(ctxt).withOffsetParsed().print(value));
sb = sb.append('[')
.append(value.getZone())
.append(']');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import tools.jackson.core.JsonGenerator;
import tools.jackson.core.JsonToken;
import tools.jackson.core.type.WritableTypeId;
import tools.jackson.databind.SerializerProvider;
import tools.jackson.databind.SerializationContext;
import tools.jackson.databind.jsontype.TypeSerializer;

import org.joda.time.DateTimeZone;
Expand All @@ -17,7 +17,7 @@ public class DateTimeZoneSerializer extends JodaSerializerBase<DateTimeZone>
public DateTimeZoneSerializer() { super(DateTimeZone.class); }

@Override
public void serialize(DateTimeZone value, JsonGenerator g, SerializerProvider ctxt)
public void serialize(DateTimeZone value, JsonGenerator g, SerializationContext ctxt)
throws JacksonException
{
g.writeString(value.getID());
Expand All @@ -26,7 +26,7 @@ public void serialize(DateTimeZone value, JsonGenerator g, SerializerProvider ct
// as per [datatype-joda#82], need to ensure we will indicate nominal, NOT physical type:
@Override
public void serializeWithType(DateTimeZone value, JsonGenerator g,
SerializerProvider ctxt, TypeSerializer typeSer)
SerializationContext ctxt, TypeSerializer typeSer)
throws JacksonException
{
WritableTypeId typeIdDef = typeSer.writeTypePrefix(g, ctxt,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
import tools.jackson.core.JacksonException;
import tools.jackson.core.JsonGenerator;

import tools.jackson.databind.SerializationContext;
import tools.jackson.databind.SerializationFeature;
import tools.jackson.databind.SerializerProvider;
import tools.jackson.datatype.joda.cfg.FormatConfig;
import tools.jackson.datatype.joda.cfg.JacksonJodaDateFormat;

Expand Down Expand Up @@ -41,15 +41,15 @@ public DurationSerializer withFormat(JacksonJodaDateFormat formatter,
}

@Override
public boolean isEmpty(SerializerProvider prov, Duration value) {
public boolean isEmpty(SerializationContext ctxt, Duration value) {
return (value.getMillis() == 0L);
}

@Override
public void serialize(Duration value, JsonGenerator g, SerializerProvider provider)
public void serialize(Duration value, JsonGenerator g, SerializationContext ctxt)
throws JacksonException
{
if (_serializationShape(provider) == FORMAT_STRING) {
if (_serializationShape(ctxt) == FORMAT_STRING) {
g.writeString(value.toString());
} else {
g.writeNumber(value.getMillis());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@

import tools.jackson.core.JacksonException;
import tools.jackson.core.JsonGenerator;
import tools.jackson.databind.SerializationContext;
import tools.jackson.databind.SerializationFeature;
import tools.jackson.databind.SerializerProvider;
import tools.jackson.datatype.joda.cfg.FormatConfig;
import tools.jackson.datatype.joda.cfg.JacksonJodaDateFormat;

Expand All @@ -30,16 +30,16 @@ public InstantSerializer withFormat(JacksonJodaDateFormat formatter,
}

@Override
public boolean isEmpty(SerializerProvider prov, Instant value) {
public boolean isEmpty(SerializationContext ctxt, Instant value) {
return (value.getMillis() == 0L);
}

@Override
public void serialize(Instant value, JsonGenerator gen, SerializerProvider provider)
public void serialize(Instant value, JsonGenerator gen, SerializationContext ctxt)
throws JacksonException
{
if (_serializationShape(provider) == FORMAT_STRING) {
gen.writeString(_format.createFormatter(provider).print(value));
if (_serializationShape(ctxt) == FORMAT_STRING) {
gen.writeString(_format.createFormatter(ctxt).print(value));
} else {
gen.writeNumber(value.getMillis());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
import tools.jackson.core.JacksonException;
import tools.jackson.core.JsonGenerator;

import tools.jackson.databind.SerializationContext;
import tools.jackson.databind.SerializationFeature;
import tools.jackson.databind.SerializerProvider;
import tools.jackson.datatype.joda.cfg.FormatConfig;
import tools.jackson.datatype.joda.cfg.JacksonJodaDateFormat;

Expand All @@ -30,20 +30,20 @@ public IntervalSerializer withFormat(JacksonJodaDateFormat formatter,
}

@Override
public boolean isEmpty(SerializerProvider prov, Interval value) {
public boolean isEmpty(SerializationContext ctxt, Interval value) {
return (value.getStartMillis() == value.getEndMillis());
}

@Override
public void serialize(Interval interval, JsonGenerator gen, SerializerProvider provider)
public void serialize(Interval interval, JsonGenerator gen, SerializationContext ctxt)
throws JacksonException
{
// 19-Nov-2014, tatu: Support textual representation similar to what Joda uses
// (and why not exact one? In future we'll make it configurable)
String repr;

if (_serializationShape(provider) == FORMAT_STRING) {
DateTimeFormatter f = _format.createFormatter(provider);
if (_serializationShape(ctxt) == FORMAT_STRING) {
DateTimeFormatter f = _format.createFormatter(ctxt);
repr = f.print(interval.getStart()) + "/" + f.print(interval.getEnd());
} else {
// !!! TODO: maybe allow textual format too?
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,15 +46,15 @@ public abstract JodaDateSerializerBase<T> withFormat(JacksonJodaDateFormat forma
int shapeOverride);

@Override
public boolean isEmpty(SerializerProvider prov, T value) {
public boolean isEmpty(SerializationContext ctxt, T value) {
return value == null;
}

@Override
public ValueSerializer<?> createContextual(SerializerProvider prov,
public ValueSerializer<?> createContextual(SerializationContext ctxt,
BeanProperty property)
{
JsonFormat.Value ann = findFormatOverrides(prov, property, handledType());
JsonFormat.Value ann = findFormatOverrides(ctxt, property, handledType());
if (ann != null) {
int shapeOverride;
Boolean useTimestamp;
Expand Down Expand Up @@ -91,7 +91,7 @@ public ValueSerializer<?> createContextual(SerializerProvider prov,
@Override
public void acceptJsonFormatVisitor(JsonFormatVisitorWrapper visitor, JavaType typeHint)
{
switch (_serializationShape(visitor.getProvider())) {
switch (_serializationShape(visitor.getContext())) {
case FORMAT_TIMESTAMP:
{
JsonIntegerFormatVisitor v2 = visitor.expectIntegerFormat(typeHint);
Expand Down Expand Up @@ -126,17 +126,17 @@ public void acceptJsonFormatVisitor(JsonFormatVisitorWrapper visitor, JavaType t
/**********************************************************
*/

protected boolean writeWithZoneId(SerializerProvider provider) {
return _format.shouldWriteWithZoneId(provider);
protected boolean writeWithZoneId(SerializationContext ctxt) {
return _format.shouldWriteWithZoneId(ctxt);
}

/**
* @since 2.9
*/
protected int _serializationShape(SerializerProvider provider) {
protected int _serializationShape(SerializationContext ctxt) {
int shape = _shapeOverride;
if (shape == 0) {
if (_format.useTimestamp(provider, _featureForNumeric)) {
if (_format.useTimestamp(ctxt, _featureForNumeric)) {
shape = _defaultNumericShape;
} else {
shape = FORMAT_STRING;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import tools.jackson.core.JsonToken;
import tools.jackson.core.type.WritableTypeId;

import tools.jackson.databind.SerializerProvider;
import tools.jackson.databind.SerializationContext;
import tools.jackson.databind.jsontype.TypeSerializer;
import tools.jackson.databind.ser.std.StdSerializer;

Expand All @@ -14,7 +14,7 @@ abstract class JodaSerializerBase<T> extends StdSerializer<T>
protected JodaSerializerBase(Class<T> cls) { super(cls); }

@Override
public void serializeWithType(T value, JsonGenerator g, SerializerProvider ctxt,
public void serializeWithType(T value, JsonGenerator g, SerializationContext ctxt,
TypeSerializer typeSer)
throws JacksonException
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

import tools.jackson.core.*;

import tools.jackson.databind.SerializationContext;
import tools.jackson.databind.SerializationFeature;
import tools.jackson.databind.SerializerProvider;
import tools.jackson.datatype.joda.cfg.FormatConfig;
import tools.jackson.datatype.joda.cfg.JacksonJodaDateFormat;

Expand Down Expand Up @@ -39,11 +39,11 @@ public boolean isEmpty(LocalDate value) {
*/

@Override
public void serialize(LocalDate value, JsonGenerator g, SerializerProvider provider)
public void serialize(LocalDate value, JsonGenerator g, SerializationContext ctxt)
throws JacksonException
{
if (_serializationShape(provider) == FORMAT_STRING) {
g.writeString(_format.createFormatter(provider).print(value));
if (_serializationShape(ctxt) == FORMAT_STRING) {
g.writeString(_format.createFormatter(ctxt).print(value));
return;
}
// 28-Jul-2017, tatu: Wrt [dataformat-joda#39]... we could perhaps support timestamps,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

import tools.jackson.core.*;
import tools.jackson.databind.SerializationFeature;
import tools.jackson.databind.SerializerProvider;
import tools.jackson.databind.SerializationContext;
import tools.jackson.datatype.joda.cfg.FormatConfig;
import tools.jackson.datatype.joda.cfg.JacksonJodaDateFormat;

Expand Down Expand Up @@ -37,18 +37,18 @@ public boolean isEmpty(LocalDateTime value) {
*/

@Override
public void serialize(LocalDateTime value, JsonGenerator gen, SerializerProvider provider)
public void serialize(LocalDateTime value, JsonGenerator gen, SerializationContext ctxt)
throws JacksonException
{
switch (_serializationShape(provider)) {
switch (_serializationShape(ctxt)) {
case FORMAT_STRING:
gen.writeString(_format.createFormatter(provider).print(value));
gen.writeString(_format.createFormatter(ctxt).print(value));
break;
case FORMAT_TIMESTAMP:
{
// copied from `LocalDateTimeDeserializer`...
DateTimeZone tz = _format.isTimezoneExplicit() ? _format.getTimeZone()
: DateTimeZone.forTimeZone(provider.getTimeZone());
: DateTimeZone.forTimeZone(ctxt.getTimeZone());
gen.writeNumber(value.toDateTime(tz).getMillis());
}
break;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
import tools.jackson.core.JacksonException;
import tools.jackson.core.JsonGenerator;

import tools.jackson.databind.SerializationContext;
import tools.jackson.databind.SerializationFeature;
import tools.jackson.databind.SerializerProvider;
import tools.jackson.datatype.joda.cfg.FormatConfig;
import tools.jackson.datatype.joda.cfg.JacksonJodaDateFormat;

Expand Down Expand Up @@ -42,11 +42,11 @@ public boolean isEmpty(LocalTime value) {
*/

@Override
public void serialize(LocalTime value, JsonGenerator g, SerializerProvider provider)
public void serialize(LocalTime value, JsonGenerator g, SerializationContext ctxt)
throws JacksonException
{
if (_serializationShape(provider) == FORMAT_STRING) {
g.writeString(_format.createFormatter(provider).print(value));
if (_serializationShape(ctxt) == FORMAT_STRING) {
g.writeString(_format.createFormatter(ctxt).print(value));
return;
}
// Timestamp here actually means an array of values
Expand Down
Loading

0 comments on commit 02c872a

Please sign in to comment.