From eda1fae8ec40d619b8155c49c3ad52a7179617a6 Mon Sep 17 00:00:00 2001 From: Tatu Saloranta Date: Fri, 29 Nov 2024 14:16:49 -0800 Subject: [PATCH] Changes wrt databind/3043 (SerializerProvider -> SerializationContext) --- .../datatype/jsonp/JsonValueSerializer.java | 22 +++++++++---------- .../JakartaInternetAddressSerializer.java | 4 ++-- .../jodamoney/CurrencyUnitSerializer.java | 4 ++-- .../jodamoney/JodaMoneySerializerBase.java | 4 ++-- .../datatype/jodamoney/MoneySerializer.java | 8 +++---- .../datatype/jsonorg/JSONArraySerializer.java | 20 ++++++++--------- .../jsonorg/JSONObjectSerializer.java | 20 ++++++++--------- .../datatype/jsr353/JsonValueSerializer.java | 22 +++++++++---------- 8 files changed, 52 insertions(+), 52 deletions(-) diff --git a/jakarta-jsonp/src/main/java/tools/jackson/datatype/jsonp/JsonValueSerializer.java b/jakarta-jsonp/src/main/java/tools/jackson/datatype/jsonp/JsonValueSerializer.java index c01a9cd..16f2804 100644 --- a/jakarta-jsonp/src/main/java/tools/jackson/datatype/jsonp/JsonValueSerializer.java +++ b/jakarta-jsonp/src/main/java/tools/jackson/datatype/jsonp/JsonValueSerializer.java @@ -4,7 +4,7 @@ import tools.jackson.core.*; 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; @@ -23,27 +23,27 @@ public JsonValueSerializer() { */ @Override - public void serialize(JsonValue value, JsonGenerator g, SerializerProvider provider) + public void serialize(JsonValue value, JsonGenerator g, SerializationContext ctxt) throws JacksonException { switch (value.getValueType()) { case ARRAY: g.writeStartArray(); - serializeArrayContents((JsonArray) value, g, provider); + serializeArrayContents((JsonArray) value, g, ctxt); g.writeEndArray(); break; case OBJECT: g.writeStartObject(value); - serializeObjectContents((JsonObject) value, g, provider); + serializeObjectContents((JsonObject) value, g, ctxt); g.writeEndObject(); break; default: // value type of some kind (scalar) - serializeScalar(value, g, provider); + serializeScalar(value, g, ctxt); } } @Override - public void serializeWithType(JsonValue value, JsonGenerator g, SerializerProvider ctxt, + public void serializeWithType(JsonValue value, JsonGenerator g, SerializationContext ctxt, TypeSerializer typeSer) throws JacksonException { @@ -67,7 +67,7 @@ public void serializeWithType(JsonValue value, JsonGenerator g, SerializerProvid */ protected void serializeScalar(JsonValue value, - JsonGenerator g, SerializerProvider provider) + JsonGenerator g, SerializationContext ctxt) throws JacksonException { switch (value.getValueType()) { @@ -103,24 +103,24 @@ protected void serializeScalar(JsonValue value, } protected void serializeArrayContents(JsonArray values, - JsonGenerator g, SerializerProvider provider) + JsonGenerator g, SerializationContext ctxt) throws JacksonException { if (!values.isEmpty()) { for (JsonValue value : values) { - serialize(value, g, provider); + serialize(value, g, ctxt); } } } protected void serializeObjectContents(JsonObject ob, - JsonGenerator g, SerializerProvider provider) + JsonGenerator g, SerializationContext ctxt) throws JacksonException { if (!ob.isEmpty()) { for (Map.Entry entry : ob.entrySet()) { g.writeName(entry.getKey()); - serialize(entry.getValue(), g, provider); + serialize(entry.getValue(), g, ctxt); } } } diff --git a/jakarta-mail/src/main/java/tools/jackson/datatype/jakarta/mail/JakartaInternetAddressSerializer.java b/jakarta-mail/src/main/java/tools/jackson/datatype/jakarta/mail/JakartaInternetAddressSerializer.java index d3438ca..fcc0d9f 100644 --- a/jakarta-mail/src/main/java/tools/jackson/datatype/jakarta/mail/JakartaInternetAddressSerializer.java +++ b/jakarta-mail/src/main/java/tools/jackson/datatype/jakarta/mail/JakartaInternetAddressSerializer.java @@ -19,7 +19,7 @@ import tools.jackson.core.JacksonException; import tools.jackson.core.JsonGenerator; -import tools.jackson.databind.SerializerProvider; +import tools.jackson.databind.SerializationContext; import tools.jackson.databind.ser.std.StdScalarSerializer; import jakarta.mail.internet.InternetAddress; @@ -34,7 +34,7 @@ public JakartaInternetAddressSerializer() { } @Override - public void serialize(InternetAddress value, JsonGenerator gen, SerializerProvider provider) + public void serialize(InternetAddress value, JsonGenerator gen, SerializationContext ctxt) throws JacksonException { gen.writeString(value.toString()); diff --git a/joda-money/src/main/java/tools/jackson/datatype/jodamoney/CurrencyUnitSerializer.java b/joda-money/src/main/java/tools/jackson/datatype/jodamoney/CurrencyUnitSerializer.java index c6b5725..653fcf5 100644 --- a/joda-money/src/main/java/tools/jackson/datatype/jodamoney/CurrencyUnitSerializer.java +++ b/joda-money/src/main/java/tools/jackson/datatype/jodamoney/CurrencyUnitSerializer.java @@ -5,7 +5,7 @@ import tools.jackson.core.JacksonException; import tools.jackson.core.JsonGenerator; -import tools.jackson.databind.SerializerProvider; +import tools.jackson.databind.SerializationContext; public class CurrencyUnitSerializer extends JodaMoneySerializerBase { @@ -15,7 +15,7 @@ public CurrencyUnitSerializer() { @Override public void serialize(final CurrencyUnit currencyUnit, - final JsonGenerator g, final SerializerProvider ctxt) + final JsonGenerator g, final SerializationContext ctxt) throws JacksonException { g.writeString(currencyUnit.getCode()); diff --git a/joda-money/src/main/java/tools/jackson/datatype/jodamoney/JodaMoneySerializerBase.java b/joda-money/src/main/java/tools/jackson/datatype/jodamoney/JodaMoneySerializerBase.java index 2ae1af5..44581ea 100644 --- a/joda-money/src/main/java/tools/jackson/datatype/jodamoney/JodaMoneySerializerBase.java +++ b/joda-money/src/main/java/tools/jackson/datatype/jodamoney/JodaMoneySerializerBase.java @@ -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; @@ -14,7 +14,7 @@ abstract class JodaMoneySerializerBase extends StdSerializer protected JodaMoneySerializerBase(Class 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 { diff --git a/joda-money/src/main/java/tools/jackson/datatype/jodamoney/MoneySerializer.java b/joda-money/src/main/java/tools/jackson/datatype/jodamoney/MoneySerializer.java index 23560a5..b2d989e 100644 --- a/joda-money/src/main/java/tools/jackson/datatype/jodamoney/MoneySerializer.java +++ b/joda-money/src/main/java/tools/jackson/datatype/jodamoney/MoneySerializer.java @@ -6,7 +6,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 static java.util.Objects.requireNonNull; @@ -27,7 +27,7 @@ public MoneySerializer() { @Override public void serialize(final Money value, - final JsonGenerator g, final SerializerProvider ctxt) + final JsonGenerator g, final SerializationContext ctxt) throws JacksonException { g.writeStartObject(); @@ -39,7 +39,7 @@ public void serialize(final Money value, // serialized as JSON Objects, unlike most other Joda types @Override public void serializeWithType(final Money value, - final JsonGenerator g, final SerializerProvider ctxt, + final JsonGenerator g, final SerializationContext ctxt, final TypeSerializer typeSer) throws JacksonException { @@ -51,7 +51,7 @@ public void serializeWithType(final Money value, } private final void _writeProperties(final Money value, - final JsonGenerator g, final SerializerProvider ctxt) + final JsonGenerator g, final SerializationContext ctxt) throws JacksonException { ctxt.defaultSerializeProperty("amount", amountConverter.fromMoney(value), g); diff --git a/json-org/src/main/java/tools/jackson/datatype/jsonorg/JSONArraySerializer.java b/json-org/src/main/java/tools/jackson/datatype/jsonorg/JSONArraySerializer.java index 0f3ae90..889eee5 100644 --- a/json-org/src/main/java/tools/jackson/datatype/jsonorg/JSONArraySerializer.java +++ b/json-org/src/main/java/tools/jackson/datatype/jsonorg/JSONArraySerializer.java @@ -19,21 +19,21 @@ public JSONArraySerializer() } @Override - public boolean isEmpty(SerializerProvider provider, JSONArray value) { + public boolean isEmpty(SerializationContext ctxt, JSONArray value) { return (value == null) || value.length() == 0; } @Override - public void serialize(JSONArray value, JsonGenerator g, SerializerProvider provider) + public void serialize(JSONArray value, JsonGenerator g, SerializationContext ctxt) throws JacksonException { g.writeStartArray(); - serializeContents(value, g, provider); + serializeContents(value, g, ctxt); g.writeEndArray(); } @Override - public void serializeWithType(JSONArray value, JsonGenerator g, SerializerProvider ctxt, + public void serializeWithType(JSONArray value, JsonGenerator g, SerializationContext ctxt, TypeSerializer typeSer) throws JacksonException { @@ -44,7 +44,7 @@ public void serializeWithType(JSONArray value, JsonGenerator g, SerializerProvid typeSer.writeTypeSuffix(g, ctxt, typeIdDef); } - protected void serializeContents(JSONArray value, JsonGenerator g, SerializerProvider provider) + protected void serializeContents(JSONArray value, JsonGenerator g, SerializationContext ctxt) throws JacksonException { for (int i = 0, len = value.length(); i < len; ++i) { @@ -55,9 +55,9 @@ protected void serializeContents(JSONArray value, JsonGenerator g, SerializerPro } Class cls = ob.getClass(); if (cls == JSONObject.class) { - JSONObjectSerializer.instance.serialize((JSONObject) ob, g, provider); + JSONObjectSerializer.instance.serialize((JSONObject) ob, g, ctxt); } else if (cls == JSONArray.class) { - serialize((JSONArray) ob, g, provider); + serialize((JSONArray) ob, g, ctxt); } else if (cls == String.class) { g.writeString((String) ob); } else if (cls == Integer.class) { @@ -69,11 +69,11 @@ protected void serializeContents(JSONArray value, JsonGenerator g, SerializerPro } else if (cls == Double.class) { g.writeNumber(((Double) ob).doubleValue()); } else if (JSONObject.class.isAssignableFrom(cls)) { // sub-class - JSONObjectSerializer.instance.serialize((JSONObject) ob, g, provider); + JSONObjectSerializer.instance.serialize((JSONObject) ob, g, ctxt); } else if (JSONArray.class.isAssignableFrom(cls)) { // sub-class - serialize((JSONArray) ob, g, provider); + serialize((JSONArray) ob, g, ctxt); } else { - provider.writeValue(g, ob); + ctxt.writeValue(g, ob); } } } diff --git a/json-org/src/main/java/tools/jackson/datatype/jsonorg/JSONObjectSerializer.java b/json-org/src/main/java/tools/jackson/datatype/jsonorg/JSONObjectSerializer.java index 731207e..c8c3254 100644 --- a/json-org/src/main/java/tools/jackson/datatype/jsonorg/JSONObjectSerializer.java +++ b/json-org/src/main/java/tools/jackson/datatype/jsonorg/JSONObjectSerializer.java @@ -20,21 +20,21 @@ public JSONObjectSerializer() } @Override - public boolean isEmpty(SerializerProvider provider, JSONObject value) { + public boolean isEmpty(SerializationContext provider, JSONObject value) { return (value == null) || value.length() == 0; } @Override - public void serialize(JSONObject value, JsonGenerator g, SerializerProvider provider) + public void serialize(JSONObject value, JsonGenerator g, SerializationContext ctxt) throws JacksonException { g.writeStartObject(value); - serializeContents(value, g, provider); + serializeContents(value, g, ctxt); g.writeEndObject(); } @Override - public void serializeWithType(JSONObject value, JsonGenerator g, SerializerProvider ctxt, + public void serializeWithType(JSONObject value, JsonGenerator g, SerializationContext ctxt, TypeSerializer typeSer) throws JacksonException { @@ -46,7 +46,7 @@ public void serializeWithType(JSONObject value, JsonGenerator g, SerializerProvi } - protected void serializeContents(JSONObject value, JsonGenerator g, SerializerProvider provider) + protected void serializeContents(JSONObject value, JsonGenerator g, SerializationContext ctxt) throws JacksonException { Iterator it = value.keys(); @@ -61,9 +61,9 @@ protected void serializeContents(JSONObject value, JsonGenerator g, SerializerPr g.writeName(key); Class cls = ob.getClass(); if (cls == JSONObject.class) { - serialize((JSONObject) ob, g, provider); + serialize((JSONObject) ob, g, ctxt); } else if (cls == JSONArray.class) { - JSONArraySerializer.instance.serialize((JSONArray) ob, g, provider); + JSONArraySerializer.instance.serialize((JSONArray) ob, g, ctxt); } else if (cls == String.class) { g.writeString((String) ob); } else if (cls == Integer.class) { @@ -75,11 +75,11 @@ protected void serializeContents(JSONObject value, JsonGenerator g, SerializerPr } else if (cls == Double.class) { g.writeNumber(((Double) ob).doubleValue()); } else if (JSONObject.class.isAssignableFrom(cls)) { // sub-class - serialize((JSONObject) ob, g, provider); + serialize((JSONObject) ob, g, ctxt); } else if (JSONArray.class.isAssignableFrom(cls)) { // sub-class - JSONArraySerializer.instance.serialize((JSONArray) ob, g, provider); + JSONArraySerializer.instance.serialize((JSONArray) ob, g, ctxt); } else { - provider.writeValue(g, ob); + ctxt.writeValue(g, ob); } } } diff --git a/jsr-353/src/main/java/tools/jackson/datatype/jsr353/JsonValueSerializer.java b/jsr-353/src/main/java/tools/jackson/datatype/jsr353/JsonValueSerializer.java index 09762df..d11c56f 100644 --- a/jsr-353/src/main/java/tools/jackson/datatype/jsr353/JsonValueSerializer.java +++ b/jsr-353/src/main/java/tools/jackson/datatype/jsr353/JsonValueSerializer.java @@ -6,7 +6,7 @@ import tools.jackson.core.*; 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; @@ -23,27 +23,27 @@ public JsonValueSerializer() { */ @Override - public void serialize(JsonValue value, JsonGenerator g, SerializerProvider provider) + public void serialize(JsonValue value, JsonGenerator g, SerializationContext ctxt) throws JacksonException { switch (value.getValueType()) { case ARRAY: g.writeStartArray(); - serializeArrayContents((JsonArray) value, g, provider); + serializeArrayContents((JsonArray) value, g, ctxt); g.writeEndArray(); break; case OBJECT: g.writeStartObject(value); - serializeObjectContents((JsonObject) value, g, provider); + serializeObjectContents((JsonObject) value, g, ctxt); g.writeEndObject(); break; default: // value type of some kind (scalar) - serializeScalar(value, g, provider); + serializeScalar(value, g, ctxt); } } @Override - public void serializeWithType(JsonValue value, JsonGenerator g, SerializerProvider ctxt, + public void serializeWithType(JsonValue value, JsonGenerator g, SerializationContext ctxt, TypeSerializer typeSer) throws JacksonException { @@ -67,7 +67,7 @@ public void serializeWithType(JsonValue value, JsonGenerator g, SerializerProvid */ protected void serializeScalar(JsonValue value, - JsonGenerator g, SerializerProvider provider) + JsonGenerator g, SerializationContext ctxt) throws JacksonException { switch (value.getValueType()) { @@ -103,24 +103,24 @@ protected void serializeScalar(JsonValue value, } protected void serializeArrayContents(JsonArray values, - JsonGenerator g, SerializerProvider provider) + JsonGenerator g, SerializationContext ctxt) throws JacksonException { if (!values.isEmpty()) { for (JsonValue value : values) { - serialize(value, g, provider); + serialize(value, g, ctxt); } } } protected void serializeObjectContents(JsonObject ob, - JsonGenerator g, SerializerProvider provider) + JsonGenerator g, SerializationContext ctxt) throws JacksonException { if (!ob.isEmpty()) { for (Map.Entry entry : ob.entrySet()) { g.writeName(entry.getKey()); - serialize(entry.getValue(), g, provider); + serialize(entry.getValue(), g, ctxt); } } }