Skip to content

Commit

Permalink
Deprecate classes in package jsonschema
Browse files Browse the repository at this point in the history
  • Loading branch information
luozhenyu committed Jan 20, 2023
1 parent 4113a82 commit f90d016
Show file tree
Hide file tree
Showing 33 changed files with 85 additions and 36 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ public void serialize(Node value, JsonGenerator g, SerializerProvider provider)
}
}

@Deprecated
@Override
public JsonNode getSchema(SerializerProvider provider, java.lang.reflect.Type typeHint) {
// Well... it is serialized as String
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,13 @@
*
* @author Ryan Heaton
* @author Tatu Saloranta
* @deprecated Since 2.2, we recommend use of external
* <a href="https://github.com/FasterXML/jackson-module-jsonSchema">JSON Schema generator module</a>
*/
@Target(ElementType.TYPE)
@Retention(RetentionPolicy.RUNTIME)
@JacksonAnnotation
@Deprecated
public @interface JsonSerializableSchema
{
/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,11 @@

/**
* Marker interface for schema-aware serializers.
*
* @deprecated Since 2.2, we recommend use of external
* <a href="https://github.com/FasterXML/jackson-module-jsonSchema">JSON Schema generator module</a>
*/
@Deprecated
public interface SchemaAware
{
/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
import com.fasterxml.jackson.databind.annotation.JacksonStdImpl;
import com.fasterxml.jackson.databind.introspect.*;
import com.fasterxml.jackson.databind.jsonFormatVisitors.JsonObjectFormatVisitor;
import com.fasterxml.jackson.databind.jsonschema.SchemaAware;
import com.fasterxml.jackson.databind.jsontype.TypeSerializer;
import com.fasterxml.jackson.databind.node.ObjectNode;
import com.fasterxml.jackson.databind.ser.impl.PropertySerializerMap;
Expand Down Expand Up @@ -874,9 +873,9 @@ public void depositSchemaProperty(ObjectNode propertiesNode,
ser = provider.findValueSerializer(getType(), this);
}
boolean isOptional = !isRequired();
if (ser instanceof SchemaAware) {
schemaNode = ((SchemaAware) ser).getSchema(provider, hint,
isOptional);
if (ser instanceof com.fasterxml.jackson.databind.jsonschema.SchemaAware) {
schemaNode = ((com.fasterxml.jackson.databind.jsonschema.SchemaAware) ser)
.getSchema(provider, hint, isOptional);
} else {
schemaNode = com.fasterxml.jackson.databind.jsonschema.JsonSchema
.getDefaultSchemaNode();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
import com.fasterxml.jackson.databind.introspect.Annotated;
import com.fasterxml.jackson.databind.introspect.BeanPropertyDefinition;
import com.fasterxml.jackson.databind.jsonFormatVisitors.JsonFormatVisitorWrapper;
import com.fasterxml.jackson.databind.jsonschema.SchemaAware;
import com.fasterxml.jackson.databind.jsontype.TypeSerializer;
import com.fasterxml.jackson.databind.node.ObjectNode;
import com.fasterxml.jackson.databind.ser.impl.WritableObjectId;
Expand Down Expand Up @@ -583,8 +582,9 @@ public com.fasterxml.jackson.databind.jsonschema.JsonSchema generateJsonSchema(C
* type information it needs is accessible via "untyped" serializer)
*/
JsonSerializer<Object> ser = findValueSerializer(type, null);
JsonNode schemaNode = (ser instanceof SchemaAware) ?
((SchemaAware) ser).getSchema(this, null) : com.fasterxml.jackson.databind.jsonschema.JsonSchema.getDefaultSchemaNode();
JsonNode schemaNode = (ser instanceof com.fasterxml.jackson.databind.jsonschema.SchemaAware)
? ((com.fasterxml.jackson.databind.jsonschema.SchemaAware) ser).getSchema(this, null)
: com.fasterxml.jackson.databind.jsonschema.JsonSchema.getDefaultSchemaNode();
if (!(schemaNode instanceof ObjectNode)) {
throw new IllegalArgumentException("Class " + type.getName()
+" would not be serialized as a JSON object and therefore has no schema");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,7 @@ private void serializeContentsSlow(String[] value, JsonGenerator gen, Serializer
}
}

@Deprecated
@Override
public JsonNode getSchema(SerializerProvider provider, Type typeHint) {
return createSchemaNode("array", true).set("items", createSchemaNode("string"));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
import com.fasterxml.jackson.databind.*;
import com.fasterxml.jackson.databind.introspect.AnnotatedMember;
import com.fasterxml.jackson.databind.jsonFormatVisitors.JsonFormatVisitorWrapper;
import com.fasterxml.jackson.databind.jsonschema.SchemaAware;
import com.fasterxml.jackson.databind.jsontype.TypeSerializer;
import com.fasterxml.jackson.databind.node.ObjectNode;
import com.fasterxml.jackson.databind.ser.ContainerSerializer;
Expand Down Expand Up @@ -271,16 +270,17 @@ public void serializeWithType(T value, JsonGenerator g, SerializerProvider provi
protected abstract void serializeContents(T value, JsonGenerator gen, SerializerProvider provider)
throws IOException;

@SuppressWarnings("deprecation")
@Deprecated
@Override
public JsonNode getSchema(SerializerProvider provider, Type typeHint)
throws JsonMappingException
{
ObjectNode o = createSchemaNode("array", true);
if (_elementSerializer != null) {
JsonNode schemaNode = null;
if (_elementSerializer instanceof SchemaAware) {
schemaNode = ((SchemaAware) _elementSerializer).getSchema(provider, null);
if (_elementSerializer instanceof com.fasterxml.jackson.databind.jsonschema.SchemaAware) {
schemaNode = ((com.fasterxml.jackson.databind.jsonschema.SchemaAware) _elementSerializer)
.getSchema(provider, null);
}
if (schemaNode == null) {
schemaNode = com.fasterxml.jackson.databind.jsonschema.JsonSchema.getDefaultSchemaNode();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,6 @@
import com.fasterxml.jackson.databind.jsonFormatVisitors.JsonFormatVisitable;
import com.fasterxml.jackson.databind.jsonFormatVisitors.JsonFormatVisitorWrapper;
import com.fasterxml.jackson.databind.jsonFormatVisitors.JsonObjectFormatVisitor;
import com.fasterxml.jackson.databind.jsonschema.JsonSerializableSchema;
import com.fasterxml.jackson.databind.jsonschema.SchemaAware;
import com.fasterxml.jackson.databind.jsontype.TypeSerializer;
import com.fasterxml.jackson.databind.node.ObjectNode;
import com.fasterxml.jackson.databind.ser.*;
Expand All @@ -40,7 +38,7 @@
public abstract class BeanSerializerBase
extends StdSerializer<Object>
implements ContextualSerializer, ResolvableSerializer,
JsonFormatVisitable, SchemaAware
JsonFormatVisitable
{
protected final static PropertyName NAME_FOR_OBJECT_REF = new PropertyName("#object-ref");

Expand Down Expand Up @@ -849,7 +847,8 @@ public JsonNode getSchema(SerializerProvider provider, Type typeHint)
ObjectNode o = createSchemaNode("object", true);
// [JACKSON-813]: Add optional JSON Schema id attribute, if found
// NOTE: not optimal, does NOT go through AnnotationIntrospector etc:
JsonSerializableSchema ann = _handledType.getAnnotation(JsonSerializableSchema.class);
com.fasterxml.jackson.databind.jsonschema.JsonSerializableSchema ann =
_handledType.getAnnotation(com.fasterxml.jackson.databind.jsonschema.JsonSerializableSchema.class);
if (ann != null) {
String id = ann.id();
if (id != null && !id.isEmpty()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ public final void serializeWithType(Object value, JsonGenerator g, SerializerPro
g.writeBoolean(Boolean.TRUE.equals(value));
}

@Deprecated
@Override
public JsonNode getSchema(SerializerProvider provider, Type typeHint) {
return createSchemaNode("boolean", !_forPrimitive);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ public void serializeWithType(byte[] value, JsonGenerator g, SerializerProvider
*/
}

@Deprecated
@Override
public JsonNode getSchema(SerializerProvider provider, Type typeHint)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ public void serialize(Class<?> value, JsonGenerator g, SerializerProvider provid
g.writeString(value.getName());
}

@Deprecated
@Override
public JsonNode getSchema(SerializerProvider provider, Type typeHint)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,7 @@ public boolean isEmpty(SerializerProvider serializers, T value) {

protected abstract long _timestamp(T value);

@Deprecated
@Override
public JsonNode getSchema(SerializerProvider serializers, Type typeHint) {
//todo: (ryan) add a format for the date in the schema?
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,7 @@ public final void serialize(Enum<?> en, JsonGenerator gen, SerializerProvider se
/**********************************************************
*/

@Deprecated
@Override
public JsonNode getSchema(SerializerProvider provider, Type typeHint)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ public void serialize(File value, JsonGenerator g, SerializerProvider provider)
g.writeString(value.getAbsolutePath());
}

@Deprecated
@Override
public JsonNode getSchema(SerializerProvider provider, Type typeHint) {
return createSchemaNode("string", true);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
import com.fasterxml.jackson.databind.jsonFormatVisitors.JsonFormatVisitable;
import com.fasterxml.jackson.databind.jsonFormatVisitors.JsonFormatVisitorWrapper;
import com.fasterxml.jackson.databind.jsonFormatVisitors.JsonStringFormatVisitor;
import com.fasterxml.jackson.databind.jsonschema.SchemaAware;
import com.fasterxml.jackson.databind.jsontype.TypeIdResolver;
import com.fasterxml.jackson.databind.jsontype.TypeSerializer;
import com.fasterxml.jackson.databind.ser.BeanSerializer;
Expand All @@ -41,7 +40,7 @@
@JacksonStdImpl
public class JsonValueSerializer
extends StdSerializer<Object>
implements ContextualSerializer, JsonFormatVisitable, SchemaAware
implements ContextualSerializer, JsonFormatVisitable
{
/**
* @since 2.9
Expand Down Expand Up @@ -302,13 +301,14 @@ public void serializeWithType(Object bean, JsonGenerator gen, SerializerProvider
/**********************************************************
*/

@SuppressWarnings("deprecation")
@Deprecated
@Override
public JsonNode getSchema(SerializerProvider ctxt, Type typeHint)
throws JsonMappingException
{
if (_valueSerializer instanceof SchemaAware) {
return ((SchemaAware)_valueSerializer).getSchema(ctxt, null);
if (_valueSerializer instanceof com.fasterxml.jackson.databind.jsonschema.SchemaAware) {
return ((com.fasterxml.jackson.databind.jsonschema.SchemaAware) _valueSerializer)
.getSchema(ctxt, null);
}
return com.fasterxml.jackson.databind.jsonschema.JsonSchema.getDefaultSchemaNode();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1102,6 +1102,7 @@ public void serializeFilteredAnyProperties(SerializerProvider provider, JsonGene
/**********************************************************
*/

@Deprecated
@Override
public JsonNode getSchema(SerializerProvider provider, Type typeHint)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,8 @@ public void serializeWithType(Object value, JsonGenerator gen, SerializerProvide
{
gen.writeNull();
}


@Deprecated
@Override
public JsonNode getSchema(SerializerProvider provider, Type typeHint) throws JsonMappingException {
return createSchemaNode("null");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ public void serialize(Number value, JsonGenerator g, SerializerProvider provider
}
}

@Deprecated
@Override
public JsonNode getSchema(SerializerProvider provider, Type typeHint) {
return createSchemaNode(_isInt ? "integer" : "number", true);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ protected Base(Class<?> cls, JsonParser.NumberType numberType,
|| (numberType == JsonParser.NumberType.BIG_INTEGER);
}

@Deprecated
@Override
public JsonNode getSchema(SerializerProvider provider, Type typeHint) {
return createSchemaNode(_schemaType, true);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,8 @@ public void serializeWithType(T value, JsonGenerator g, SerializerProvider provi
serialize(value, g, provider);
typeSer.writeTypeSuffix(g, typeIdDef);
}


@Deprecated
@Override
public JsonNode getSchema(SerializerProvider provider, Type typeHint)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ public void serialize(java.sql.Time value, JsonGenerator g, SerializerProvider p
g.writeString(value.toString());
}

@Deprecated
@Override
public JsonNode getSchema(SerializerProvider provider, Type typeHint) {
return createSchemaNode("string", true);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@ public boolean isEmpty(SerializerProvider provider, T value) {
return (value == null) || (value.isEmpty());
}

@Deprecated
@Override
public JsonNode getSchema(SerializerProvider provider, Type typeHint) {
return createSchemaNode("array", true).set("items", contentSchema());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,7 @@ public void serializeContents(boolean[] value, JsonGenerator g, SerializerProvid
}
}

@Deprecated
@Override
public JsonNode getSchema(SerializerProvider provider, Type typeHint)
{
Expand Down Expand Up @@ -232,6 +233,7 @@ public void serializeContents(short[] value, JsonGenerator g, SerializerProvider
}
}

@Deprecated
@Override
public JsonNode getSchema(SerializerProvider provider, Type typeHint)
{
Expand Down Expand Up @@ -307,6 +309,7 @@ private final void _writeArrayContents(JsonGenerator g, char[] value)
}
}

@Deprecated
@Override
public JsonNode getSchema(SerializerProvider provider, Type typeHint)
{
Expand Down Expand Up @@ -397,6 +400,7 @@ public void serializeContents(int[] value, JsonGenerator g, SerializerProvider p
}
}

@Deprecated
@Override
public JsonNode getSchema(SerializerProvider provider, Type typeHint) {
return createSchemaNode("array", true).set("items", createSchemaNode("integer"));
Expand Down Expand Up @@ -469,6 +473,7 @@ public void serializeContents(long[] value, JsonGenerator g, SerializerProvider
}
}

@Deprecated
@Override
public JsonNode getSchema(SerializerProvider provider, Type typeHint)
{
Expand Down Expand Up @@ -547,6 +552,7 @@ public void serializeContents(float[] value, JsonGenerator g, SerializerProvider
}
}

@Deprecated
@Override
public JsonNode getSchema(SerializerProvider provider, Type typeHint) {
return createSchemaNode("array", true).set("items", createSchemaNode("number"));
Expand Down Expand Up @@ -631,6 +637,7 @@ public void serializeContents(double[] value, JsonGenerator g, SerializerProvide
}
}

@Deprecated
@Override
public JsonNode getSchema(SerializerProvider provider, Type typeHint) {
return createSchemaNode("array", true).set("items", createSchemaNode("number"));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
import com.fasterxml.jackson.databind.*;
import com.fasterxml.jackson.databind.jsonFormatVisitors.JsonFormatVisitable;
import com.fasterxml.jackson.databind.jsonFormatVisitors.JsonFormatVisitorWrapper;
import com.fasterxml.jackson.databind.jsonschema.SchemaAware;
import com.fasterxml.jackson.databind.jsontype.TypeSerializer;
import com.fasterxml.jackson.databind.ser.ContextualSerializer;
import com.fasterxml.jackson.databind.ser.ResolvableSerializer;
Expand All @@ -29,7 +28,7 @@
public class StdDelegatingSerializer
extends StdSerializer<Object>
implements ContextualSerializer, ResolvableSerializer,
JsonFormatVisitable, SchemaAware
JsonFormatVisitable
{
protected final Converter<Object,?> _converter;

Expand Down Expand Up @@ -201,22 +200,26 @@ public boolean isEmpty(SerializerProvider prov, Object value)
/**********************************************************
*/

@Deprecated
@Override
public JsonNode getSchema(SerializerProvider provider, Type typeHint)
throws JsonMappingException
{
if (_delegateSerializer instanceof SchemaAware) {
return ((SchemaAware) _delegateSerializer).getSchema(provider, typeHint);
if (_delegateSerializer instanceof com.fasterxml.jackson.databind.jsonschema.SchemaAware) {
return ((com.fasterxml.jackson.databind.jsonschema.SchemaAware) _delegateSerializer)
.getSchema(provider, typeHint);
}
return super.getSchema(provider, typeHint);
}

@Deprecated
@Override
public JsonNode getSchema(SerializerProvider provider, Type typeHint,
boolean isOptional) throws JsonMappingException
{
if (_delegateSerializer instanceof SchemaAware) {
return ((SchemaAware) _delegateSerializer).getSchema(provider, typeHint, isOptional);
if (_delegateSerializer instanceof com.fasterxml.jackson.databind.jsonschema.SchemaAware) {
return ((com.fasterxml.jackson.databind.jsonschema.SchemaAware) _delegateSerializer)
.getSchema(provider, typeHint, isOptional);
}
return super.getSchema(provider, typeHint);
}
Expand Down
Loading

0 comments on commit f90d016

Please sign in to comment.