Skip to content

Commit

Permalink
Fix #3046 (JsonSerializable -> JacksonSerializable)
Browse files Browse the repository at this point in the history
  • Loading branch information
cowtowncoder committed Feb 8, 2021
1 parent 3c1f3af commit c59045b
Show file tree
Hide file tree
Showing 20 changed files with 67 additions and 62 deletions.
1 change: 1 addition & 0 deletions release-notes/VERSION
Original file line number Diff line number Diff line change
Expand Up @@ -45,5 +45,6 @@ Versions: 3.x (for earlier see VERSION-2.x)
#3028: Change `UUIDSerializer` to use `StreamWriteCapability` check instead of
`JsonGenerator.canWriteBinaryNatively()`
#3037: Rename `Module` as `JacksonModule` in 3.0 (to avoid overlap with `java.lang.Module`)
#3046: Rename `JsonSerializable` as `JacksonSerializable` in 3.0
- Remove `MappingJsonFactory`
- Add context parameter for `TypeSerializer` contextualization (`forProperty()`)
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,13 @@
* so -- if class is a bean, it can be serialized without
* implementing this interface.
*<p>
* Note that while it is possible to just directly implement {@link JsonSerializable},
* Note that while it is possible to just directly implement {@link JacksonSerializable},
* actual implementations are strongly recommended to instead extend
* {@link JsonSerializable.Base}.
* {@link JacksonSerializable.Base}.
*<p>
* NOTE: in Jackson 2.x this type was named {@code JsonSerializable}
*/
public interface JsonSerializable
public interface JacksonSerializable
{
/**
* Serialization method called when no additional type information is
Expand Down Expand Up @@ -47,9 +49,9 @@ public void serializeWithType(JsonGenerator gen, SerializerProvider serializers,
* Base class with minimal implementation, as well as couple of extension methods
* that core Jackson databinding makes use of.
* Use of this base class is strongly recommended over directly implementing
* {@link JsonSerializable}.
* {@link JacksonSerializable}.
*/
public abstract static class Base implements JsonSerializable
public abstract static class Base implements JacksonSerializable
{
/**
* Method that may be called on instance to determine if it is considered
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/com/fasterxml/jackson/databind/JsonNode.java
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
* and {@link ObjectMapper#treeAsTokens(TreeNode)}
*/
public abstract class JsonNode
extends JsonSerializable.Base // i.e. implements JsonSerializable
extends JacksonSerializable.Base // i.e. implements JacksonSerializable
implements TreeNode, Iterable<JsonNode>
{
/*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ public ArrayNode deepCopy()

/*
/**********************************************************
/* Overrides for JsonSerializable.Base
/* Overrides for JacksonSerializable.Base
/**********************************************************
*/

Expand Down Expand Up @@ -169,7 +169,7 @@ public void serialize(JsonGenerator f, SerializerProvider provider)
final int size = c.size();
f.writeStartArray(this, size);
for (int i = 0; i < size; ++i) { // we'll typically have array list
// For now, assuming it's either BaseJsonNode, JsonSerializable
// For now, assuming it's either BaseJsonNode, JacksonSerializable
JsonNode n = c.get(i);
((BaseJsonNode) n).serialize(f, provider);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import com.fasterxml.jackson.core.*;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.JsonSerializable;
import com.fasterxml.jackson.databind.JacksonSerializable;
import com.fasterxml.jackson.databind.SerializerProvider;
import com.fasterxml.jackson.databind.json.JsonMapper;
import com.fasterxml.jackson.databind.jsontype.TypeSerializer;
Expand All @@ -11,7 +11,7 @@
* Abstract base class common to all standard {@link JsonNode}
* implementations.
* The main addition here is that we declare that sub-classes must
* implement {@link JsonSerializable}.
* implement {@link JacksonSerializable}.
* This simplifies object mapping aspects a bit, as no external serializers are needed.
*<p>
* Note that support for {@link java.io.Serializable} is added here and so all subtypes
Expand Down Expand Up @@ -113,7 +113,7 @@ public JsonParser.NumberType numberType() {

/*
/**********************************************************
/* JsonSerializable
/* JacksonSerializable
/**********************************************************
*/

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ public ObjectNode deepCopy()

/*
/**********************************************************
/* Overrides for JsonSerializable.Base
/* Overrides for JacksonSerializable.Base
/**********************************************************
*/

Expand Down Expand Up @@ -307,7 +307,7 @@ public void serialize(JsonGenerator g, SerializerProvider provider)
for (Map.Entry<String, JsonNode> en : _children.entrySet()) {
/* 17-Feb-2009, tatu: Can we trust that all nodes will always
* extend BaseJsonNode? Or if not, at least implement
* JsonSerializable? Let's start with former, change if
* JacksonSerializable? Let's start with former, change if
* we must.
*/
BaseJsonNode value = (BaseJsonNode) en.getValue();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import com.fasterxml.jackson.core.*;

import com.fasterxml.jackson.databind.JsonSerializable;
import com.fasterxml.jackson.databind.JacksonSerializable;
import com.fasterxml.jackson.databind.SerializerProvider;

/**
Expand Down Expand Up @@ -109,8 +109,8 @@ public final void serialize(JsonGenerator gen, SerializerProvider ctxt) throws J
{
if (_value == null) {
ctxt.defaultSerializeNullValue(gen);
} else if (_value instanceof JsonSerializable) {
((JsonSerializable) _value).serialize(gen, ctxt);
} else if (_value instanceof JacksonSerializable) {
((JacksonSerializable) _value).serialize(gen, ctxt);
} else {
// 25-May-2018, tatu: [databind#1991] do not call via generator but through context;
// this to preserve contextual information
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
import com.fasterxml.jackson.databind.introspect.*;
import com.fasterxml.jackson.databind.jsontype.TypeSerializer;
import com.fasterxml.jackson.databind.ser.jackson.JsonValueSerializer;
import com.fasterxml.jackson.databind.ser.jackson.JsonSerializableSerializer;
import com.fasterxml.jackson.databind.ser.jackson.JacksonSerializableSerializer;
import com.fasterxml.jackson.databind.ser.jdk.*;
import com.fasterxml.jackson.databind.ser.std.*;
import com.fasterxml.jackson.databind.type.*;
Expand Down Expand Up @@ -296,12 +296,12 @@ protected final JsonSerializer<?> findSerializerByLookup(JavaType type,

/**
* Method called to see if one of primary per-class annotations
* (or related, like implementing of {@link JsonSerializable})
* (or related, like implementing of {@link JacksonSerializable})
* determines the serializer to use.
*<p>
* Currently handles things like:
*<ul>
* <li>If type implements {@link JsonSerializable}, use that
* <li>If type implements {@link JacksonSerializable}, use that
* </li>
* <li>If type has {@link com.fasterxml.jackson.annotation.JsonValue} annotation (or equivalent), build serializer
* based on that property
Expand All @@ -312,9 +312,9 @@ protected final JsonSerializer<?> findSerializerByAnnotations(SerializerProvider
JavaType type, BeanDescription beanDesc)
{
Class<?> raw = type.getRawClass();
// First: JsonSerializable?
if (JsonSerializable.class.isAssignableFrom(raw)) {
return JsonSerializableSerializer.instance;
// First: serializable by Jackson-specific interface?
if (JacksonSerializable.class.isAssignableFrom(raw)) {
return JacksonSerializableSerializer.instance;
}
// Second: @JsonValue for any type
AnnotatedMember valueAccessor = beanDesc.findJsonValueAccessor();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ protected JsonSerializer<?> _createSerializer2(SerializerProvider ctxt,
}
}
}
// 25-Jun-2015, tatu: Then JsonSerializable, @JsonValue etc. NOTE! Prior to 2.6,
// 25-Jun-2015, tatu: Then JacksonSerializable, @JsonValue etc. NOTE! Prior to 2.6,
// this call was BEFORE custom serializer lookup, which was wrong.
if (ser == null) {
ser = findSerializerByAnnotations(ctxt, type, beanDesc);
Expand All @@ -213,7 +213,7 @@ protected JsonSerializer<?> _createSerializer2(SerializerProvider ctxt,

if (ser == null) {
// Otherwise, we will check "primary types"; both marker types that
// indicate specific handling (JsonSerializable), or main types that have
// indicate specific handling (JacksonSerializable), or main types that have
// precedence over container types
ser = findSerializerByLookup(type, config, beanDesc, formatOverrides, staticTyping);
if (ser == null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,44 +3,46 @@
import com.fasterxml.jackson.core.*;

import com.fasterxml.jackson.databind.JavaType;
import com.fasterxml.jackson.databind.JsonSerializable;
import com.fasterxml.jackson.databind.JacksonSerializable;
import com.fasterxml.jackson.databind.SerializerProvider;
import com.fasterxml.jackson.databind.annotation.JacksonStdImpl;
import com.fasterxml.jackson.databind.jsonFormatVisitors.JsonFormatVisitorWrapper;
import com.fasterxml.jackson.databind.jsontype.TypeSerializer;
import com.fasterxml.jackson.databind.ser.std.StdSerializer;

/**
* Generic handler for types that implement {@link JsonSerializable}.
* Generic handler for types that implement {@link JacksonSerializable}.
*<p>
* Note: given that this is used for anything that implements
* interface, cannot be checked for direct class equivalence.
*<p>
* NOTE: in Jackson 2.x was named {@code JsonSerializableSerializer}
*/
@JacksonStdImpl
public class JsonSerializableSerializer
extends StdSerializer<JsonSerializable>
public class JacksonSerializableSerializer
extends StdSerializer<JacksonSerializable>
{
public final static JsonSerializableSerializer instance = new JsonSerializableSerializer();
public final static JacksonSerializableSerializer instance = new JacksonSerializableSerializer();

protected JsonSerializableSerializer() { super(JsonSerializable.class); }
protected JacksonSerializableSerializer() { super(JacksonSerializable.class); }

@Override
public boolean isEmpty(SerializerProvider serializers, JsonSerializable value) {
if (value instanceof JsonSerializable.Base) {
return ((JsonSerializable.Base) value).isEmpty(serializers);
public boolean isEmpty(SerializerProvider serializers, JacksonSerializable value) {
if (value instanceof JacksonSerializable.Base) {
return ((JacksonSerializable.Base) value).isEmpty(serializers);
}
return false;
}

@Override
public void serialize(JsonSerializable value, JsonGenerator gen, SerializerProvider serializers)
public void serialize(JacksonSerializable value, JsonGenerator gen, SerializerProvider serializers)
throws JacksonException
{
value.serialize(gen, serializers);
}

@Override
public final void serializeWithType(JsonSerializable value, JsonGenerator gen, SerializerProvider serializers,
public final void serializeWithType(JacksonSerializable value, JsonGenerator gen, SerializerProvider serializers,
TypeSerializer typeSer) throws JacksonException
{
value.serializeWithType(gen, serializers, typeSer);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
/**
* We also want to directly support serialization of {@link TokenBuffer};
* and since it is part of core package, it cannot implement
* {@link com.fasterxml.jackson.databind.JsonSerializable}
* {@link com.fasterxml.jackson.databind.JacksonSerializable}
* (which is only included in the mapper package)
*/
@JacksonStdImpl
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

public abstract class TypeBase
extends JavaType
implements JsonSerializable
implements JacksonSerializable
{
private static final long serialVersionUID = 1;

Expand Down Expand Up @@ -148,7 +148,7 @@ public JavaType[] findTypeParameters(Class<?> expType)

/*
/**********************************************************
/* JsonSerializable base implementation
/* JacksonSerializable base implementation
/**********************************************************
*/

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
* @see com.fasterxml.jackson.databind.util.JSONWrappedObject
*/
public class JSONPObject
implements JsonSerializable
implements JacksonSerializable
{
/**
* JSONP function name to use for serialization
Expand Down Expand Up @@ -46,9 +46,9 @@ public JSONPObject(String function, Object value, JavaType asType)
}

/*
/**********************************************************
/* JsonSerializable(WithType) implementation
/**********************************************************
/**********************************************************************
/* JacksonSerializable implementation
/**********************************************************************
*/

@Override
Expand Down Expand Up @@ -94,9 +94,9 @@ public void serialize(JsonGenerator gen, SerializerProvider provider)
}

/*
/**************************************************************
/**********************************************************************
/* Accessors
/**************************************************************
/**********************************************************************
*/

public String getFunction() { return _function; }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
*
* @see com.fasterxml.jackson.databind.util.JSONPObject
*/
public class JSONWrappedObject implements JsonSerializable
public class JSONWrappedObject implements JacksonSerializable
{
/**
* Literal String to output before serialized value.
Expand Down Expand Up @@ -59,7 +59,7 @@ public JSONWrappedObject(String prefix, String suffix, Object value, JavaType as

/*
/**********************************************************************
/* JsonSerializable implementation
/* JacksonSerializable implementation
/**********************************************************************
*/

Expand Down
20 changes: 10 additions & 10 deletions src/main/java/com/fasterxml/jackson/databind/util/RawValue.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import com.fasterxml.jackson.core.JsonGenerator;
import com.fasterxml.jackson.core.SerializableString;

import com.fasterxml.jackson.databind.JsonSerializable;
import com.fasterxml.jackson.databind.JacksonSerializable;
import com.fasterxml.jackson.databind.SerializerProvider;
import com.fasterxml.jackson.databind.jsontype.TypeSerializer;

Expand All @@ -16,11 +16,11 @@
* ({@link com.fasterxml.jackson.databind.JsonNode})
*/
public class RawValue
implements JsonSerializable
implements JacksonSerializable
{
/**
* Contents to serialize. Untyped because there are multiple types that are
* supported: {@link java.lang.String}, {@link JsonSerializable}, {@link SerializableString}.
* supported: {@link java.lang.String}, {@link JacksonSerializable}, {@link SerializableString}.
*/
protected Object _value;

Expand All @@ -32,7 +32,7 @@ public RawValue(SerializableString v) {
_value = v;
}

public RawValue(JsonSerializable v) {
public RawValue(JacksonSerializable v) {
_value = v;
}

Expand All @@ -49,7 +49,7 @@ protected RawValue(Object value, boolean bogus) {

/**
* Accessor for returning enclosed raw value in whatever form it was created in
* (usually {@link java.lang.String}, {link SerializableString}, or any {@link JsonSerializable}).
* (usually {@link java.lang.String}, {link SerializableString}, or any {@link JacksonSerializable}).
*/
public Object rawValue() {
return _value;
Expand All @@ -58,8 +58,8 @@ public Object rawValue() {
@Override
public void serialize(JsonGenerator gen, SerializerProvider serializers) throws JacksonException
{
if (_value instanceof JsonSerializable) {
((JsonSerializable) _value).serialize(gen, serializers);
if (_value instanceof JacksonSerializable) {
((JacksonSerializable) _value).serialize(gen, serializers);
} else {
_serialize(gen);
}
Expand All @@ -69,8 +69,8 @@ public void serialize(JsonGenerator gen, SerializerProvider serializers) throws
public void serializeWithType(JsonGenerator gen, SerializerProvider serializers,
TypeSerializer typeSer) throws JacksonException
{
if (_value instanceof JsonSerializable) {
((JsonSerializable) _value).serializeWithType(gen, serializers, typeSer);
if (_value instanceof JacksonSerializable) {
((JacksonSerializable) _value).serializeWithType(gen, serializers, typeSer);
} else if (_value instanceof SerializableString) {
/* Since these are not really to be deserialized (with or without type info),
* just re-route as regular write, which will create one... hopefully it works
Expand All @@ -81,7 +81,7 @@ public void serializeWithType(JsonGenerator gen, SerializerProvider serializers,

public void serialize(JsonGenerator gen) throws JacksonException
{
if (_value instanceof JsonSerializable) {
if (_value instanceof JacksonSerializable) {
// No SerializerProvider passed, must go via generator, callback
gen.writePOJO(_value);
} else {
Expand Down
Loading

0 comments on commit c59045b

Please sign in to comment.