Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Changes wrt databind/3043 (SerializerProvider -> SerializationContext) #49

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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
{
Expand All @@ -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()) {
Expand Down Expand Up @@ -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<String, JsonValue> entry : ob.entrySet()) {
g.writeName(entry.getKey());
serialize(entry.getValue(), g, provider);
serialize(entry.getValue(), g, ctxt);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<CurrencyUnit>
{
Expand All @@ -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());
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 JodaMoneySerializerBase<T> extends StdSerializer<T>
protected JodaMoneySerializerBase(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 @@ -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;
Expand All @@ -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();
Expand All @@ -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
{
Expand All @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand All @@ -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) {
Expand All @@ -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) {
Expand All @@ -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);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand All @@ -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();
Expand All @@ -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) {
Expand All @@ -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);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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
{
Expand All @@ -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()) {
Expand Down Expand Up @@ -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<String, JsonValue> entry : ob.entrySet()) {
g.writeName(entry.getKey());
serialize(entry.getValue(), g, provider);
serialize(entry.getValue(), g, ctxt);
}
}
}
Expand Down