From b9c9d01e7673524c6f7ec4f7d0f9c6632bddc7c1 Mon Sep 17 00:00:00 2001 From: jackphel Date: Thu, 26 Jul 2012 15:04:03 -0400 Subject: [PATCH 01/19] tentative json schema java representation. --- .../databind/jsonschema/JsonSchema.java | 5 +- .../databind/jsonschema/SchemaFactory.java | 7 + .../databind/jsonschema/types/AnySchema.java | 7 + .../jsonschema/types/ArraySchema.java | 86 +++++ .../jsonschema/types/BooleanSchema.java | 8 + .../jsonschema/types/ContainerTypeSchema.java | 6 + .../jsonschema/types/HyperSchema.java | 322 ++++++++++++++++++ .../jsonschema/types/IntegerSchema.java | 16 + .../databind/jsonschema/types/NullSchema.java | 10 + .../jsonschema/types/NumberSchema.java | 29 ++ .../jsonschema/types/ObjectSchema.java | 112 ++++++ .../databind/jsonschema/types/Schema.java | 215 ++++++++++++ .../databind/jsonschema/types/SchemaType.java | 37 ++ .../jsonschema/types/SimpleTypeSchema.java | 39 +++ .../jsonschema/types/StringSchema.java | 23 ++ .../jsonschema/types/UnionTypeSchema.java | 13 + .../jsonschema/types/ValueTypeSchema.java | 78 +++++ .../ser/impl/SimpleBeanPropertyFilter.java | 6 +- .../databind/ser/std/BeanSerializerBase.java | 45 +-- 19 files changed, 1017 insertions(+), 47 deletions(-) create mode 100644 src/main/java/com/fasterxml/jackson/databind/jsonschema/SchemaFactory.java create mode 100644 src/main/java/com/fasterxml/jackson/databind/jsonschema/types/AnySchema.java create mode 100644 src/main/java/com/fasterxml/jackson/databind/jsonschema/types/ArraySchema.java create mode 100644 src/main/java/com/fasterxml/jackson/databind/jsonschema/types/BooleanSchema.java create mode 100644 src/main/java/com/fasterxml/jackson/databind/jsonschema/types/ContainerTypeSchema.java create mode 100644 src/main/java/com/fasterxml/jackson/databind/jsonschema/types/HyperSchema.java create mode 100644 src/main/java/com/fasterxml/jackson/databind/jsonschema/types/IntegerSchema.java create mode 100644 src/main/java/com/fasterxml/jackson/databind/jsonschema/types/NullSchema.java create mode 100644 src/main/java/com/fasterxml/jackson/databind/jsonschema/types/NumberSchema.java create mode 100644 src/main/java/com/fasterxml/jackson/databind/jsonschema/types/ObjectSchema.java create mode 100644 src/main/java/com/fasterxml/jackson/databind/jsonschema/types/Schema.java create mode 100644 src/main/java/com/fasterxml/jackson/databind/jsonschema/types/SchemaType.java create mode 100644 src/main/java/com/fasterxml/jackson/databind/jsonschema/types/SimpleTypeSchema.java create mode 100644 src/main/java/com/fasterxml/jackson/databind/jsonschema/types/StringSchema.java create mode 100644 src/main/java/com/fasterxml/jackson/databind/jsonschema/types/UnionTypeSchema.java create mode 100644 src/main/java/com/fasterxml/jackson/databind/jsonschema/types/ValueTypeSchema.java diff --git a/src/main/java/com/fasterxml/jackson/databind/jsonschema/JsonSchema.java b/src/main/java/com/fasterxml/jackson/databind/jsonschema/JsonSchema.java index e79a68a818..781810dbf6 100644 --- a/src/main/java/com/fasterxml/jackson/databind/jsonschema/JsonSchema.java +++ b/src/main/java/com/fasterxml/jackson/databind/jsonschema/JsonSchema.java @@ -1,5 +1,8 @@ package com.fasterxml.jackson.databind.jsonschema; +import java.math.BigDecimal; +import java.util.Map; + import com.fasterxml.jackson.annotation.JsonCreator; import com.fasterxml.jackson.annotation.JsonValue; @@ -82,5 +85,5 @@ public static JsonNode getDefaultSchemaNode() //objectNode.put("required", false); return objectNode; } - + } diff --git a/src/main/java/com/fasterxml/jackson/databind/jsonschema/SchemaFactory.java b/src/main/java/com/fasterxml/jackson/databind/jsonschema/SchemaFactory.java new file mode 100644 index 0000000000..25a86af2fa --- /dev/null +++ b/src/main/java/com/fasterxml/jackson/databind/jsonschema/SchemaFactory.java @@ -0,0 +1,7 @@ +package com.fasterxml.jackson.databind.jsonschema; + +public class SchemaFactory { + + + +} diff --git a/src/main/java/com/fasterxml/jackson/databind/jsonschema/types/AnySchema.java b/src/main/java/com/fasterxml/jackson/databind/jsonschema/types/AnySchema.java new file mode 100644 index 0000000000..66578395e6 --- /dev/null +++ b/src/main/java/com/fasterxml/jackson/databind/jsonschema/types/AnySchema.java @@ -0,0 +1,7 @@ +package com.fasterxml.jackson.databind.jsonschema.types; + +import com.fasterxml.jackson.databind.node.TextNode; + +public class AnySchema extends ValueTypeSchema { + public static final TextNode type = TextNode.valueOf(SchemaType.ANY.toString()); +} \ No newline at end of file diff --git a/src/main/java/com/fasterxml/jackson/databind/jsonschema/types/ArraySchema.java b/src/main/java/com/fasterxml/jackson/databind/jsonschema/types/ArraySchema.java new file mode 100644 index 0000000000..eebe10b069 --- /dev/null +++ b/src/main/java/com/fasterxml/jackson/databind/jsonschema/types/ArraySchema.java @@ -0,0 +1,86 @@ +package com.fasterxml.jackson.databind.jsonschema.types; + +import com.fasterxml.jackson.databind.node.TextNode; + +/* + * This attribute defines the allowed items in an instance array, and + MUST be a schema or an array of schemas. The default value is an + empty schema which allows any value for items in the instance array. + */ +public class ArraySchema extends ContainerTypeSchema { + public static final TextNode type = TextNode.valueOf(SchemaType.ARRAY.toString()); + + //This attribute defines the minimum number of values in an array + private int minItems; + + //This attribute defines the maximum number of values in an array + private int maxItems; + + /* + * This attribute indicates that all items in an array instance MUST be + unique (contains no two identical values). + + Two instance are consider equal if they are both of the same type + and: + + are null; or are booleans/numbers/strings and have the same value; or + + are arrays, contains the same number of items, and each item in + the array is equal to the corresponding item in the other array; + or + + are objects, contains the same property names, and each property + in the object is equal to the corresponding property in the other + object. + */ + private boolean uniqueItems; + + private ArraySchema.Items items; + + private ArraySchema.AdditionalItems additionalItems; + + /* + * This attribute defines the allowed items in an instance array, and + MUST be a schema or an array of schemas. The default value is an + empty schema which allows any value for items in the instance array. + */ + public static abstract class Items {} + + /* + * When this attribute value is a schema and the instance value is an + array, then all the items in the array MUST be valid according to the + schema. + */ + public static class SingleItems extends ArraySchema.Items { + public static final ArraySchema.SingleItems defaultSingleItems = new SingleItems(); + } + + /* + * When this attribute value is an array of schemas and the instance + value is an array, each position in the instance array MUST conform + to the schema in the corresponding position for this array. This + called tuple typing. When tuple typing is used, additional items are + allowed, disallowed, or constrained by the "additionalItems" + */ + public static class ArrayItems extends ArraySchema.Items {} + + /* + * This provides a definition for additional items in an array instance + when tuple definitions of the items is provided. + */ + public static abstract class AdditionalItems {} + + /* + * This can be false + to indicate additional items in the array are not allowed + */ + public static class NoAdditionalItems {} + + /* + * or it can + be a schema that defines the schema of the additional items. + */ + public static class SchemaAdditionalItems { + private Schema schema; + } + } \ No newline at end of file diff --git a/src/main/java/com/fasterxml/jackson/databind/jsonschema/types/BooleanSchema.java b/src/main/java/com/fasterxml/jackson/databind/jsonschema/types/BooleanSchema.java new file mode 100644 index 0000000000..198e10c813 --- /dev/null +++ b/src/main/java/com/fasterxml/jackson/databind/jsonschema/types/BooleanSchema.java @@ -0,0 +1,8 @@ +package com.fasterxml.jackson.databind.jsonschema.types; + +import com.fasterxml.jackson.databind.node.BooleanNode; +import com.fasterxml.jackson.databind.node.TextNode; + +public class BooleanSchema extends ValueTypeSchema { + public static final TextNode type = TextNode.valueOf(SchemaType.BOOLEAN.toString()); +} \ No newline at end of file diff --git a/src/main/java/com/fasterxml/jackson/databind/jsonschema/types/ContainerTypeSchema.java b/src/main/java/com/fasterxml/jackson/databind/jsonschema/types/ContainerTypeSchema.java new file mode 100644 index 0000000000..5b3f27738a --- /dev/null +++ b/src/main/java/com/fasterxml/jackson/databind/jsonschema/types/ContainerTypeSchema.java @@ -0,0 +1,6 @@ +package com.fasterxml.jackson.databind.jsonschema.types; + + +public abstract class ContainerTypeSchema extends SimpleTypeSchema { + +} \ No newline at end of file diff --git a/src/main/java/com/fasterxml/jackson/databind/jsonschema/types/HyperSchema.java b/src/main/java/com/fasterxml/jackson/databind/jsonschema/types/HyperSchema.java new file mode 100644 index 0000000000..64881d0179 --- /dev/null +++ b/src/main/java/com/fasterxml/jackson/databind/jsonschema/types/HyperSchema.java @@ -0,0 +1,322 @@ +package com.fasterxml.jackson.databind.jsonschema.types; + +import com.fasterxml.jackson.databind.jsonschema.types.HyperSchema.LinkDescriptionObject; +import com.fasterxml.jackson.databind.node.TextNode; + +public class HyperSchema extends Schema { + + + /* + * This attribute indicates that the instance property SHOULD NOT be + changed. Attempts by a user agent to modify the value of this + property are expected to be rejected by a server. + */ + private TextNode readOnly; + + /* + * If the instance property value is a string, this attribute defines + that the string SHOULD be interpreted as binary data and decoded + using the encoding named by this schema property. RFC 2045, Sec 6.1 + [RFC2045] lists the possible values for this property. + */ + private TextNode contentEncoding; + + + /* + * This attribute is a URI that defines what the instance's URI MUST + start with in order to validate. The value of the "pathStart" + attribute MUST be resolved as per RFC 3986, Sec 5 [RFC3986], and is + relative to the instance's URI. + + When multiple schemas have been referenced for an instance, the user + agent can determine if this schema is applicable for a particular + instance by determining if the URI of the instance begins with the + the value of the "pathStart" attribute. If the URI of the instance + does not start with this URI, or if another schema specifies a + starting URI that is longer and also matches the instance, this + schema SHOULD NOT be applied to the instance. Any schema that does + not have a pathStart attribute SHOULD be considered applicable to all + the instances for which it is referenced. + */ + private TextNode pathStart; + + /* + * This attribute defines the media type of the instance representations + that this schema is defining. + */ + private TextNode mediaType; + + /* + * This property indicates the fragment resolution protocol to use for + resolving fragment identifiers in URIs within the instance + representations. This applies to the instance object URIs and all + children of the instance object's URIs. The default fragment + resolution protocol is "slash-delimited", which is defined below. + Other fragment resolution protocols MAY be used, but are not defined + in this document. + + The fragment identifier is based on RFC 2396, Sec 5 [RFC2396], and + defines the mechanism for resolving references to entities within a + document. + */ + private TextNode fragmentResolution; + /* + * 6.2.1. slash-delimited fragment resolution + + With the slash-delimited fragment resolution protocol, the fragment + identifier is interpreted as a series of property reference tokens + that start with and are delimited by the "/" character (\x2F). Each + property reference token is a series of unreserved or escaped URI + characters. Each property reference token SHOULD be interpreted, + starting from the beginning of the fragment identifier, as a path + reference in the target JSON structure. The final target value of + the fragment can be determined by starting with the root of the JSON + structure from the representation of the resource identified by the + pre-fragment URI. If the target is a JSON object, then the new + target is the value of the property with the name identified by the + next property reference token in the fragment. If the target is a + JSON array, then the target is determined by finding the item in + array the array with the index defined by the next property reference + token (which MUST be a number). The target is successively updated + for each property reference token, until the entire fragment has been + traversed. + + Property names SHOULD be URI-encoded. In particular, any "/" in a + property name MUST be encoded to avoid being interpreted as a + property delimiter. + + For example, for the following JSON representation: + + { + "foo":{ + "anArray":[ + {"prop":44} + ], + "another prop":{ + "baz":"A string" + } + } + } + + The following fragment identifiers would be resolved: + + fragment identifier resolution + ------------------- ---------- + # self, the root of the resource itself + #/foo the object referred to by the foo property + #/foo/another%20prop the object referred to by the "another prop" + property of the object referred to by the + "foo" property + #/foo/another%20prop/baz the string referred to by the value of "baz" + property of the "another prop" property of + the object referred to by the "foo" property + #/foo/anArray/0 the first object in the "anArray" array + + 6.2.2. dot-delimited fragment resolution + + The dot-delimited fragment resolution protocol is the same as slash- + delimited fragment resolution protocol except that the "." character + (\x2E) is used as the delimiter between property names (instead of + "/") and the path does not need to start with a ".". For example, + #.foo and #foo are a valid fragment identifiers for referencing the + value of the foo propery. + */ + + private LinkDescriptionObject[] links; + + /* + * A link description object is used to describe link relations. In the + context of a schema, it defines the link relations of the instances + of the schema, and can be parameterized by the instance values. The + link description format can be used on its own in regular (non-schema + documents), and use of this format can be declared by referencing the + normative link description schema as the the schema for the data + structure that uses the links. + */ + public class LinkDescriptionObject { + + /* + * The value of the "href" link description property indicates the + target URI of the related resource. The value of the instance + property SHOULD be resolved as a URI-Reference per RFC 3986 [RFC3986] + and MAY be a relative URI. The base URI to be used for relative + resolution SHOULD be the URI used to retrieve the instance object + (not the schema) when used within a schema. Also, when links are + used within a schema, the URI SHOULD be parametrized by the property + values of the instance object, if property values exist for the + corresponding variables in the template (otherwise they MAY be + provided from alternate sources, like user input). + + Instance property values SHOULD be substituted into the URIs where + matching braces ('{', '}') are found surrounding zero or more + characters, creating an expanded URI. Instance property value + substitutions are resolved by using the text between the braces to + denote the property name from the instance to get the value to + substitute. For example, if an href value is defined: + + http://somesite.com/{id} + + Then it would be resolved by replace the value of the "id" property + value from the instance object. If the value of the "id" property + was "45", the expanded URI would be: + + http://somesite.com/45 + + If matching braces are found with the string "@" (no quotes) between + the braces, then the actual instance value SHOULD be used to replace + the braces, rather than a property value. This should only be used + in situations where the instance is a scalar (string, boolean, or + number), and not for objects or arrays. + + */ + private TextNode href; + + /* + * The value of the "rel" property indicates the name of the relation to + the target resource. The relation to the target SHOULD be + interpreted as specifically from the instance object that the schema + (or sub-schema) applies to, not just the top level resource that + contains the object within its hierarchy. If a resource JSON + representation contains a sub object with a property interpreted as a + link, that sub-object holds the relation with the target. A relation + to target from the top level resource MUST be indicated with the + schema describing the top level JSON representation. + + Relationship definitions SHOULD NOT be media type dependent, and + users are encouraged to utilize existing accepted relation + definitions, including those in existing relation registries (see RFC + 4287 [RFC4287]). However, we define these relations here for clarity + of normative interpretation within the context of JSON hyper schema + defined relations: + + self If the relation value is "self", when this property is + encountered in the instance object, the object represents a + resource and the instance object is treated as a full + representation of the target resource identified by the specified + URI. + + full This indicates that the target of the link is the full + representation for the instance object. The object that contains + this link possibly may not be the full representation. + + describedby This indicates the target of the link is the schema for + the instance object. This MAY be used to specifically denote the + schemas of objects within a JSON object hierarchy, facilitating + polymorphic type data structures. + + root This relation indicates that the target of the link SHOULD be + treated as the root or the body of the representation for the + purposes of user agent interaction or fragment resolution. All + other properties of the instance objects can be regarded as meta- + data descriptions for the data. + + The following relations are applicable for schemas (the schema as the + "from" resource in the relation): + + instances This indicates the target resource that represents + collection of instances of a schema. + + create This indicates a target to use for creating new instances of + a schema. This link definition SHOULD be a submission link with a + non-safe method (like POST). + + For example, if a schema is defined: + + { + "links": [ + { + "rel": "self" + "href": "{id}" + }, + { + "rel": "up" + "href": "{upId}" + }, + { + "rel": "children" + "href": "?upId={id}" + } + ] + } + + And if a collection of instance resource's JSON representation was + retrieved: + + GET /Resource/ + + [ + { + "id": "thing", + "upId": "parent" + }, + { + "id": "thing2", + "upId": "parent" + } + ] + + This would indicate that for the first item in the collection, its + own (self) URI would resolve to "/Resource/thing" and the first + item's "up" relation SHOULD be resolved to the resource at + "/Resource/parent". The "children" collection would be located at + "/Resource/?upId=thing". + */ + private TextNode rel; + + /* + * This property value is a schema that defines the expected structure + of the JSON representation of the target of the link. + */ + private Schema targetSchema; + + /* + * This attribute defines which method can be used to access the target + resource. In an HTTP environment, this would be "GET" or "POST" + (other HTTP methods such as "PUT" and "DELETE" have semantics that + are clearly implied by accessed resources, and do not need to be + defined here). This defaults to "GET". + */ + private TextNode method; + + /* + * If present, this property indicates a query media type format that + the server supports for querying or posting to the collection of + instances at the target resource. The query can be suffixed to the + target URI to query the collection with property-based constraints on + the resources that SHOULD be returned from the server or used to post + data to the resource (depending on the method). For example, with + the following schema: + + { + "links":[ + { + "enctype":"application/x-www-form-urlencoded", + "method":"GET", + "href":"/Product/", + "properties":{ + "name":{"description":"name of the product"} + } + } + ] + } + This indicates that the client can query the server for instances + that have a specific name: + + /Product/?name=Slinky + + If no enctype or method is specified, only the single URI specified + by the href property is defined. If the method is POST, + "application/json" is the default media type. + */ + private TextNode enctype; + + /* + * This attribute contains a schema which defines the acceptable + structure of the submitted request (for a GET request, this schema + would define the properties for the query string and for a POST + request, this would define the body). + */ + private Schema schema; + + } +} \ No newline at end of file diff --git a/src/main/java/com/fasterxml/jackson/databind/jsonschema/types/IntegerSchema.java b/src/main/java/com/fasterxml/jackson/databind/jsonschema/types/IntegerSchema.java new file mode 100644 index 0000000000..b273af9c76 --- /dev/null +++ b/src/main/java/com/fasterxml/jackson/databind/jsonschema/types/IntegerSchema.java @@ -0,0 +1,16 @@ +package com.fasterxml.jackson.databind.jsonschema.types; + +import com.fasterxml.jackson.databind.node.IntNode; +import com.fasterxml.jackson.databind.node.TextNode; + +public class IntegerSchema extends NumberSchema { + public static final TextNode type = TextNode.valueOf(SchemaType.INTEGER.toString()); + + /* + * This attribute defines what value the number instance must be + divisible by with no remainder (the result of the division must be an + integer.) The value of this attribute SHOULD NOT be 0. + */ + private IntNode divisibleBy; + +} \ No newline at end of file diff --git a/src/main/java/com/fasterxml/jackson/databind/jsonschema/types/NullSchema.java b/src/main/java/com/fasterxml/jackson/databind/jsonschema/types/NullSchema.java new file mode 100644 index 0000000000..52d29cd18a --- /dev/null +++ b/src/main/java/com/fasterxml/jackson/databind/jsonschema/types/NullSchema.java @@ -0,0 +1,10 @@ +package com.fasterxml.jackson.databind.jsonschema.types; + +import com.fasterxml.jackson.databind.node.TextNode; + +/** + * value must be null; + */ +public class NullSchema extends ValueTypeSchema { + public static final TextNode type = TextNode.valueOf(SchemaType.NULL.toString()); +} \ No newline at end of file diff --git a/src/main/java/com/fasterxml/jackson/databind/jsonschema/types/NumberSchema.java b/src/main/java/com/fasterxml/jackson/databind/jsonschema/types/NumberSchema.java new file mode 100644 index 0000000000..a674cbb791 --- /dev/null +++ b/src/main/java/com/fasterxml/jackson/databind/jsonschema/types/NumberSchema.java @@ -0,0 +1,29 @@ +package com.fasterxml.jackson.databind.jsonschema.types; + +import com.fasterxml.jackson.databind.node.BooleanNode; +import com.fasterxml.jackson.databind.node.NumericNode; +import com.fasterxml.jackson.databind.node.TextNode; + +public class NumberSchema extends ValueTypeSchema { + public static final TextNode type = TextNode.valueOf(SchemaType.NUMBER.toString()); + //This attribute defines the minimum value of the instance property + private NumericNode minimum; + + //This attribute defines the maximum value of the instance property + private NumericNode maximum; + + /* + * This attribute indicates if the value of the instance (if the + instance is a number) can not equal the number defined by the + "minimum" attribute. + */ + private BooleanNode exclusiveMinimum = BooleanNode.FALSE; + + /* + * This attribute indicates if the value of the instance (if the + instance is a number) can not equal the number defined by the + "maximum" attribute. + */ + private BooleanNode exclusiveMaximum = BooleanNode.FALSE; + +} \ No newline at end of file diff --git a/src/main/java/com/fasterxml/jackson/databind/jsonschema/types/ObjectSchema.java b/src/main/java/com/fasterxml/jackson/databind/jsonschema/types/ObjectSchema.java new file mode 100644 index 0000000000..88da2d2dcd --- /dev/null +++ b/src/main/java/com/fasterxml/jackson/databind/jsonschema/types/ObjectSchema.java @@ -0,0 +1,112 @@ +package com.fasterxml.jackson.databind.jsonschema.types; + +import java.util.List; +import java.util.Map; + +import com.fasterxml.jackson.databind.node.ObjectNode; +import com.fasterxml.jackson.databind.node.TextNode; + +public class ObjectSchema extends ContainerTypeSchema { + public static final TextNode type = TextNode.valueOf(SchemaType.OBJECT.toString()); + + /* + * This attribute is an object with property definitions that define the + valid values of instance object property values. When the instance + value is an object, the property values of the instance object MUST + conform to the property definitions in this object. In this object, + each property definition's value MUST be a schema, and the property's + name MUST be the name of the instance property that it defines. The + instance property value MUST be valid according to the schema from + the property definition. Properties are considered unordered, the + order of the instance properties MAY be in any order. + */ + private Map properties; + public Schema putProperty(String name, Schema value) { + return properties.put(name, value); + } + + /* + * + This attribute is an object that defines the schema for a set of + property names of an object instance. The name of each property of + this attribute's object is a regular expression pattern in the ECMA + 262/Perl 5 format, while the value is a schema. If the pattern + matches the name of a property on the instance object, the value of + the instance's property MUST be valid against the pattern name's + schema value. + */ + private Map patternProperties; + public Schema putPatternProperty(String regex, Schema value) { + return patternProperties.put(regex, value); + } + + /* + * This attribute defines a schema for all properties that are not + explicitly defined in an object type definition. If specified, the + value MUST be a schema or a boolean. If false is provided, no + additional properties are allowed beyond the properties defined in + the schema. The default value is an empty schema which allows any + value for additional properties. + */ + private AdditionalProperties additionalProperties; + public void rejectAdditionalProperties() { + additionalProperties = NoAdditionalProperties.instance; + } + + public static abstract class AdditionalProperties {} + public static class NoAdditionalProperties extends AdditionalProperties { + public static final NoAdditionalProperties instance = new NoAdditionalProperties(); + protected NoAdditionalProperties() {} + } + public static class SchemaAdditionalProperties extends AdditionalProperties{ + private Schema schema; + public SchemaAdditionalProperties(Schema schema) { + this.schema = schema; + } + } + /* + * This attribute is an object that defines the requirements of a + property on an instance object. If an object instance has a property + with the same name as a property in this attribute's object, then the + instance must be valid against the attribute's property value + */ + private List dependencies; + public boolean addSimpleDependency(String depender, String dependsOn) { + return dependencies.add(new SimpleDependency(depender, dependsOn)); + } + public boolean addSchemaDependency(String depender, Schema parentMustMatch) { + return dependencies.add(new SchemaDependency(depender, parentMustMatch)); + } + + public static abstract class Dependency {} + + /* + * Simple Dependency If the dependency value is a string, then the + instance object MUST have a property with the same name as the + dependency value. If the dependency value is an array of strings, + then the instance object MUST have a property with the same name + as each string in the dependency value's array. + */ + public static class SimpleDependency extends Dependency { + private String depender; + private String dependsOn; + + public SimpleDependency(String depender, String dependsOn) { + this.depender = depender; + this.dependsOn = dependsOn; + } + } + + /* + * Schema Dependency If the dependency value is a schema, then the + instance object MUST be valid against the schema. + */ + public static class SchemaDependency extends Dependency { + private String depender; + private Schema parentMustMatch; + public SchemaDependency(String depender, Schema parentMustMatch) { + this.depender = depender; + this.parentMustMatch = parentMustMatch; + } + } +} \ No newline at end of file diff --git a/src/main/java/com/fasterxml/jackson/databind/jsonschema/types/Schema.java b/src/main/java/com/fasterxml/jackson/databind/jsonschema/types/Schema.java new file mode 100644 index 0000000000..88d4abe2fa --- /dev/null +++ b/src/main/java/com/fasterxml/jackson/databind/jsonschema/types/Schema.java @@ -0,0 +1,215 @@ +package com.fasterxml.jackson.databind.jsonschema.types; + +import java.lang.reflect.Type; + +import com.fasterxml.jackson.databind.JavaType; +import com.fasterxml.jackson.databind.JsonMappingException; +import com.fasterxml.jackson.databind.JsonNode; +import com.fasterxml.jackson.databind.JsonSerializer; +import com.fasterxml.jackson.databind.SerializerProvider; +import com.fasterxml.jackson.databind.jsonschema.JsonSchema; +import com.fasterxml.jackson.databind.jsonschema.SchemaAware; +import com.fasterxml.jackson.databind.node.BooleanNode; +import com.fasterxml.jackson.databind.node.ObjectNode; +import com.fasterxml.jackson.databind.node.TextNode; +import com.fasterxml.jackson.databind.ser.BeanPropertyFilter; +import com.fasterxml.jackson.databind.ser.BeanPropertyWriter; +import com.fasterxml.jackson.databind.ser.std.BeanSerializerBase; + +/** + * Json Schema Draft + *
+ JSON (JavaScript Object Notation) Schema defines the media type + "application/schema+json", a JSON based format for defining the + structure of JSON data. JSON Schema provides a contract for what + JSON data is required for a given application and how to interact + with it. JSON Schema is intended to define validation, + documentation, hyperlink navigation, and interaction control of JSON + data. +
+ +
+ JSON (JavaScript Object Notation) Schema is a JSON media type for + defining the structure of JSON data. JSON Schema provides a contract + for what JSON data is required for a given application and how to + interact with it. JSON Schema is intended to define validation, + documentation, hyperlink navigation, and interaction control of JSON + data. +
+ + An example JSON Schema provided by the Schema draft: +
+	{
+	  "name":"Product",
+	  "properties":{
+	    "id":{
+	      "type":"number",
+	      "description":"Product identifier",
+	      "required":true
+	    },
+	    "name":{
+	      "description":"Name of the product",
+	      "type":"string",
+	      "required":true
+	    },
+	    "price":{
+	      "required":true,
+	      "type": "number",
+	      "minimum":0,
+	      "required":true
+	    },
+	    "tags":{
+	      "type":"array",
+	      "items":{
+	        "type":"string"
+	      }
+	    }
+	  },
+	  "links":[
+	    {
+	      "rel":"full",
+	      "href":"{id}"
+	    },
+	    {
+	      "rel":"comments",
+	      "href":"comments/?id={id}"
+	    }
+	  ]
+	}
+	
+ + * @author jphelan + */ +public abstract class Schema { + public JsonNode asJson() { + + return null; + } + + /** + * Attempt to add the output of the given {@link BeanPropertyWriter} in the given {@link ObjectNode}. + * Otherwise, add the default schema {@link JsonNode} in place of the writer's output + * + * @param writer Bean property serializer to use to create schema value + * @param propertiesNode Node which the given property would exist within + * @param provider Provider that can be used for accessing dynamic aspects of serialization + * processing + * + * {@link BeanPropertyFilter#depositSchemaProperty(BeanPropertyWriter, ObjectNode, SerializerProvider)} + */ + public static void depositSchemaProperty(BeanPropertyWriter writer, ObjectNode propertiesNode, SerializerProvider provider) { + JavaType propType = writer.getSerializationType(); + + // 03-Dec-2010, tatu: SchemaAware REALLY should use JavaType, but alas it doesn't... + Type hint = (propType == null) ? writer.getGenericPropertyType() : propType.getRawClass(); + JsonNode schemaNode; + // Maybe it already has annotated/statically configured serializer? + JsonSerializer ser = writer.getSerializer(); + + try { + if (ser == null) { // nope + Class serType = writer.getRawSerializationType(); + if (serType == null) { + serType = writer.getPropertyType(); + } + ser = provider.findValueSerializer(serType, writer); + } + boolean isOptional = !BeanSerializerBase.isPropertyRequired(writer, provider); + if (ser instanceof SchemaAware) { + schemaNode = ((SchemaAware) ser).getSchema(provider, hint, isOptional) ; + } else { + schemaNode = JsonSchema.getDefaultSchemaNode(); + } + } catch (JsonMappingException e) { + schemaNode = JsonSchema.getDefaultSchemaNode(); + //TODO: log error + } + propertiesNode.put(writer.getName(), schemaNode); + } + + /* + * This attribute indicates if the instance must have a value, and not + be undefined. This is false by default, making the instance + optional. + */ + private BooleanNode required = BooleanNode.FALSE;// default = false; + + /* + * This attribute defines the current URI of this schema (this attribute + is effectively a "self" link). This URI MAY be relative or absolute. + If the URI is relative it is resolved against the current URI of the + parent schema it is contained in. If this schema is not contained in + any parent schema, the current URI of the parent schema is held to be + the URI under which this schema was addressed. If id is missing, the + current URI of a schema is defined to be that of the parent schema. + The current URI of the schema is also used to construct relative + references such as for $ref. + */ + private TextNode id; + + /* + * This attribute defines a URI of a schema that contains the full + representation of this schema. When a validator encounters this + attribute, it SHOULD replace the current schema with the schema + referenced by the value's URI (if known and available) and re- + validate the instance. This URI MAY be relative or absolute, and + relative URIs SHOULD be resolved against the URI of the current + schema. + */ + private TextNode $ref; + + /* + * This attribute defines a URI of a JSON Schema that is the schema of + the current schema. When this attribute is defined, a validator + SHOULD use the schema referenced by the value's URI (if known and + available) when resolving Hyper Schema (Section 6) links + (Section 6.1). + + A validator MAY use this attribute's value to determine which version + of JSON Schema the current schema is written in, and provide the + appropriate validation features and behavior. Therefore, it is + RECOMMENDED that all schema authors include this attribute in their + schemas to prevent conflicts with future JSON Schema specification + changes. + + */ + private TextNode $schema; + + /* + * The value of this property MUST be another schema which will provide + a base schema which the current schema will inherit from. The + inheritance rules are such that any instance that is valid according + to the current schema MUST be valid according to the referenced + schema. This MAY also be an array, in which case, the instance MUST + be valid for all the schemas in the array. A schema that extends + another schema MAY define additional attributes, constrain existing + attributes, or add other constraints. + + Conceptually, the behavior of extends can be seen as validating an + instance against all constraints in the extending schema as well as + the extended schema(s). More optimized implementations that merge + schemas are possible, but are not required. An example of using + "extends": + + { + "description":"An adult", + "properties":{"age":{"minimum": 21}}, + "extends":"person" + } + { + "description":"Extended schema", + "properties":{"deprecated":{"type": "boolean"}}, + "extends":"http://json-schema.org/draft-03/schema" + } + */ + private Schema[] extendsextends; + + /* + * This attribute takes the same values as the "type" attribute, however + if the instance matches the type or if this value is an array and the + instance matches any type or schema in the array, then this instance + is not valid. + */ + private Schema[] disallow; + +} \ No newline at end of file diff --git a/src/main/java/com/fasterxml/jackson/databind/jsonschema/types/SchemaType.java b/src/main/java/com/fasterxml/jackson/databind/jsonschema/types/SchemaType.java new file mode 100644 index 0000000000..6d310499ba --- /dev/null +++ b/src/main/java/com/fasterxml/jackson/databind/jsonschema/types/SchemaType.java @@ -0,0 +1,37 @@ +package com.fasterxml.jackson.databind.jsonschema.types; + +public enum SchemaType { + STRING { + @Override + public String toString() { return "string"; } + }, + NUMBER { + @Override + public String toString() { return "number"; } + }, + INTEGER { + @Override + public String toString() { return "integer"; } + }, + BOOLEAN { + @Override + public String toString() { return "boolean"; } + }, + OBJECT { + @Override + public String toString() { return "object"; } + }, + ARRAY { + @Override + public String toString() { return "array"; } + }, + NULL { + @Override + public String toString() { return "null"; } + }, + ANY { + @Override + public String toString() { return "any"; } + } + +} \ No newline at end of file diff --git a/src/main/java/com/fasterxml/jackson/databind/jsonschema/types/SimpleTypeSchema.java b/src/main/java/com/fasterxml/jackson/databind/jsonschema/types/SimpleTypeSchema.java new file mode 100644 index 0000000000..d2942c5559 --- /dev/null +++ b/src/main/java/com/fasterxml/jackson/databind/jsonschema/types/SimpleTypeSchema.java @@ -0,0 +1,39 @@ +package com.fasterxml.jackson.databind.jsonschema.types; + +import java.util.Set; + +import com.fasterxml.jackson.databind.JsonNode; +import com.fasterxml.jackson.databind.node.TextNode; + +public abstract class SimpleTypeSchema extends Schema { + + + /* + * This provides an enumeration of all possible values that are valid + for the instance property. This MUST be an array, and each item in + the array represents a possible value for the instance value. If + this attribute is defined, the instance value MUST be one of the + values in the array in order for the schema to be valid. Comparison + of enum values uses the same algorithm as defined in "uniqueItems" + (Section 5.15). + */ + private Set enumenum; + + /* + * This attribute defines the default value of the instance when the + instance is undefined. + */ + private JsonNode defaultdefault; + + /* + * This attribute is a string that provides a short description of the + instance property. + */ + private TextNode title; + + /* + * This attribute is a string that provides a full description of the of + purpose the instance property. + */ + private TextNode description; +} \ No newline at end of file diff --git a/src/main/java/com/fasterxml/jackson/databind/jsonschema/types/StringSchema.java b/src/main/java/com/fasterxml/jackson/databind/jsonschema/types/StringSchema.java new file mode 100644 index 0000000000..d25c29790e --- /dev/null +++ b/src/main/java/com/fasterxml/jackson/databind/jsonschema/types/StringSchema.java @@ -0,0 +1,23 @@ +package com.fasterxml.jackson.databind.jsonschema.types; + +import com.fasterxml.jackson.databind.node.IntNode; +import com.fasterxml.jackson.databind.node.TextNode; + +public class StringSchema extends ValueTypeSchema { + public static final TextNode type = TextNode.valueOf(SchemaType.STRING.toString()); + + /* + * this provides a regular + expression that a string instance MUST match in order to be valid. + Regular expressions SHOULD follow the regular expression + specification from ECMA 262/Perl 5 + */ + private TextNode pattern; + + //this defines the minimum length of the string. + private IntNode minLength; + + //this defines the maximum length of the string. + private IntNode maxLength; + +} \ No newline at end of file diff --git a/src/main/java/com/fasterxml/jackson/databind/jsonschema/types/UnionTypeSchema.java b/src/main/java/com/fasterxml/jackson/databind/jsonschema/types/UnionTypeSchema.java new file mode 100644 index 0000000000..46a916437a --- /dev/null +++ b/src/main/java/com/fasterxml/jackson/databind/jsonschema/types/UnionTypeSchema.java @@ -0,0 +1,13 @@ +package com.fasterxml.jackson.databind.jsonschema.types; + +import com.fasterxml.jackson.databind.node.ArrayNode; + +public class UnionTypeSchema extends Schema { + private ValueTypeSchema[] elements; + private ArrayNode value; + public final ValueTypeSchema[] getElements() { return elements; } + public final void setElements(ValueTypeSchema[] elements) { + assert elements.length >= 2 : "Union Type Schemas must contain two or more Simple Type Schemas" ; + this.elements = elements; + } +} \ No newline at end of file diff --git a/src/main/java/com/fasterxml/jackson/databind/jsonschema/types/ValueTypeSchema.java b/src/main/java/com/fasterxml/jackson/databind/jsonschema/types/ValueTypeSchema.java new file mode 100644 index 0000000000..db4bebe7af --- /dev/null +++ b/src/main/java/com/fasterxml/jackson/databind/jsonschema/types/ValueTypeSchema.java @@ -0,0 +1,78 @@ +package com.fasterxml.jackson.databind.jsonschema.types; + +import com.fasterxml.jackson.databind.JsonNode; + +/** +* A primitive type. +*/ +public abstract class ValueTypeSchema extends SimpleTypeSchema { + + private T value; + + /* + * This property defines the type of data, content type, or microformat + to be expected in the instance property values. A format attribute + MAY be one of the values listed below, and if so, SHOULD adhere to + the semantics describing for the format. A format SHOULD only be + used to give meaning to primitive types (string, integer, number, or + boolean). Validators MAY (but are not required to) validate that the + instance values conform to a format. + */ + private ValueTypeSchema.Format format; + + public static enum Format { + DATE_TIME { + @Override + public String toString() { return "date-time"; } + }, + DATE { + @Override + public String toString() { return "date"; } + }, + TIME { + @Override + public String toString() { return "time"; } + }, + UTC_MILLISEC { + @Override + public String toString() { return "utc-millisec"; } + }, + REGEX { + @Override + public String toString() { return "regex"; } + }, + COLOR { + @Override + public String toString() { return "color"; } + }, + STYLE { + @Override + public String toString() { return "style"; } + }, + PHONE { + @Override + public String toString() { return "phone"; } + }, + URI { + @Override + public String toString() { return "uri"; } + }, + EMAIL { + @Override + public String toString() { return "email"; } + }, + IP_ADDRESS { + @Override + public String toString() { return "ip-address"; } + }, + IPV6 { + @Override + public String toString() { return "ipv6"; } + }, + HOST_NAME { + @Override + public String toString() { return "host-name"; } + } + + } +} \ No newline at end of file diff --git a/src/main/java/com/fasterxml/jackson/databind/ser/impl/SimpleBeanPropertyFilter.java b/src/main/java/com/fasterxml/jackson/databind/ser/impl/SimpleBeanPropertyFilter.java index d6fbb8703d..2267207b7b 100644 --- a/src/main/java/com/fasterxml/jackson/databind/ser/impl/SimpleBeanPropertyFilter.java +++ b/src/main/java/com/fasterxml/jackson/databind/ser/impl/SimpleBeanPropertyFilter.java @@ -8,10 +8,10 @@ import com.fasterxml.jackson.databind.*; import com.fasterxml.jackson.databind.jsonschema.JsonSchema; import com.fasterxml.jackson.databind.jsonschema.SchemaAware; +import com.fasterxml.jackson.databind.jsonschema.types.Schema; import com.fasterxml.jackson.databind.node.ObjectNode; import com.fasterxml.jackson.databind.ser.BeanPropertyFilter; import com.fasterxml.jackson.databind.ser.BeanPropertyWriter; -import com.fasterxml.jackson.databind.ser.std.BeanSerializerBase; /** * Simple {@link BeanPropertyFilter} implementation that only uses property name @@ -84,7 +84,7 @@ public void serializeAsField(Object bean, JsonGenerator jgen, public void depositSchemaProperty(BeanPropertyWriter writer, ObjectNode propertiesNode, SerializerProvider provider) { if (_propertiesToInclude.contains(writer.getName())) { - BeanSerializerBase.depositSchemaProperty(writer, propertiesNode, provider); + Schema.depositSchemaProperty(writer, propertiesNode, provider); } } } @@ -116,7 +116,7 @@ public void serializeAsField(Object bean, JsonGenerator jgen, public void depositSchemaProperty(BeanPropertyWriter writer, ObjectNode propertiesNode, SerializerProvider provider) { if (!_propertiesToExclude.contains(writer.getName())) { - BeanSerializerBase.depositSchemaProperty(writer, propertiesNode, provider); + Schema.depositSchemaProperty(writer, propertiesNode, provider); } } } diff --git a/src/main/java/com/fasterxml/jackson/databind/ser/std/BeanSerializerBase.java b/src/main/java/com/fasterxml/jackson/databind/ser/std/BeanSerializerBase.java index c74575fb71..1a7b5bcf69 100644 --- a/src/main/java/com/fasterxml/jackson/databind/ser/std/BeanSerializerBase.java +++ b/src/main/java/com/fasterxml/jackson/databind/ser/std/BeanSerializerBase.java @@ -14,9 +14,9 @@ import com.fasterxml.jackson.databind.introspect.Annotated; import com.fasterxml.jackson.databind.introspect.AnnotatedMember; import com.fasterxml.jackson.databind.introspect.ObjectIdInfo; -import com.fasterxml.jackson.databind.jsonschema.JsonSchema; import com.fasterxml.jackson.databind.jsonschema.JsonSerializableSchema; import com.fasterxml.jackson.databind.jsonschema.SchemaAware; +import com.fasterxml.jackson.databind.jsonschema.types.Schema; import com.fasterxml.jackson.databind.jsontype.TypeSerializer; import com.fasterxml.jackson.databind.node.ObjectNode; import com.fasterxml.jackson.databind.ser.*; @@ -658,7 +658,7 @@ public JsonNode getSchema(SerializerProvider provider, Type typeHint) } JavaType propType = prop.getSerializationType(); - depositSchemaProperty(prop, propertiesNode, provider); + Schema.depositSchemaProperty(prop, propertiesNode, provider); } o.put("properties", propertiesNode); @@ -679,45 +679,4 @@ public static boolean isPropertyRequired(final BeanPropertyWriter prop, final Se return (value == null) ? false : value.booleanValue(); } - /** - * Attempt to add the output of the given {@link BeanPropertyWriter} in the given {@link ObjectNode}. - * Otherwise, add the default schema {@link JsonNode} in place of the writer's output - * - * @param writer Bean property serializer to use to create schema value - * @param propertiesNode Node which the given property would exist within - * @param provider Provider that can be used for accessing dynamic aspects of serialization - * processing - * - * {@link BeanPropertyFilter#depositSchemaProperty(BeanPropertyWriter, ObjectNode, SerializerProvider)} - */ - public static void depositSchemaProperty(BeanPropertyWriter writer, ObjectNode propertiesNode, SerializerProvider provider) { - JavaType propType = writer.getSerializationType(); - - // 03-Dec-2010, tatu: SchemaAware REALLY should use JavaType, but alas it doesn't... - Type hint = (propType == null) ? writer.getGenericPropertyType() : propType.getRawClass(); - JsonNode schemaNode; - // Maybe it already has annotated/statically configured serializer? - JsonSerializer ser = writer.getSerializer(); - - try { - if (ser == null) { // nope - Class serType = writer.getRawSerializationType(); - if (serType == null) { - serType = writer.getPropertyType(); - } - ser = provider.findValueSerializer(serType, writer); - } - boolean isOptional = !BeanSerializerBase.isPropertyRequired(writer, provider); - if (ser instanceof SchemaAware) { - schemaNode = ((SchemaAware) ser).getSchema(provider, hint, isOptional) ; - } else { - schemaNode = JsonSchema.getDefaultSchemaNode(); - } - } catch (JsonMappingException e) { - schemaNode = JsonSchema.getDefaultSchemaNode(); - //TODO: log error - } - propertiesNode.put(writer.getName(), schemaNode); - } - } From 8cbae7ba6f7b753357c981f10e75935faed3a091 Mon Sep 17 00:00:00 2001 From: jackphel Date: Mon, 30 Jul 2012 16:50:34 -0400 Subject: [PATCH 02/19] serializers return schema pojos (untested) schemas are proper objects, except for hyperschema --- .../jackson/databind/ObjectMapper.java | 8 +- .../databind/ext/CoreXMLSerializers.java | 6 +- .../jackson/databind/ext/DOMSerializer.java | 9 +- .../databind/jsonschema/SchemaAware.java | 23 +- .../databind/jsonschema/SchemaFactory.java | 7 - .../factories/AnySchemaFactory.java | 24 ++ .../factories/ArraySchemaFactory.java | 58 ++++ .../factories/BooleanSchemaFactory.java | 23 ++ .../factories/IntegerSchemaFactory.java | 23 ++ .../factories/NullSchemaFactory.java | 23 ++ .../factories/NumberSchemaFactory.java | 25 ++ .../factories/ObjectSchemaFactory.java | 98 +++++++ .../jsonschema/factories/SchemaFactory.java | 62 +++++ .../factories/SchemaFactoryDelegate.java | 8 + .../factories/StringSchemaFactory.java | 23 ++ .../factories/ValueTypeSchemaFactory.java | 33 +++ .../databind/jsonschema/types/AnySchema.java | 33 ++- .../jsonschema/types/ArraySchema.java | 132 ++++++++-- .../jsonschema/types/BooleanSchema.java | 15 +- .../jsonschema/types/ContainerTypeSchema.java | 21 ++ .../jsonschema/types/HyperSchema.java | 59 +++-- .../jsonschema/types/IntegerSchema.java | 17 +- .../jsonschema/types/JsonValueFormat.java | 119 +++++++++ .../databind/jsonschema/types/NullSchema.java | 14 +- .../jsonschema/types/NumberSchema.java | 93 ++++++- .../jsonschema/types/ObjectSchema.java | 112 +++++++- .../databind/jsonschema/types/Schema.java | 249 ++++++++++++------ .../jsonschema/types/SimpleTypeSchema.java | 84 ++++-- .../jsonschema/types/StringSchema.java | 73 ++++- .../jsonschema/types/UnionTypeSchema.java | 25 +- .../jsonschema/types/ValueTypeSchema.java | 117 ++++---- .../visitors/JsonAnyFormatVisitor.java | 5 + .../visitors/JsonArrayFormatVisitor.java | 15 ++ .../visitors/JsonBooleanFormatVisitor.java | 5 + .../visitors/JsonFormatVisitor.java | 20 ++ .../visitors/JsonIntegerFormatVisitor.java | 5 + .../visitors/JsonNullFormatVisitor.java | 5 + .../visitors/JsonNumberFormatVisitor.java | 7 + .../visitors/JsonObjectFormatVisitor.java | 23 ++ .../visitors/JsonStringFormatVisitor.java | 5 + .../visitors/JsonValueFormatVisitor.java | 12 + .../databind/ser/BeanPropertyFilter.java | 3 +- .../ser/DefaultSerializerProvider.java | 21 +- .../databind/ser/impl/FailingSerializer.java | 8 +- .../ser/impl/IndexedStringListSerializer.java | 11 +- .../ser/impl/SimpleBeanPropertyFilter.java | 11 +- .../ser/impl/StringArraySerializer.java | 8 +- .../ser/impl/StringCollectionSerializer.java | 10 +- .../databind/ser/impl/UnknownSerializer.java | 5 +- .../ser/std/AsArraySerializerBase.java | 26 +- .../databind/ser/std/BeanSerializerBase.java | 60 +++-- .../databind/ser/std/BooleanSerializer.java | 5 +- .../ser/std/DateTimeSerializerBase.java | 13 +- .../databind/ser/std/EnumMapSerializer.java | 30 ++- .../databind/ser/std/EnumSerializer.java | 36 +-- .../databind/ser/std/JsonValueSerializer.java | 12 +- .../databind/ser/std/MapSerializer.java | 8 +- .../databind/ser/std/NullSerializer.java | 6 +- .../databind/ser/std/NumberSerializers.java | 25 +- .../ser/std/ObjectArraySerializer.java | 24 +- .../databind/ser/std/RawSerializer.java | 8 +- .../ser/std/SerializableSerializer.java | 66 ++--- .../databind/ser/std/SqlDateSerializer.java | 7 +- .../databind/ser/std/SqlTimeSerializer.java | 6 +- .../ser/std/StaticListSerializerBase.java | 11 +- .../databind/ser/std/StdArraySerializers.java | 54 ++-- .../databind/ser/std/StdJdkSerializers.java | 25 +- .../databind/ser/std/StdKeySerializer.java | 8 +- .../databind/ser/std/StdScalarSerializer.java | 6 +- .../databind/ser/std/StdSerializer.java | 47 +--- .../databind/ser/std/StringSerializer.java | 6 +- .../databind/ser/std/ToStringSerializer.java | 6 +- .../ser/std/TokenBufferSerializer.java | 5 +- .../jsonschema/TestGenerateJsonSchema.java | 63 ++--- .../jsonschema/TestReadJsonSchema.java | 3 +- .../databind/module/TestSimpleModule.java | 9 +- 76 files changed, 1750 insertions(+), 620 deletions(-) delete mode 100644 src/main/java/com/fasterxml/jackson/databind/jsonschema/SchemaFactory.java create mode 100644 src/main/java/com/fasterxml/jackson/databind/jsonschema/factories/AnySchemaFactory.java create mode 100644 src/main/java/com/fasterxml/jackson/databind/jsonschema/factories/ArraySchemaFactory.java create mode 100644 src/main/java/com/fasterxml/jackson/databind/jsonschema/factories/BooleanSchemaFactory.java create mode 100644 src/main/java/com/fasterxml/jackson/databind/jsonschema/factories/IntegerSchemaFactory.java create mode 100644 src/main/java/com/fasterxml/jackson/databind/jsonschema/factories/NullSchemaFactory.java create mode 100644 src/main/java/com/fasterxml/jackson/databind/jsonschema/factories/NumberSchemaFactory.java create mode 100644 src/main/java/com/fasterxml/jackson/databind/jsonschema/factories/ObjectSchemaFactory.java create mode 100644 src/main/java/com/fasterxml/jackson/databind/jsonschema/factories/SchemaFactory.java create mode 100644 src/main/java/com/fasterxml/jackson/databind/jsonschema/factories/SchemaFactoryDelegate.java create mode 100644 src/main/java/com/fasterxml/jackson/databind/jsonschema/factories/StringSchemaFactory.java create mode 100644 src/main/java/com/fasterxml/jackson/databind/jsonschema/factories/ValueTypeSchemaFactory.java create mode 100644 src/main/java/com/fasterxml/jackson/databind/jsonschema/types/JsonValueFormat.java create mode 100644 src/main/java/com/fasterxml/jackson/databind/jsonschema/visitors/JsonAnyFormatVisitor.java create mode 100644 src/main/java/com/fasterxml/jackson/databind/jsonschema/visitors/JsonArrayFormatVisitor.java create mode 100644 src/main/java/com/fasterxml/jackson/databind/jsonschema/visitors/JsonBooleanFormatVisitor.java create mode 100644 src/main/java/com/fasterxml/jackson/databind/jsonschema/visitors/JsonFormatVisitor.java create mode 100644 src/main/java/com/fasterxml/jackson/databind/jsonschema/visitors/JsonIntegerFormatVisitor.java create mode 100644 src/main/java/com/fasterxml/jackson/databind/jsonschema/visitors/JsonNullFormatVisitor.java create mode 100644 src/main/java/com/fasterxml/jackson/databind/jsonschema/visitors/JsonNumberFormatVisitor.java create mode 100644 src/main/java/com/fasterxml/jackson/databind/jsonschema/visitors/JsonObjectFormatVisitor.java create mode 100644 src/main/java/com/fasterxml/jackson/databind/jsonschema/visitors/JsonStringFormatVisitor.java create mode 100644 src/main/java/com/fasterxml/jackson/databind/jsonschema/visitors/JsonValueFormatVisitor.java diff --git a/src/main/java/com/fasterxml/jackson/databind/ObjectMapper.java b/src/main/java/com/fasterxml/jackson/databind/ObjectMapper.java index 08dadcbcd7..cc1525bf41 100644 --- a/src/main/java/com/fasterxml/jackson/databind/ObjectMapper.java +++ b/src/main/java/com/fasterxml/jackson/databind/ObjectMapper.java @@ -27,6 +27,8 @@ import com.fasterxml.jackson.databind.introspect.JacksonAnnotationIntrospector; import com.fasterxml.jackson.databind.introspect.VisibilityChecker; import com.fasterxml.jackson.databind.jsonschema.JsonSchema; +import com.fasterxml.jackson.databind.jsonschema.factories.SchemaFactory; +import com.fasterxml.jackson.databind.jsonschema.types.Schema; import com.fasterxml.jackson.databind.jsontype.*; import com.fasterxml.jackson.databind.jsontype.impl.StdSubtypeResolver; import com.fasterxml.jackson.databind.jsontype.impl.StdTypeResolverBuilder; @@ -2397,8 +2399,10 @@ protected Object _convert(Object fromValue, JavaType toValueType) * @param t The class to generate schema for * @return Constructed JSON schema. */ - public JsonSchema generateJsonSchema(Class t) throws JsonMappingException { - return _serializerProvider(getSerializationConfig()).generateJsonSchema(t); + public Schema generateJsonSchema(Class t) throws JsonMappingException { + SchemaFactory visitor = new SchemaFactory(this); + _serializerProvider(getSerializationConfig()).acceptJsonFormatVisitor(t, visitor); + return visitor.finalSchema(); } /* diff --git a/src/main/java/com/fasterxml/jackson/databind/ext/CoreXMLSerializers.java b/src/main/java/com/fasterxml/jackson/databind/ext/CoreXMLSerializers.java index fd967eccc8..3f3dbc65e7 100644 --- a/src/main/java/com/fasterxml/jackson/databind/ext/CoreXMLSerializers.java +++ b/src/main/java/com/fasterxml/jackson/databind/ext/CoreXMLSerializers.java @@ -16,6 +16,7 @@ import com.fasterxml.jackson.databind.JsonNode; import com.fasterxml.jackson.databind.JsonSerializer; import com.fasterxml.jackson.databind.SerializerProvider; +import com.fasterxml.jackson.databind.jsonschema.visitors.JsonFormatVisitor; import com.fasterxml.jackson.databind.ser.std.CalendarSerializer; import com.fasterxml.jackson.databind.ser.std.StdSerializer; import com.fasterxml.jackson.databind.ser.std.ToStringSerializer; @@ -62,9 +63,8 @@ public void serialize(XMLGregorianCalendar value, JsonGenerator jgen, Serializer CalendarSerializer.instance.serialize(value.toGregorianCalendar(), jgen, provider); } - @Override - public JsonNode getSchema(SerializerProvider provider, Type typeHint) throws JsonMappingException { - return CalendarSerializer.instance.getSchema(provider, typeHint); + public void acceptJsonFormatVisitor(JsonFormatVisitor visitor, Type typeHint) { + CalendarSerializer.instance.acceptJsonFormatVisitor(visitor, null); } } } diff --git a/src/main/java/com/fasterxml/jackson/databind/ext/DOMSerializer.java b/src/main/java/com/fasterxml/jackson/databind/ext/DOMSerializer.java index 2c16f6d67e..215b288f09 100644 --- a/src/main/java/com/fasterxml/jackson/databind/ext/DOMSerializer.java +++ b/src/main/java/com/fasterxml/jackson/databind/ext/DOMSerializer.java @@ -1,6 +1,8 @@ package com.fasterxml.jackson.databind.ext; import java.io.IOException; +import java.lang.reflect.Type; + import org.w3c.dom.Node; import org.w3c.dom.bootstrap.DOMImplementationRegistry; import org.w3c.dom.ls.DOMImplementationLS; @@ -8,8 +10,8 @@ import com.fasterxml.jackson.core.*; -import com.fasterxml.jackson.databind.JsonNode; import com.fasterxml.jackson.databind.SerializerProvider; +import com.fasterxml.jackson.databind.jsonschema.visitors.JsonFormatVisitor; import com.fasterxml.jackson.databind.ser.std.StdSerializer; public class DOMSerializer @@ -39,9 +41,8 @@ public void serialize(Node value, JsonGenerator jgen, SerializerProvider provide } @Override - public JsonNode getSchema(SerializerProvider provider, java.lang.reflect.Type typeHint) + public void acceptJsonFormatVisitor(JsonFormatVisitor visitor, Type typeHint) { - // Well... it is serialized as String - return createSchemaNode("string", true); + visitor.anyFormat(); } } diff --git a/src/main/java/com/fasterxml/jackson/databind/jsonschema/SchemaAware.java b/src/main/java/com/fasterxml/jackson/databind/jsonschema/SchemaAware.java index f3505cd37d..d3fdc461fa 100644 --- a/src/main/java/com/fasterxml/jackson/databind/jsonschema/SchemaAware.java +++ b/src/main/java/com/fasterxml/jackson/databind/jsonschema/SchemaAware.java @@ -1,11 +1,9 @@ package com.fasterxml.jackson.databind.jsonschema; -import com.fasterxml.jackson.databind.JsonNode; -import com.fasterxml.jackson.databind.JsonMappingException; -import com.fasterxml.jackson.databind.SerializerProvider; - import java.lang.reflect.Type; +import com.fasterxml.jackson.databind.jsonschema.visitors.JsonFormatVisitor; + /** * Marker interface for schema-aware serializers. */ @@ -13,22 +11,9 @@ public interface SchemaAware { /** * Get the representation of the schema to which this serializer will conform. + * @param typeHint TODO * - * @param provider The serializer provider. - * @param typeHint A hint about the type. - * @return Json-schema for this serializer. - */ - public JsonNode getSchema(SerializerProvider provider, Type typeHint) - throws JsonMappingException; - - /** - * Get the representation of the schema to which this serializer will conform. - * - * @param provider The serializer provider. - * @param isOptional Is the type optional - * @param typeHint A hint about the type. * @return Json-schema for this serializer. */ - public JsonNode getSchema(SerializerProvider provider, Type typeHint, boolean isOptional) - throws JsonMappingException; + public void acceptJsonFormatVisitor(JsonFormatVisitor visitor, Type typeHint); } diff --git a/src/main/java/com/fasterxml/jackson/databind/jsonschema/SchemaFactory.java b/src/main/java/com/fasterxml/jackson/databind/jsonschema/SchemaFactory.java deleted file mode 100644 index 25a86af2fa..0000000000 --- a/src/main/java/com/fasterxml/jackson/databind/jsonschema/SchemaFactory.java +++ /dev/null @@ -1,7 +0,0 @@ -package com.fasterxml.jackson.databind.jsonschema; - -public class SchemaFactory { - - - -} diff --git a/src/main/java/com/fasterxml/jackson/databind/jsonschema/factories/AnySchemaFactory.java b/src/main/java/com/fasterxml/jackson/databind/jsonschema/factories/AnySchemaFactory.java new file mode 100644 index 0000000000..30f83df180 --- /dev/null +++ b/src/main/java/com/fasterxml/jackson/databind/jsonschema/factories/AnySchemaFactory.java @@ -0,0 +1,24 @@ +package com.fasterxml.jackson.databind.jsonschema.factories; + +import com.fasterxml.jackson.databind.jsonschema.types.AnySchema; +import com.fasterxml.jackson.databind.jsonschema.types.Schema; +import com.fasterxml.jackson.databind.jsonschema.visitors.JsonAnyFormatVisitor; + +public class AnySchemaFactory extends SchemaFactory implements + JsonAnyFormatVisitor, SchemaFactoryDelegate { + + protected SchemaFactory parent; + protected AnySchema anySchema; + + public AnySchemaFactory(SchemaFactory parent) { + super(parent.mapper); + this.parent = parent; + anySchema = new AnySchema(); + } + + public Schema getSchema() { + return anySchema; + } + + +} diff --git a/src/main/java/com/fasterxml/jackson/databind/jsonschema/factories/ArraySchemaFactory.java b/src/main/java/com/fasterxml/jackson/databind/jsonschema/factories/ArraySchemaFactory.java new file mode 100644 index 0000000000..d45ce34882 --- /dev/null +++ b/src/main/java/com/fasterxml/jackson/databind/jsonschema/factories/ArraySchemaFactory.java @@ -0,0 +1,58 @@ +package com.fasterxml.jackson.databind.jsonschema.factories; + +import com.fasterxml.jackson.databind.BeanProperty; +import com.fasterxml.jackson.databind.JavaType; +import com.fasterxml.jackson.databind.JsonMappingException; +import com.fasterxml.jackson.databind.JsonSerializer; +import com.fasterxml.jackson.databind.jsonschema.SchemaAware; +import com.fasterxml.jackson.databind.jsonschema.types.ArraySchema; +import com.fasterxml.jackson.databind.jsonschema.types.Schema; +import com.fasterxml.jackson.databind.jsonschema.types.SchemaType; +import com.fasterxml.jackson.databind.jsonschema.visitors.JsonArrayFormatVisitor; + +public class ArraySchemaFactory extends SchemaFactory implements JsonArrayFormatVisitor, SchemaFactoryDelegate { + + protected SchemaFactory parent; + protected ArraySchema arraySchema; + protected BeanProperty _property; + + public ArraySchemaFactory(SchemaFactory parent, BeanProperty property) { + super(parent.mapper); + this.parent = parent; + arraySchema = new ArraySchema(); + } + + public ArraySchemaFactory(SchemaFactory schemaFactory) { + this(schemaFactory, null); + } + + public void itemsFormat(JavaType contentType) { + // An array of object matches any values, thus we leave the schema empty. + if (contentType.getRawClass() != Object.class) { + + JsonSerializer ser; + try { + ser = getProvider().findValueSerializer(contentType, _property); + if (ser instanceof SchemaAware) { + SchemaFactory visitor = new SchemaFactory(mapper); + ((SchemaAware) ser).acceptJsonFormatVisitor(visitor, null); + arraySchema.setItemsSchema(visitor.finalSchema()); + } + } catch (JsonMappingException e) { + //TODO: log error + } + } + } + + public void itemsFormat(SchemaAware toVisit) {} + + public void itemsFormat(SchemaType format) { + arraySchema.setItemsSchema(Schema.minimalForFormat(format)); + } + + public Schema getSchema() { + return arraySchema; + } + + +} diff --git a/src/main/java/com/fasterxml/jackson/databind/jsonschema/factories/BooleanSchemaFactory.java b/src/main/java/com/fasterxml/jackson/databind/jsonschema/factories/BooleanSchemaFactory.java new file mode 100644 index 0000000000..9e5cd6e757 --- /dev/null +++ b/src/main/java/com/fasterxml/jackson/databind/jsonschema/factories/BooleanSchemaFactory.java @@ -0,0 +1,23 @@ +package com.fasterxml.jackson.databind.jsonschema.factories; + +import com.fasterxml.jackson.databind.jsonschema.types.BooleanSchema; +import com.fasterxml.jackson.databind.jsonschema.types.ValueTypeSchema; +import com.fasterxml.jackson.databind.jsonschema.visitors.JsonBooleanFormatVisitor; + +public class BooleanSchemaFactory extends ValueTypeSchemaFactory implements + SchemaFactoryDelegate, JsonBooleanFormatVisitor { + + protected SchemaFactory parent; + protected BooleanSchema booleanSchema; + + public BooleanSchemaFactory(SchemaFactory parent) { + super(parent.mapper); + this.parent = parent; + booleanSchema = new BooleanSchema(); + } + + public ValueTypeSchema getValueSchema() { + return booleanSchema; + } + +} diff --git a/src/main/java/com/fasterxml/jackson/databind/jsonschema/factories/IntegerSchemaFactory.java b/src/main/java/com/fasterxml/jackson/databind/jsonschema/factories/IntegerSchemaFactory.java new file mode 100644 index 0000000000..cbacc6d039 --- /dev/null +++ b/src/main/java/com/fasterxml/jackson/databind/jsonschema/factories/IntegerSchemaFactory.java @@ -0,0 +1,23 @@ +package com.fasterxml.jackson.databind.jsonschema.factories; + +import com.fasterxml.jackson.databind.jsonschema.types.IntegerSchema; +import com.fasterxml.jackson.databind.jsonschema.types.ValueTypeSchema; +import com.fasterxml.jackson.databind.jsonschema.visitors.JsonIntegerFormatVisitor; + +public class IntegerSchemaFactory extends ValueTypeSchemaFactory implements + JsonIntegerFormatVisitor, SchemaFactoryDelegate { + + protected SchemaFactory parent; + protected IntegerSchema integerSchema; + + public IntegerSchemaFactory(SchemaFactory parent) { + super(parent.mapper); + this.parent = parent; + integerSchema = new IntegerSchema(); + } + + public ValueTypeSchema getValueSchema() { + return integerSchema; + } + +} diff --git a/src/main/java/com/fasterxml/jackson/databind/jsonschema/factories/NullSchemaFactory.java b/src/main/java/com/fasterxml/jackson/databind/jsonschema/factories/NullSchemaFactory.java new file mode 100644 index 0000000000..cf5f1bfe32 --- /dev/null +++ b/src/main/java/com/fasterxml/jackson/databind/jsonschema/factories/NullSchemaFactory.java @@ -0,0 +1,23 @@ +package com.fasterxml.jackson.databind.jsonschema.factories; + +import com.fasterxml.jackson.databind.jsonschema.types.NullSchema; +import com.fasterxml.jackson.databind.jsonschema.types.Schema; +import com.fasterxml.jackson.databind.jsonschema.visitors.JsonNullFormatVisitor; + +public class NullSchemaFactory extends SchemaFactory implements + JsonNullFormatVisitor, SchemaFactoryDelegate { + + protected SchemaFactory parent; + protected NullSchema nullSchema; + + public NullSchemaFactory(SchemaFactory parent) { + super(parent.mapper); + this.parent = parent; + nullSchema = new NullSchema(); + } + + public Schema getSchema() { + return nullSchema; + } + +} diff --git a/src/main/java/com/fasterxml/jackson/databind/jsonschema/factories/NumberSchemaFactory.java b/src/main/java/com/fasterxml/jackson/databind/jsonschema/factories/NumberSchemaFactory.java new file mode 100644 index 0000000000..c3e9192f1b --- /dev/null +++ b/src/main/java/com/fasterxml/jackson/databind/jsonschema/factories/NumberSchemaFactory.java @@ -0,0 +1,25 @@ +package com.fasterxml.jackson.databind.jsonschema.factories; + +import com.fasterxml.jackson.databind.jsonschema.types.NumberSchema; +import com.fasterxml.jackson.databind.jsonschema.types.ValueTypeSchema; +import com.fasterxml.jackson.databind.jsonschema.visitors.JsonNumberFormatVisitor; + +public class NumberSchemaFactory extends ValueTypeSchemaFactory implements + JsonNumberFormatVisitor, SchemaFactoryDelegate { + + protected SchemaFactory parent; + protected NumberSchema numberSchema; + + public NumberSchemaFactory(SchemaFactory parent) { + super(parent.mapper); + this.parent = parent; + numberSchema = new NumberSchema(); + } + + @Override + protected ValueTypeSchema getValueSchema() { + return numberSchema; + } + + +} diff --git a/src/main/java/com/fasterxml/jackson/databind/jsonschema/factories/ObjectSchemaFactory.java b/src/main/java/com/fasterxml/jackson/databind/jsonschema/factories/ObjectSchemaFactory.java new file mode 100644 index 0000000000..6e80ec0061 --- /dev/null +++ b/src/main/java/com/fasterxml/jackson/databind/jsonschema/factories/ObjectSchemaFactory.java @@ -0,0 +1,98 @@ +package com.fasterxml.jackson.databind.jsonschema.factories; + +import java.lang.reflect.Type; + +import com.fasterxml.jackson.databind.JavaType; +import com.fasterxml.jackson.databind.JsonMappingException; +import com.fasterxml.jackson.databind.JsonSerializer; +import com.fasterxml.jackson.databind.SerializerProvider; +import com.fasterxml.jackson.databind.jsonschema.SchemaAware; +import com.fasterxml.jackson.databind.jsonschema.types.ObjectSchema; +import com.fasterxml.jackson.databind.jsonschema.types.Schema; +import com.fasterxml.jackson.databind.jsonschema.types.SchemaType; +import com.fasterxml.jackson.databind.jsonschema.visitors.JsonObjectFormatVisitor; +import com.fasterxml.jackson.databind.ser.BeanPropertyWriter; + +public class ObjectSchemaFactory extends SchemaFactory implements JsonObjectFormatVisitor, SchemaFactoryDelegate { + + protected SchemaFactory parent; + protected ObjectSchema objectSchema; + + public ObjectSchemaFactory(SchemaFactory parent) { + super(parent.mapper); + this.parent = parent; + objectSchema = new ObjectSchema(); + } + + public Schema getSchema() { + // TODO Auto-generated method stub + return objectSchema; + } + + private JsonSerializer getSer(BeanPropertyWriter writer, Class serType) { + JsonSerializer ser = writer.getSerializer(); + if (ser == null) { // nope + if (serType == null) { + serType = writer.getPropertyType(); + } + try { + return getProvider().findValueSerializer(serType, writer); + } catch (JsonMappingException e) { + // TODO: log error + } + } + return null; + } + + private Type writerType(BeanPropertyWriter writer) { + + //TODO:Will these ever return different types? + + //JavaType propType = writer.getSerializationType(); + //Type hint = (propType == null) ? writer.getGenericPropertyType() : propType.getRawClass(); + return writer.getRawSerializationType(); + } + + protected Schema propertySchema(BeanPropertyWriter writer) { + SchemaFactory visitor = new SchemaFactory(mapper); + Type serType = writerType(writer); + JsonSerializer ser = getSer(writer, serType.getClass()); + if (ser != null && ser instanceof SchemaAware) { + ((SchemaAware)ser).acceptJsonFormatVisitor(visitor, serType); + } else { + visitor.anyFormat(); + } + return visitor.finalSchema(); + } + + protected Schema propertySchema(SchemaAware handler, Type propertyTypeHint) { + SchemaFactory visitor = new SchemaFactory(mapper); + handler.acceptJsonFormatVisitor(visitor, propertyTypeHint); + return visitor.finalSchema(); + } + + public void property(BeanPropertyWriter writer) { + objectSchema.putProperty(writer.getName(), propertySchema(writer)); + } + + public void optionalProperty(BeanPropertyWriter writer) { + objectSchema.putOptionalProperty(writer.getName(), propertySchema(writer)); + } + + public void property(String name, SchemaAware handler, Type propertyTypeHint) { + objectSchema.putProperty(name, propertySchema(handler, propertyTypeHint)); + } + + public void optionalProperty(String name, SchemaAware handler, Type propertyTypeHint) { + objectSchema.putOptionalProperty(name, propertySchema(handler, propertyTypeHint)); + } + + public void property(String name) { + objectSchema.putProperty(name, Schema.minimalForFormat(SchemaType.ANY)); + } + + public void optionalProperty(String name) { + objectSchema.putOptionalProperty(name, Schema.minimalForFormat(SchemaType.ANY)); + } + +} diff --git a/src/main/java/com/fasterxml/jackson/databind/jsonschema/factories/SchemaFactory.java b/src/main/java/com/fasterxml/jackson/databind/jsonschema/factories/SchemaFactory.java new file mode 100644 index 0000000000..5007bff0b4 --- /dev/null +++ b/src/main/java/com/fasterxml/jackson/databind/jsonschema/factories/SchemaFactory.java @@ -0,0 +1,62 @@ +package com.fasterxml.jackson.databind.jsonschema.factories; + +import java.lang.reflect.Type; + +import com.fasterxml.jackson.databind.ObjectMapper; +import com.fasterxml.jackson.databind.SerializerProvider; +import com.fasterxml.jackson.databind.jsonschema.types.Schema; +import com.fasterxml.jackson.databind.jsonschema.visitors.JsonAnyFormatVisitor; +import com.fasterxml.jackson.databind.jsonschema.visitors.JsonArrayFormatVisitor; +import com.fasterxml.jackson.databind.jsonschema.visitors.JsonBooleanFormatVisitor; +import com.fasterxml.jackson.databind.jsonschema.visitors.JsonFormatVisitor; +import com.fasterxml.jackson.databind.jsonschema.visitors.JsonIntegerFormatVisitor; +import com.fasterxml.jackson.databind.jsonschema.visitors.JsonNullFormatVisitor; +import com.fasterxml.jackson.databind.jsonschema.visitors.JsonNumberFormatVisitor; +import com.fasterxml.jackson.databind.jsonschema.visitors.JsonObjectFormatVisitor; +import com.fasterxml.jackson.databind.jsonschema.visitors.JsonStringFormatVisitor; + +public class SchemaFactory implements JsonFormatVisitor { + + protected ObjectMapper mapper; + private SchemaFactoryDelegate delegate; + + public SerializerProvider getProvider() { + return mapper.getSerializerProvider(); + } + + public SchemaFactory(ObjectMapper mapper) { + this.mapper = mapper; + } + + public JsonObjectFormatVisitor objectFormat(Type type) { + //BasicClassIntrospector.instance. + delegate = new ObjectSchemaFactory(this); + return (JsonObjectFormatVisitor) delegate; + } + + public JsonArrayFormatVisitor arrayFormat(Type elementType) { + delegate = new ArraySchemaFactory(this); + return (JsonArrayFormatVisitor) delegate; + } + + public JsonStringFormatVisitor stringFormat() { + delegate = new StringSchemaFactory(this); + return (JsonStringFormatVisitor) delegate; + } + public JsonNumberFormatVisitor numberFormat() { return new NumberSchemaFactory(this); } + public JsonIntegerFormatVisitor integerFormat() { return new IntegerSchemaFactory(this); } + public JsonBooleanFormatVisitor booleanFormat() { return new BooleanSchemaFactory(this); } + public JsonNullFormatVisitor nullFormat() { return new NullSchemaFactory(this); } + public JsonAnyFormatVisitor anyFormat() { return new AnySchemaFactory(this); } + + public Schema finalSchema() { + assert delegate != null : "SchemaFactory must envoke a delegate method before it can return a Schema."; + if (delegate == null) { + return null; + } else { + return delegate.getSchema(); + } + + } + +} diff --git a/src/main/java/com/fasterxml/jackson/databind/jsonschema/factories/SchemaFactoryDelegate.java b/src/main/java/com/fasterxml/jackson/databind/jsonschema/factories/SchemaFactoryDelegate.java new file mode 100644 index 0000000000..6eb23b9080 --- /dev/null +++ b/src/main/java/com/fasterxml/jackson/databind/jsonschema/factories/SchemaFactoryDelegate.java @@ -0,0 +1,8 @@ +package com.fasterxml.jackson.databind.jsonschema.factories; + +import com.fasterxml.jackson.databind.jsonschema.types.Schema; + +public interface SchemaFactoryDelegate { + + public Schema getSchema(); +} diff --git a/src/main/java/com/fasterxml/jackson/databind/jsonschema/factories/StringSchemaFactory.java b/src/main/java/com/fasterxml/jackson/databind/jsonschema/factories/StringSchemaFactory.java new file mode 100644 index 0000000000..28e2b237e0 --- /dev/null +++ b/src/main/java/com/fasterxml/jackson/databind/jsonschema/factories/StringSchemaFactory.java @@ -0,0 +1,23 @@ +package com.fasterxml.jackson.databind.jsonschema.factories; + +import com.fasterxml.jackson.databind.jsonschema.types.StringSchema; +import com.fasterxml.jackson.databind.jsonschema.types.ValueTypeSchema; +import com.fasterxml.jackson.databind.jsonschema.visitors.JsonStringFormatVisitor; + +public class StringSchemaFactory extends ValueTypeSchemaFactory implements JsonStringFormatVisitor, + SchemaFactoryDelegate { + + protected StringSchema stringSchema; + protected SchemaFactory parent; + + public StringSchemaFactory(SchemaFactory parent) { + super(parent.mapper); + this.parent = parent; + stringSchema = new StringSchema(); + } + + public ValueTypeSchema getValueSchema() { + return stringSchema; + } + +} diff --git a/src/main/java/com/fasterxml/jackson/databind/jsonschema/factories/ValueTypeSchemaFactory.java b/src/main/java/com/fasterxml/jackson/databind/jsonschema/factories/ValueTypeSchemaFactory.java new file mode 100644 index 0000000000..88f075081b --- /dev/null +++ b/src/main/java/com/fasterxml/jackson/databind/jsonschema/factories/ValueTypeSchemaFactory.java @@ -0,0 +1,33 @@ +package com.fasterxml.jackson.databind.jsonschema.factories; + +import java.util.Set; + +import com.fasterxml.jackson.databind.ObjectMapper; +import com.fasterxml.jackson.databind.jsonschema.types.JsonValueFormat; +import com.fasterxml.jackson.databind.jsonschema.types.Schema; +import com.fasterxml.jackson.databind.jsonschema.types.ValueTypeSchema; +import com.fasterxml.jackson.databind.jsonschema.visitors.JsonValueFormatVisitor; + +public abstract class ValueTypeSchemaFactory extends SchemaFactory implements + SchemaFactoryDelegate, JsonValueFormatVisitor { + + protected ValueTypeSchemaFactory(ObjectMapper mapper) { + super(mapper); + } + + public Schema getSchema() { + return getValueSchema(); + } + protected abstract ValueTypeSchema getValueSchema(); + + public void format(JsonValueFormat format) { + getValueSchema().setFormat(format); + + } + + public void enumTypes(Set enums) { + getValueSchema().setEnums(enums); + + } + +} diff --git a/src/main/java/com/fasterxml/jackson/databind/jsonschema/types/AnySchema.java b/src/main/java/com/fasterxml/jackson/databind/jsonschema/types/AnySchema.java index 66578395e6..ae2e872d42 100644 --- a/src/main/java/com/fasterxml/jackson/databind/jsonschema/types/AnySchema.java +++ b/src/main/java/com/fasterxml/jackson/databind/jsonschema/types/AnySchema.java @@ -1,7 +1,34 @@ package com.fasterxml.jackson.databind.jsonschema.types; -import com.fasterxml.jackson.databind.node.TextNode; +import java.util.Set; -public class AnySchema extends ValueTypeSchema { - public static final TextNode type = TextNode.valueOf(SchemaType.ANY.toString()); +import com.fasterxml.jackson.annotation.JsonProperty; + + +public class AnySchema extends SimpleTypeSchema { + + @JsonProperty(required = true) + public final SchemaType type = SchemaType.ANY; + + /** + * This provides an enumeration of all possible values that are valid + for the instance property. This MUST be an array, and each item in + the array represents a possible value for the instance value. If + this attribute is defined, the instance value MUST be one of the + values in the array in order for the schema to be valid. Comparison + of enum values uses the same algorithm as defined in "uniqueItems" + (Section 5.15). + */ + @JsonProperty + private Set enums; + + public void setEnums(Set enums) { + this.enums = enums; + } + + @Override + public boolean isAnySchema() { return true; } + + @Override + public AnySchema asAnySchema() { return this; } } \ No newline at end of file diff --git a/src/main/java/com/fasterxml/jackson/databind/jsonschema/types/ArraySchema.java b/src/main/java/com/fasterxml/jackson/databind/jsonschema/types/ArraySchema.java index eebe10b069..2f7677793d 100644 --- a/src/main/java/com/fasterxml/jackson/databind/jsonschema/types/ArraySchema.java +++ b/src/main/java/com/fasterxml/jackson/databind/jsonschema/types/ArraySchema.java @@ -1,6 +1,7 @@ package com.fasterxml.jackson.databind.jsonschema.types; -import com.fasterxml.jackson.databind.node.TextNode; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.annotation.JsonValue; /* * This attribute defines the allowed items in an instance array, and @@ -8,15 +9,47 @@ empty schema which allows any value for items in the instance array. */ public class ArraySchema extends ContainerTypeSchema { - public static final TextNode type = TextNode.valueOf(SchemaType.ARRAY.toString()); - //This attribute defines the minimum number of values in an array + @JsonProperty(required = true) + public final SchemaType type = SchemaType.ARRAY; + + /**This attribute defines the minimum number of values in an array*/ + @JsonProperty private int minItems; + /** + * {@link ArraySchema#minItems} + * @param minItems the minItems to set + */ + public void setMinItems(int minItems) { + this.minItems = minItems; + } + /** + * {@link ArraySchema#minItems} + * @return the minItems + */ + public int getMinItems() { + return minItems; + } - //This attribute defines the maximum number of values in an array + /**This attribute defines the maximum number of values in an array*/ + @JsonProperty private int maxItems; + /** + * {@link ArraySchema#maxItems} + * @param maxItems the maxItems to set + */ + public void setMaxItems(int maxItems) { + this.maxItems = maxItems; + } + /** + * {@link ArraySchema#maxItems} + * @return the maxItems + */ + public int getMaxItems() { + return maxItems; + } - /* + /** * This attribute indicates that all items in an array instance MUST be unique (contains no two identical values). @@ -33,54 +66,123 @@ public class ArraySchema extends ContainerTypeSchema { in the object is equal to the corresponding property in the other object. */ - private boolean uniqueItems; + @JsonProperty + private Boolean uniqueItems; + + /** + * {@link ArraySchema#uniqueItems} + * @param uniqueItems the uniqueItems to set + */ + public void setUniqueItems(Boolean uniqueItems) { + this.uniqueItems = uniqueItems; + } + /** + * {@link ArraySchema#uniqueItems} + * @return the uniqueItems + */ + public Boolean getUniqueItems() { + return uniqueItems; + } + + @JsonProperty private ArraySchema.Items items; + /** + * {@link ArraySchema#items} + * @param items the items to set + */ + public void setItems(ArraySchema.Items items) { + this.items = items; + } + /** + * {@link ArraySchema#items} + * @return the items + */ + public ArraySchema.Items getItems() { + return items; + } + public void setItemsSchema(Schema schema) { + items = new SingleItems(schema); + } + + @JsonProperty private ArraySchema.AdditionalItems additionalItems; + /** + * {@link ArraySchema#additionalItems} + * @param additionalItems the additionalItems to set + */ + public void setAdditionalItems(ArraySchema.AdditionalItems additionalItems) { + this.additionalItems = additionalItems; + } + /** + * {@link ArraySchema#additionalItems} + * @return the additionalItems + */ + public ArraySchema.AdditionalItems getAdditionalItems() { + return additionalItems; + } - /* + /** * This attribute defines the allowed items in an instance array, and MUST be a schema or an array of schemas. The default value is an empty schema which allows any value for items in the instance array. */ public static abstract class Items {} - /* + /** * When this attribute value is a schema and the instance value is an array, then all the items in the array MUST be valid according to the schema. */ public static class SingleItems extends ArraySchema.Items { - public static final ArraySchema.SingleItems defaultSingleItems = new SingleItems(); + @JsonProperty + private Schema schema; + public SingleItems(Schema schema) { + this.schema = schema; + } } - /* + /** * When this attribute value is an array of schemas and the instance value is an array, each position in the instance array MUST conform to the schema in the corresponding position for this array. This called tuple typing. When tuple typing is used, additional items are allowed, disallowed, or constrained by the "additionalItems" */ - public static class ArrayItems extends ArraySchema.Items {} + public static class ArrayItems extends ArraySchema.Items { + @JsonProperty + private Schema[] schemas; + } - /* + /** * This provides a definition for additional items in an array instance when tuple definitions of the items is provided. */ public static abstract class AdditionalItems {} - /* + /** * This can be false to indicate additional items in the array are not allowed */ - public static class NoAdditionalItems {} + public static class NoAdditionalItems { + @JsonValue + public Boolean value() { return false; } + } - /* + /** * or it can be a schema that defines the schema of the additional items. */ public static class SchemaAdditionalItems { + + @JsonProperty(required = true) private Schema schema; } + + @Override + public boolean isArraySchema() { return true; } + + @Override + public ArraySchema asArraySchema() { return this; } } \ No newline at end of file diff --git a/src/main/java/com/fasterxml/jackson/databind/jsonschema/types/BooleanSchema.java b/src/main/java/com/fasterxml/jackson/databind/jsonschema/types/BooleanSchema.java index 198e10c813..2aef4ee400 100644 --- a/src/main/java/com/fasterxml/jackson/databind/jsonschema/types/BooleanSchema.java +++ b/src/main/java/com/fasterxml/jackson/databind/jsonschema/types/BooleanSchema.java @@ -1,8 +1,15 @@ package com.fasterxml.jackson.databind.jsonschema.types; -import com.fasterxml.jackson.databind.node.BooleanNode; -import com.fasterxml.jackson.databind.node.TextNode; +import com.fasterxml.jackson.annotation.JsonProperty; -public class BooleanSchema extends ValueTypeSchema { - public static final TextNode type = TextNode.valueOf(SchemaType.BOOLEAN.toString()); +public class BooleanSchema extends ValueTypeSchema { + + @JsonProperty(required = true) + public final SchemaType type = SchemaType.BOOLEAN; + + @Override + public boolean isBooleanSchema() { return true; } + + @Override + public BooleanSchema asBooleanSchema() { return this; } } \ No newline at end of file diff --git a/src/main/java/com/fasterxml/jackson/databind/jsonschema/types/ContainerTypeSchema.java b/src/main/java/com/fasterxml/jackson/databind/jsonschema/types/ContainerTypeSchema.java index 5b3f27738a..7d99bdd6d4 100644 --- a/src/main/java/com/fasterxml/jackson/databind/jsonschema/types/ContainerTypeSchema.java +++ b/src/main/java/com/fasterxml/jackson/databind/jsonschema/types/ContainerTypeSchema.java @@ -1,6 +1,27 @@ package com.fasterxml.jackson.databind.jsonschema.types; +import java.util.Set; + +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.databind.JsonNode; + public abstract class ContainerTypeSchema extends SimpleTypeSchema { + /** + * This provides an enumeration of all possible values that are valid + for the instance property. This MUST be an array, and each item in + the array represents a possible value for the instance value. If + this attribute is defined, the instance value MUST be one of the + values in the array in order for the schema to be valid. Comparison + of enum values uses the same algorithm as defined in "uniqueItems" + (Section 5.15). + */ + @JsonProperty(required = true) + private Set enums; + + @Override + public boolean isContainerTypeSchema() { return true; } + @Override + public ContainerTypeSchema asContainerSchema() { return this; } } \ No newline at end of file diff --git a/src/main/java/com/fasterxml/jackson/databind/jsonschema/types/HyperSchema.java b/src/main/java/com/fasterxml/jackson/databind/jsonschema/types/HyperSchema.java index 64881d0179..2974908732 100644 --- a/src/main/java/com/fasterxml/jackson/databind/jsonschema/types/HyperSchema.java +++ b/src/main/java/com/fasterxml/jackson/databind/jsonschema/types/HyperSchema.java @@ -1,28 +1,29 @@ package com.fasterxml.jackson.databind.jsonschema.types; -import com.fasterxml.jackson.databind.jsonschema.types.HyperSchema.LinkDescriptionObject; -import com.fasterxml.jackson.databind.node.TextNode; +import com.fasterxml.jackson.annotation.JsonProperty; public class HyperSchema extends Schema { - /* + /** * This attribute indicates that the instance property SHOULD NOT be changed. Attempts by a user agent to modify the value of this property are expected to be rejected by a server. */ - private TextNode readOnly; + @JsonProperty + private String readOnly; - /* + /** * If the instance property value is a string, this attribute defines that the string SHOULD be interpreted as binary data and decoded using the encoding named by this schema property. RFC 2045, Sec 6.1 [RFC2045] lists the possible values for this property. */ - private TextNode contentEncoding; + @JsonProperty + private String contentEncoding; - /* + /** * This attribute is a URI that defines what the instance's URI MUST start with in order to validate. The value of the "pathStart" attribute MUST be resolved as per RFC 3986, Sec 5 [RFC3986], and is @@ -38,15 +39,17 @@ public class HyperSchema extends Schema { not have a pathStart attribute SHOULD be considered applicable to all the instances for which it is referenced. */ - private TextNode pathStart; + @JsonProperty + private String pathStart; - /* + /** * This attribute defines the media type of the instance representations that this schema is defining. */ - private TextNode mediaType; + @JsonProperty + private String mediaType; - /* + /** * This property indicates the fragment resolution protocol to use for resolving fragment identifiers in URIs within the instance representations. This applies to the instance object URIs and all @@ -59,8 +62,9 @@ public class HyperSchema extends Schema { defines the mechanism for resolving references to entities within a document. */ - private TextNode fragmentResolution; - /* + @JsonProperty + private String fragmentResolution; + /** * 6.2.1. slash-delimited fragment resolution With the slash-delimited fragment resolution protocol, the fragment @@ -122,9 +126,10 @@ public class HyperSchema extends Schema { value of the foo propery. */ + @JsonProperty private LinkDescriptionObject[] links; - /* + /** * A link description object is used to describe link relations. In the context of a schema, it defines the link relations of the instances of the schema, and can be parameterized by the instance values. The @@ -135,7 +140,7 @@ link description format can be used on its own in regular (non-schema */ public class LinkDescriptionObject { - /* + /** * The value of the "href" link description property indicates the target URI of the related resource. The value of the instance property SHOULD be resolved as a URI-Reference per RFC 3986 [RFC3986] @@ -169,9 +174,10 @@ in situations where the instance is a scalar (string, boolean, or number), and not for objects or arrays. */ - private TextNode href; + @JsonProperty + private String href; - /* + /** * The value of the "rel" property indicates the name of the relation to the target resource. The relation to the target SHOULD be interpreted as specifically from the instance object that the schema @@ -261,24 +267,27 @@ The following relations are applicable for schemas (the schema as the "/Resource/parent". The "children" collection would be located at "/Resource/?upId=thing". */ - private TextNode rel; + @JsonProperty + private String rel; - /* + /** * This property value is a schema that defines the expected structure of the JSON representation of the target of the link. */ + @JsonProperty private Schema targetSchema; - /* + /** * This attribute defines which method can be used to access the target resource. In an HTTP environment, this would be "GET" or "POST" (other HTTP methods such as "PUT" and "DELETE" have semantics that are clearly implied by accessed resources, and do not need to be defined here). This defaults to "GET". */ - private TextNode method; + @JsonProperty + private String method; - /* + /** * If present, this property indicates a query media type format that the server supports for querying or posting to the collection of instances at the target resource. The query can be suffixed to the @@ -308,14 +317,16 @@ data to the resource (depending on the method). For example, with by the href property is defined. If the method is POST, "application/json" is the default media type. */ - private TextNode enctype; + @JsonProperty + private String enctype; - /* + /** * This attribute contains a schema which defines the acceptable structure of the submitted request (for a GET request, this schema would define the properties for the query string and for a POST request, this would define the body). */ + @JsonProperty private Schema schema; } diff --git a/src/main/java/com/fasterxml/jackson/databind/jsonschema/types/IntegerSchema.java b/src/main/java/com/fasterxml/jackson/databind/jsonschema/types/IntegerSchema.java index b273af9c76..60bc18fdb8 100644 --- a/src/main/java/com/fasterxml/jackson/databind/jsonschema/types/IntegerSchema.java +++ b/src/main/java/com/fasterxml/jackson/databind/jsonschema/types/IntegerSchema.java @@ -1,16 +1,23 @@ package com.fasterxml.jackson.databind.jsonschema.types; -import com.fasterxml.jackson.databind.node.IntNode; -import com.fasterxml.jackson.databind.node.TextNode; +import com.fasterxml.jackson.annotation.JsonProperty; public class IntegerSchema extends NumberSchema { - public static final TextNode type = TextNode.valueOf(SchemaType.INTEGER.toString()); - /* + @JsonProperty(required = true) + public final SchemaType type = SchemaType.INTEGER; + + /** * This attribute defines what value the number instance must be divisible by with no remainder (the result of the division must be an integer.) The value of this attribute SHOULD NOT be 0. */ - private IntNode divisibleBy; + @JsonProperty + private Integer divisibleBy; + + @Override + public boolean isIntegerSchema() { return true; } + @Override + public IntegerSchema asIntegerSchema() { return this; } } \ No newline at end of file diff --git a/src/main/java/com/fasterxml/jackson/databind/jsonschema/types/JsonValueFormat.java b/src/main/java/com/fasterxml/jackson/databind/jsonschema/types/JsonValueFormat.java new file mode 100644 index 0000000000..f02cf78449 --- /dev/null +++ b/src/main/java/com/fasterxml/jackson/databind/jsonschema/types/JsonValueFormat.java @@ -0,0 +1,119 @@ +package com.fasterxml.jackson.databind.jsonschema.types; + +public enum JsonValueFormat { + /* + * This SHOULD be a date in ISO 8601 format of YYYY-MM- + DDThh:mm:ssZ in UTC time. This is the recommended form of date/ + timestamp. + */ + DATE_TIME { + @Override + public String toString() { return "date-time"; } + }, + + /* + * This SHOULD be a date in the format of YYYY-MM-DD. It is + recommended that you use the "date-time" format instead of "date" + unless you need to transfer only the date part. + */ + DATE { + @Override + public String toString() { return "date"; } + }, + + /* + * This SHOULD be a time in the format of hh:mm:ss. It is + recommended that you use the "date-time" format instead of "time" + unless you need to transfer only the time part. + */ + TIME { + @Override + public String toString() { return "time"; } + }, + + /* + * This SHOULD be the difference, measured in + milliseconds, between the specified time and midnight, 00:00 of + January 1, 1970 UTC. The value SHOULD be a number (integer or + float). + */ + UTC_MILLISEC { + @Override + public String toString() { return "utc-millisec"; } + }, + + /* + * A regular expression, following the regular expression + specification from ECMA 262/Perl 5. + */ + REGEX { + @Override + public String toString() { return "regex"; } + }, + + /* + * This is a CSS color (like "#FF0000" or "red"), based on CSS + 2.1 [W3C.CR-CSS21-20070719]. + */ + COLOR { + @Override + public String toString() { return "color"; } + }, + + /* + * This is a CSS style definition (like "color: red; background- + color:#FFF"), based on CSS 2.1 [W3C.CR-CSS21-20070719]. + */ + STYLE { + @Override + public String toString() { return "style"; } + }, + + /* + * This SHOULD be a phone number (format MAY follow E.123). + */ + PHONE { + @Override + public String toString() { return "phone"; } + }, + + /* + * This value SHOULD be a URI.. + */ + URI { + @Override + public String toString() { return "uri"; } + }, + + /* + * This SHOULD be an email address. + */ + EMAIL { + @Override + public String toString() { return "email"; } + }, + /* + * This SHOULD be an ip version 4 address. + */ + IP_ADDRESS { + @Override + public String toString() { return "ip-address"; } + }, + + /* + * This SHOULD be an ip version 6 address. + */ + IPV6 { + @Override + public String toString() { return "ipv6"; } + }, + + /* + * This SHOULD be a host-name. + */ + HOST_NAME { + @Override + public String toString() { return "host-name"; } + } + +} \ No newline at end of file diff --git a/src/main/java/com/fasterxml/jackson/databind/jsonschema/types/NullSchema.java b/src/main/java/com/fasterxml/jackson/databind/jsonschema/types/NullSchema.java index 52d29cd18a..96edc3c8dd 100644 --- a/src/main/java/com/fasterxml/jackson/databind/jsonschema/types/NullSchema.java +++ b/src/main/java/com/fasterxml/jackson/databind/jsonschema/types/NullSchema.java @@ -1,10 +1,18 @@ package com.fasterxml.jackson.databind.jsonschema.types; -import com.fasterxml.jackson.databind.node.TextNode; +import com.fasterxml.jackson.annotation.JsonProperty; /** * value must be null; */ -public class NullSchema extends ValueTypeSchema { - public static final TextNode type = TextNode.valueOf(SchemaType.NULL.toString()); +public class NullSchema extends SimpleTypeSchema { + + @JsonProperty(required = true) + public final SchemaType type = SchemaType.NULL; + + @Override + public boolean isNullSchema() { return true; } + + @Override + public NullSchema asNullSchema() { return this; } } \ No newline at end of file diff --git a/src/main/java/com/fasterxml/jackson/databind/jsonschema/types/NumberSchema.java b/src/main/java/com/fasterxml/jackson/databind/jsonschema/types/NumberSchema.java index a674cbb791..59c3fb28f6 100644 --- a/src/main/java/com/fasterxml/jackson/databind/jsonschema/types/NumberSchema.java +++ b/src/main/java/com/fasterxml/jackson/databind/jsonschema/types/NumberSchema.java @@ -1,29 +1,96 @@ package com.fasterxml.jackson.databind.jsonschema.types; -import com.fasterxml.jackson.databind.node.BooleanNode; -import com.fasterxml.jackson.databind.node.NumericNode; -import com.fasterxml.jackson.databind.node.TextNode; +import com.fasterxml.jackson.annotation.JsonProperty; -public class NumberSchema extends ValueTypeSchema { - public static final TextNode type = TextNode.valueOf(SchemaType.NUMBER.toString()); - //This attribute defines the minimum value of the instance property - private NumericNode minimum; +public class NumberSchema extends ValueTypeSchema { - //This attribute defines the maximum value of the instance property - private NumericNode maximum; + @JsonProperty(required = true) + public final SchemaType type = SchemaType.NUMBER; - /* + /**This attribute defines the minimum value of the instance property*/ + @JsonProperty + private Double minimum; + /** + * {@link NumberSchema#minimum} + * @param minimum the minimum to set + */ + public void setMinimum(Double minimum) { + this.minimum = minimum; + } + /** + * {@link NumberSchema#minimum} + * @return the minimum + */ + public Double getMinimum() { + return minimum; + } + + + /**This attribute defines the maximum value of the instance property*/ + @JsonProperty + private Double maximum; + /** + * {@link NumberSchema#maximum} + * @param maximum the maximum to set + */ + public void setMaximum(Double maximum) { + this.maximum = maximum; + } + /** + * {@link NumberSchema#maximum} + * @return the maximum + */ + public Double getMaximum() { + return maximum; + } + + /** * This attribute indicates if the value of the instance (if the instance is a number) can not equal the number defined by the "minimum" attribute. */ - private BooleanNode exclusiveMinimum = BooleanNode.FALSE; + @JsonProperty + private Boolean exclusiveMinimum; + /** + * {@link NumberSchema#exclusiveMinimum} + * @param exclusiveMinimum the exclusiveMinimum to set + */ + public void setExclusiveMinimum(Boolean exclusiveMinimum) { + this.exclusiveMinimum = exclusiveMinimum; + } + /** + * {@link NumberSchema#exclusiveMinimum} + * @return the exclusiveMinimum + */ + public Boolean getExclusiveMinimum() { + return exclusiveMinimum; + } - /* + /** * This attribute indicates if the value of the instance (if the instance is a number) can not equal the number defined by the "maximum" attribute. */ - private BooleanNode exclusiveMaximum = BooleanNode.FALSE; + @JsonProperty + private Boolean exclusiveMaximum; + /** + * {@link NumberSchema#exclusiveMaximum} + * @param exclusiveMaximum the exclusiveMaximum to set + */ + public void setExclusiveMaximum(Boolean exclusiveMaximum) { + this.exclusiveMaximum = exclusiveMaximum; + } + /** + * {@link NumberSchema#exclusiveMaximum} + * @return the exclusiveMaximum + */ + public Boolean getExclusiveMaximum() { + return exclusiveMaximum; + } + @Override + public boolean isNumberSchema() { return true; } + + @Override + public NumberSchema asNumberSchema() { return this; } } \ No newline at end of file diff --git a/src/main/java/com/fasterxml/jackson/databind/jsonschema/types/ObjectSchema.java b/src/main/java/com/fasterxml/jackson/databind/jsonschema/types/ObjectSchema.java index 88da2d2dcd..9623408d92 100644 --- a/src/main/java/com/fasterxml/jackson/databind/jsonschema/types/ObjectSchema.java +++ b/src/main/java/com/fasterxml/jackson/databind/jsonschema/types/ObjectSchema.java @@ -3,13 +3,15 @@ import java.util.List; import java.util.Map; -import com.fasterxml.jackson.databind.node.ObjectNode; -import com.fasterxml.jackson.databind.node.TextNode; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.annotation.JsonValue; public class ObjectSchema extends ContainerTypeSchema { - public static final TextNode type = TextNode.valueOf(SchemaType.OBJECT.toString()); - /* + @JsonProperty(required = true) + public final String type = SchemaType.OBJECT.toString(); + + /** * This attribute is an object with property definitions that define the valid values of instance object property values. When the instance value is an object, the property values of the instance object MUST @@ -20,12 +22,31 @@ public class ObjectSchema extends ContainerTypeSchema { the property definition. Properties are considered unordered, the order of the instance properties MAY be in any order. */ + @JsonProperty private Map properties; public Schema putProperty(String name, Schema value) { return properties.put(name, value); } + public void putOptionalProperty(String name, Schema schema) { + // just don't put anything in the property list + } + /** + * {@link ObjectSchema#properties} + * @param properties the properties to set + */ + public void setProperties(Map properties) { + this.properties = properties; + } + /** + * {@link ObjectSchema#properties} + * @return the properties + */ + public Map getProperties() { + return properties; + } + - /* + /** * This attribute is an object that defines the schema for a set of property names of an object instance. The name of each property of @@ -35,12 +56,27 @@ public Schema putProperty(String name, Schema value) { the instance's property MUST be valid against the pattern name's schema value. */ + @JsonProperty private Map patternProperties; public Schema putPatternProperty(String regex, Schema value) { return patternProperties.put(regex, value); } + /** + * {@link ObjectSchema#patternProperties} + * @param patternProperties the patternProperties to set + */ + public void setPatternProperties(Map patternProperties) { + this.patternProperties = patternProperties; + } + /** + * {@link ObjectSchema#patternProperties} + * @return the patternProperties + */ + public Map getPatternProperties() { + return patternProperties; + } - /* + /** * This attribute defines a schema for all properties that are not explicitly defined in an object type definition. If specified, the value MUST be a schema or a boolean. If false is provided, no @@ -48,29 +84,72 @@ public Schema putPatternProperty(String regex, Schema value) { the schema. The default value is an empty schema which allows any value for additional properties. */ + @JsonProperty private AdditionalProperties additionalProperties; public void rejectAdditionalProperties() { additionalProperties = NoAdditionalProperties.instance; } + /** + * {@link ObjectSchema#additionalProperties} + * @param additionalProperties the additionalProperties to set + */ + public void setAdditionalProperties( + AdditionalProperties additionalProperties) { + this.additionalProperties = additionalProperties; + } + /** + * {@link ObjectSchema#additionalProperties} + * @return the additionalProperties + */ + public AdditionalProperties getAdditionalProperties() { + return additionalProperties; + } public static abstract class AdditionalProperties {} public static class NoAdditionalProperties extends AdditionalProperties { public static final NoAdditionalProperties instance = new NoAdditionalProperties(); + protected NoAdditionalProperties() {} + + @JsonValue + public Boolean value() { + return schema; + } + + public final Boolean schema = false; } public static class SchemaAdditionalProperties extends AdditionalProperties{ + + @JsonProperty private Schema schema; + public SchemaAdditionalProperties(Schema schema) { this.schema = schema; } } - /* + /** * This attribute is an object that defines the requirements of a property on an instance object. If an object instance has a property with the same name as a property in this attribute's object, then the instance must be valid against the attribute's property value */ + @JsonProperty private List dependencies; + /** + * {@link ObjectSchema#dependencies} + * @param dependencies the dependencies to set + */ + public void setDependencies(List dependencies) { + this.dependencies = dependencies; + } + /** + * {@link ObjectSchema#dependencies} + * @return the dependencies + */ + public List getDependencies() { + return dependencies; + } + public boolean addSimpleDependency(String depender, String dependsOn) { return dependencies.add(new SimpleDependency(depender, dependsOn)); } @@ -80,7 +159,7 @@ public boolean addSchemaDependency(String depender, Schema parentMustMatch) { public static abstract class Dependency {} - /* + /** * Simple Dependency If the dependency value is a string, then the instance object MUST have a property with the same name as the dependency value. If the dependency value is an array of strings, @@ -88,7 +167,11 @@ public static abstract class Dependency {} as each string in the dependency value's array. */ public static class SimpleDependency extends Dependency { + + @JsonProperty(required = true) private String depender; + + @JsonProperty(required = true) private String dependsOn; public SimpleDependency(String depender, String dependsOn) { @@ -97,16 +180,27 @@ public SimpleDependency(String depender, String dependsOn) { } } - /* + /** * Schema Dependency If the dependency value is a schema, then the instance object MUST be valid against the schema. */ public static class SchemaDependency extends Dependency { + + @JsonProperty(required = true) private String depender; + + @JsonProperty(required = true) private Schema parentMustMatch; public SchemaDependency(String depender, Schema parentMustMatch) { this.depender = depender; this.parentMustMatch = parentMustMatch; } } + + @Override + public boolean isObjectSchema() { return true ;} + + @Override + public ObjectSchema asObjectSchema() { return this; } + } \ No newline at end of file diff --git a/src/main/java/com/fasterxml/jackson/databind/jsonschema/types/Schema.java b/src/main/java/com/fasterxml/jackson/databind/jsonschema/types/Schema.java index 88d4abe2fa..083ecdaaed 100644 --- a/src/main/java/com/fasterxml/jackson/databind/jsonschema/types/Schema.java +++ b/src/main/java/com/fasterxml/jackson/databind/jsonschema/types/Schema.java @@ -1,20 +1,10 @@ package com.fasterxml.jackson.databind.jsonschema.types; -import java.lang.reflect.Type; -import com.fasterxml.jackson.databind.JavaType; -import com.fasterxml.jackson.databind.JsonMappingException; -import com.fasterxml.jackson.databind.JsonNode; -import com.fasterxml.jackson.databind.JsonSerializer; -import com.fasterxml.jackson.databind.SerializerProvider; -import com.fasterxml.jackson.databind.jsonschema.JsonSchema; -import com.fasterxml.jackson.databind.jsonschema.SchemaAware; -import com.fasterxml.jackson.databind.node.BooleanNode; -import com.fasterxml.jackson.databind.node.ObjectNode; -import com.fasterxml.jackson.databind.node.TextNode; -import com.fasterxml.jackson.databind.ser.BeanPropertyFilter; -import com.fasterxml.jackson.databind.ser.BeanPropertyWriter; -import com.fasterxml.jackson.databind.ser.std.BeanSerializerBase; +import com.fasterxml.jackson.annotation.JsonGetter; +import com.fasterxml.jackson.annotation.JsonIgnore; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.annotation.JsonSetter; /** * Json Schema Draft @@ -81,60 +71,35 @@ * @author jphelan */ public abstract class Schema { - public JsonNode asJson() { - - return null; - } - - /** - * Attempt to add the output of the given {@link BeanPropertyWriter} in the given {@link ObjectNode}. - * Otherwise, add the default schema {@link JsonNode} in place of the writer's output - * - * @param writer Bean property serializer to use to create schema value - * @param propertiesNode Node which the given property would exist within - * @param provider Provider that can be used for accessing dynamic aspects of serialization - * processing - * - * {@link BeanPropertyFilter#depositSchemaProperty(BeanPropertyWriter, ObjectNode, SerializerProvider)} - */ - public static void depositSchemaProperty(BeanPropertyWriter writer, ObjectNode propertiesNode, SerializerProvider provider) { - JavaType propType = writer.getSerializationType(); - - // 03-Dec-2010, tatu: SchemaAware REALLY should use JavaType, but alas it doesn't... - Type hint = (propType == null) ? writer.getGenericPropertyType() : propType.getRawClass(); - JsonNode schemaNode; - // Maybe it already has annotated/statically configured serializer? - JsonSerializer ser = writer.getSerializer(); - - try { - if (ser == null) { // nope - Class serType = writer.getRawSerializationType(); - if (serType == null) { - serType = writer.getPropertyType(); - } - ser = provider.findValueSerializer(serType, writer); - } - boolean isOptional = !BeanSerializerBase.isPropertyRequired(writer, provider); - if (ser instanceof SchemaAware) { - schemaNode = ((SchemaAware) ser).getSchema(provider, hint, isOptional) ; - } else { - schemaNode = JsonSchema.getDefaultSchemaNode(); - } - } catch (JsonMappingException e) { - schemaNode = JsonSchema.getDefaultSchemaNode(); - //TODO: log error - } - propertiesNode.put(writer.getName(), schemaNode); + + public final SchemaType type = null; + + public SchemaType getType() { + return this.type; } - - /* + + /** * This attribute indicates if the instance must have a value, and not be undefined. This is false by default, making the instance optional. */ - private BooleanNode required = BooleanNode.FALSE;// default = false; - - /* + @JsonProperty + private Boolean required = false;// default = false; + /** + * {@link Schema#required} + * @param required the required to set + */ + public void setRequired(Boolean required) { + this.required = required; + } + /** + * {@link Schema#required} + * @return the required + */ + public Boolean getRequired() { + return required; + } + /** * This attribute defines the current URI of this schema (this attribute is effectively a "self" link). This URI MAY be relative or absolute. If the URI is relative it is resolved against the current URI of the @@ -145,9 +110,23 @@ public static void depositSchemaProperty(BeanPropertyWriter writer, ObjectNode p The current URI of the schema is also used to construct relative references such as for $ref. */ - private TextNode id; - - /* + @JsonProperty + private String id; + /** + * {@link Schema#id} + * @param id the id to set + */ + public void setId(String id) { + this.id = id; + } + /** + * {@link Schema#id} + * @return the id + */ + public String getId() { + return id; + } + /** * This attribute defines a URI of a schema that contains the full representation of this schema. When a validator encounters this attribute, it SHOULD replace the current schema with the schema @@ -156,9 +135,23 @@ public static void depositSchemaProperty(BeanPropertyWriter writer, ObjectNode p relative URIs SHOULD be resolved against the URI of the current schema. */ - private TextNode $ref; - - /* + @JsonProperty + private String $ref; + /** + * {@link Schema#$ref} + * @param $ref the $ref to set + */ + public void set$ref(String $ref) { + this.$ref = $ref; + } + /** + * {@link Schema#$ref} + * @return the $ref + */ + public String get$ref() { + return $ref; + } + /** * This attribute defines a URI of a JSON Schema that is the schema of the current schema. When this attribute is defined, a validator SHOULD use the schema referenced by the value's URI (if known and @@ -173,9 +166,23 @@ public static void depositSchemaProperty(BeanPropertyWriter writer, ObjectNode p changes. */ - private TextNode $schema; - - /* + @JsonProperty + private String $schema; + /** + * {@link Schema#$schema} + * @param $schema the $schema to set + */ + public void set$schema(String $schema) { + this.$schema = $schema; + } + /** + * {@link Schema#$schema} + * @return the $schema + */ + public String get$schema() { + return $schema; + } + /** * The value of this property MUST be another schema which will provide a base schema which the current schema will inherit from. The inheritance rules are such that any instance that is valid according @@ -202,14 +209,108 @@ the extended schema(s). More optimized implementations that merge "extends":"http://json-schema.org/draft-03/schema" } */ + @JsonIgnore private Schema[] extendsextends; - - /* + /** + * {@link Schema#extendsextends} + * @param extendsextends the extendsextends to set + */ + @JsonSetter("extends") + public void setExtends(Schema[] extendsextends) { + this.extendsextends = extendsextends; + } + /** + * {@link Schema#extendsextends} + * @return the extendsextends + */ + @JsonGetter("extends") + public Schema[] getExtends() { + return extendsextends; + } + /** * This attribute takes the same values as the "type" attribute, however if the instance matches the type or if this value is an array and the instance matches any type or schema in the array, then this instance is not valid. */ + @JsonProperty private Schema[] disallow; + + /** + * {@link Schema#disallow} + * @param disallow the disallow to set + */ + public void setDisallow(Schema[] disallow) { + this.disallow = disallow; + } + /** + * {@link Schema#disallow} + * @return the disallow + */ + public Schema[] getDisallow() { + return disallow; + } + + //subtype oracles + + public boolean isUnionTypeSchema() { return false; } + + public boolean isSimpleTypeSchema() { return false; } + + public boolean isNullSchema() { return false; } + public boolean isAnySchema() { return false; } + + public boolean isContainerTypeSchema() { return false; } + public boolean isArraySchema() { return false; } + public boolean isObjectSchema() { return false; } + + public boolean isValueTypeSchema() { return false; } + public boolean isBooleanSchema() { return false; } + public boolean isIntegerSchema() { return false; } + public boolean isNumberSchema() { return false; } + public boolean isStringSchema() { return false; } + + // subtype retrievers: + + public UnionTypeSchema asUnionTypeSchema() { return null; } + + public SimpleTypeSchema asSimpleTypeSchema() { return null; } + + public NullSchema asNullSchema() { return null; } + public AnySchema asAnySchema() { return null; } + + public ContainerTypeSchema asContainerSchema() { return null; } + public ArraySchema asArraySchema() { return null; } + public ObjectSchema asObjectSchema() { return null; } + + public ValueTypeSchema asValueSchemaSchema() { return null; } + public BooleanSchema asBooleanSchema() { return null; } + public IntegerSchema asIntegerSchema() { return null; } + public NumberSchema asNumberSchema() { return null; } + public StringSchema asStringSchema() { return null; } + + + + public static Schema minimalForFormat(SchemaType format) { + switch (format) { + case ARRAY: + return new ArraySchema(); + case OBJECT: + return new ObjectSchema(); + case BOOLEAN: + return new BooleanSchema(); + case INTEGER: + return new IntegerSchema(); + case NUMBER: + return new NumberSchema(); + case STRING: + return new StringSchema(); + case NULL: + return new NullSchema(); + + default: + return new AnySchema(); + } + } } \ No newline at end of file diff --git a/src/main/java/com/fasterxml/jackson/databind/jsonschema/types/SimpleTypeSchema.java b/src/main/java/com/fasterxml/jackson/databind/jsonschema/types/SimpleTypeSchema.java index d2942c5559..b2084b95be 100644 --- a/src/main/java/com/fasterxml/jackson/databind/jsonschema/types/SimpleTypeSchema.java +++ b/src/main/java/com/fasterxml/jackson/databind/jsonschema/types/SimpleTypeSchema.java @@ -1,39 +1,81 @@ package com.fasterxml.jackson.databind.jsonschema.types; -import java.util.Set; - -import com.fasterxml.jackson.databind.JsonNode; -import com.fasterxml.jackson.databind.node.TextNode; +import com.fasterxml.jackson.annotation.JsonGetter; +import com.fasterxml.jackson.annotation.JsonIgnore; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.annotation.JsonSetter; public abstract class SimpleTypeSchema extends Schema { - /* - * This provides an enumeration of all possible values that are valid - for the instance property. This MUST be an array, and each item in - the array represents a possible value for the instance value. If - this attribute is defined, the instance value MUST be one of the - values in the array in order for the schema to be valid. Comparison - of enum values uses the same algorithm as defined in "uniqueItems" - (Section 5.15). - */ - private Set enumenum; - - /* + /** * This attribute defines the default value of the instance when the instance is undefined. */ - private JsonNode defaultdefault; + @JsonIgnore + private String defaultdefault; + /** + * {@link SimpleTypeSchema#defaultdefault} + * @param defaultdefault the defaultdefault to set + */ + @JsonSetter("default") + public void setDefault(String defaultdefault) { + this.defaultdefault = defaultdefault; + } + /** + * {@link SimpleTypeSchema#defaultdefault} + * @return the defaultdefault + */ + @JsonGetter("default") + public String getDefault() { + return defaultdefault; + } - /* + /** * This attribute is a string that provides a short description of the instance property. */ - private TextNode title; + @JsonProperty + private String title; + /** + * {@link SimpleTypeSchema#title} + * @param title the title to set + */ + public void setTitle(String title) { + this.title = title; + } + /** + * {@link SimpleTypeSchema#title} + * @return the title + */ + public String getTitle() { + return title; + } - /* + /** * This attribute is a string that provides a full description of the of purpose the instance property. */ - private TextNode description; + @JsonProperty + private String description; + /** + * {@link SimpleTypeSchema#description} + * @param description the description to set + */ + public void setDescription(String description) { + this.description = description; + } + /** + * {@link SimpleTypeSchema#description} + * @return the description + */ + public String getDescription() { + return description; + } + + @Override + public boolean isSimpleTypeSchema() { return true; } + + @Override + public SimpleTypeSchema asSimpleTypeSchema() { return this; } } \ No newline at end of file diff --git a/src/main/java/com/fasterxml/jackson/databind/jsonschema/types/StringSchema.java b/src/main/java/com/fasterxml/jackson/databind/jsonschema/types/StringSchema.java index d25c29790e..6faa7d9f52 100644 --- a/src/main/java/com/fasterxml/jackson/databind/jsonschema/types/StringSchema.java +++ b/src/main/java/com/fasterxml/jackson/databind/jsonschema/types/StringSchema.java @@ -1,23 +1,74 @@ package com.fasterxml.jackson.databind.jsonschema.types; -import com.fasterxml.jackson.databind.node.IntNode; -import com.fasterxml.jackson.databind.node.TextNode; +import com.fasterxml.jackson.annotation.JsonProperty; -public class StringSchema extends ValueTypeSchema { - public static final TextNode type = TextNode.valueOf(SchemaType.STRING.toString()); +public class StringSchema extends ValueTypeSchema { - /* + @JsonProperty(required = true) + public final SchemaType type = SchemaType.STRING; + + /** * this provides a regular expression that a string instance MUST match in order to be valid. Regular expressions SHOULD follow the regular expression specification from ECMA 262/Perl 5 */ - private TextNode pattern; + @JsonProperty + private String pattern; + /** + * {@link StringSchema#pattern} + * @param pattern the pattern to set + */ + public void setPattern(String pattern) { + this.pattern = pattern; + } + /** + * {@link StringSchema#pattern} + * @return the pattern + */ + public String getPattern() { + return pattern; + } + + /**this defines the minimum length of the string.*/ + @JsonProperty + private Integer minLength; + /** + * {@link StringSchema#minLength} + * @param minLength the minLength to set + */ + public void setMinLength(Integer minLength) { + this.minLength = minLength; + } + /** + * {@link StringSchema#minLength} + * @return the minLength + */ + public Integer getMinLength() { + return minLength; + } - //this defines the minimum length of the string. - private IntNode minLength; + /**this defines the maximum length of the string.*/ + @JsonProperty + private Integer maxLength; + /** + * {@link StringSchema#maxLength} + * @param maxLength the maxLength to set + */ + public void setMaxLength(Integer maxLength) { + this.maxLength = maxLength; + } + /** + * {@link StringSchema#maxLength} + * @return the maxLength + */ + public Integer getMaxLength() { + return maxLength; + } - //this defines the maximum length of the string. - private IntNode maxLength; + @Override + public boolean isStringSchema() { return true; } -} \ No newline at end of file + @Override + public StringSchema asStringSchema() { return this; } +} diff --git a/src/main/java/com/fasterxml/jackson/databind/jsonschema/types/UnionTypeSchema.java b/src/main/java/com/fasterxml/jackson/databind/jsonschema/types/UnionTypeSchema.java index 46a916437a..831ee7d57c 100644 --- a/src/main/java/com/fasterxml/jackson/databind/jsonschema/types/UnionTypeSchema.java +++ b/src/main/java/com/fasterxml/jackson/databind/jsonschema/types/UnionTypeSchema.java @@ -1,13 +1,30 @@ package com.fasterxml.jackson.databind.jsonschema.types; -import com.fasterxml.jackson.databind.node.ArrayNode; +import com.fasterxml.jackson.annotation.JsonProperty; public class UnionTypeSchema extends Schema { + + @JsonProperty private ValueTypeSchema[] elements; - private ArrayNode value; - public final ValueTypeSchema[] getElements() { return elements; } - public final void setElements(ValueTypeSchema[] elements) { + /** + * {@link UnionTypeSchema#elements} + * @param elements the elements to set + */ + public void setElements(ValueTypeSchema[] elements) { assert elements.length >= 2 : "Union Type Schemas must contain two or more Simple Type Schemas" ; this.elements = elements; } + /** + * {@link UnionTypeSchema#elements} + * @return the elements + */ + public ValueTypeSchema[] getElements() { + return elements; + } + + @Override + public UnionTypeSchema asUnionTypeSchema() { return this; } + + @Override + public boolean isUnionTypeSchema() { return true; } } \ No newline at end of file diff --git a/src/main/java/com/fasterxml/jackson/databind/jsonschema/types/ValueTypeSchema.java b/src/main/java/com/fasterxml/jackson/databind/jsonschema/types/ValueTypeSchema.java index db4bebe7af..ad133c6481 100644 --- a/src/main/java/com/fasterxml/jackson/databind/jsonschema/types/ValueTypeSchema.java +++ b/src/main/java/com/fasterxml/jackson/databind/jsonschema/types/ValueTypeSchema.java @@ -1,15 +1,15 @@ package com.fasterxml.jackson.databind.jsonschema.types; -import com.fasterxml.jackson.databind.JsonNode; +import java.util.Set; + +import com.fasterxml.jackson.annotation.JsonProperty; /** * A primitive type. */ -public abstract class ValueTypeSchema extends SimpleTypeSchema { - - private T value; - - /* +public abstract class ValueTypeSchema extends SimpleTypeSchema { + + /** * This property defines the type of data, content type, or microformat to be expected in the instance property values. A format attribute MAY be one of the values listed below, and if so, SHOULD adhere to @@ -17,62 +17,57 @@ public abstract class ValueTypeSchema extends SimpleTypeSche used to give meaning to primitive types (string, integer, number, or boolean). Validators MAY (but are not required to) validate that the instance values conform to a format. + + Additional custom formats MAY be created. These custom formats MAY + be expressed as an URI, and this URI MAY reference a schema of that */ - private ValueTypeSchema.Format format; + @JsonProperty + private JsonValueFormat format; + /** + * {@link ValueTypeSchema#format} + * @param format the format to set + */ + public void setFormat(JsonValueFormat format) { + this.format = format; + } + /** + * {@link ValueTypeSchema#format} + * @return the format + */ + public JsonValueFormat getFormat() { + return format; + } + - public static enum Format { - DATE_TIME { - @Override - public String toString() { return "date-time"; } - }, - DATE { - @Override - public String toString() { return "date"; } - }, - TIME { - @Override - public String toString() { return "time"; } - }, - UTC_MILLISEC { - @Override - public String toString() { return "utc-millisec"; } - }, - REGEX { - @Override - public String toString() { return "regex"; } - }, - COLOR { - @Override - public String toString() { return "color"; } - }, - STYLE { - @Override - public String toString() { return "style"; } - }, - PHONE { - @Override - public String toString() { return "phone"; } - }, - URI { - @Override - public String toString() { return "uri"; } - }, - EMAIL { - @Override - public String toString() { return "email"; } - }, - IP_ADDRESS { - @Override - public String toString() { return "ip-address"; } - }, - IPV6 { - @Override - public String toString() { return "ipv6"; } - }, - HOST_NAME { - @Override - public String toString() { return "host-name"; } - } - + /** + * This provides an enumeration of all possible values that are valid + for the instance property. This MUST be an array, and each item in + the array represents a possible value for the instance value. If + this attribute is defined, the instance value MUST be one of the + values in the array in order for the schema to be valid. Comparison + of enum values uses the same algorithm as defined in "uniqueItems" + (Section 5.15). + */ + @JsonProperty + private Set enums; + /** + * {@link ValueTypeSchema#enums} + * @param enums the enums to set + */ + public void setEnums(Set enums) { + this.enums = enums; + } + /** + * {@link ValueTypeSchema#enums} + * @return the enums + */ + public Set getEnums() { + return enums; } + + @Override + public boolean isValueTypeSchema() { return true; } + + @Override + public ValueTypeSchema asValueSchemaSchema() { return this; } } \ No newline at end of file diff --git a/src/main/java/com/fasterxml/jackson/databind/jsonschema/visitors/JsonAnyFormatVisitor.java b/src/main/java/com/fasterxml/jackson/databind/jsonschema/visitors/JsonAnyFormatVisitor.java new file mode 100644 index 0000000000..1a1b7a2abf --- /dev/null +++ b/src/main/java/com/fasterxml/jackson/databind/jsonschema/visitors/JsonAnyFormatVisitor.java @@ -0,0 +1,5 @@ +package com.fasterxml.jackson.databind.jsonschema.visitors; + +public interface JsonAnyFormatVisitor { + +} diff --git a/src/main/java/com/fasterxml/jackson/databind/jsonschema/visitors/JsonArrayFormatVisitor.java b/src/main/java/com/fasterxml/jackson/databind/jsonschema/visitors/JsonArrayFormatVisitor.java new file mode 100644 index 0000000000..6331a6d57d --- /dev/null +++ b/src/main/java/com/fasterxml/jackson/databind/jsonschema/visitors/JsonArrayFormatVisitor.java @@ -0,0 +1,15 @@ +package com.fasterxml.jackson.databind.jsonschema.visitors; + +import com.fasterxml.jackson.databind.JavaType; +import com.fasterxml.jackson.databind.jsonschema.SchemaAware; +import com.fasterxml.jackson.databind.jsonschema.types.SchemaType; + +public interface JsonArrayFormatVisitor { + + void itemsFormat(JavaType contentType); + + void itemsFormat(SchemaType format); + + void itemsFormat(SchemaAware toVisit); + +} diff --git a/src/main/java/com/fasterxml/jackson/databind/jsonschema/visitors/JsonBooleanFormatVisitor.java b/src/main/java/com/fasterxml/jackson/databind/jsonschema/visitors/JsonBooleanFormatVisitor.java new file mode 100644 index 0000000000..1b200ed61a --- /dev/null +++ b/src/main/java/com/fasterxml/jackson/databind/jsonschema/visitors/JsonBooleanFormatVisitor.java @@ -0,0 +1,5 @@ +package com.fasterxml.jackson.databind.jsonschema.visitors; + +public interface JsonBooleanFormatVisitor extends JsonValueFormatVisitor { + +} diff --git a/src/main/java/com/fasterxml/jackson/databind/jsonschema/visitors/JsonFormatVisitor.java b/src/main/java/com/fasterxml/jackson/databind/jsonschema/visitors/JsonFormatVisitor.java new file mode 100644 index 0000000000..aae53a9405 --- /dev/null +++ b/src/main/java/com/fasterxml/jackson/databind/jsonschema/visitors/JsonFormatVisitor.java @@ -0,0 +1,20 @@ +package com.fasterxml.jackson.databind.jsonschema.visitors; + +import java.lang.reflect.Type; + +import com.fasterxml.jackson.databind.SerializerProvider; + +public interface JsonFormatVisitor { + + public JsonObjectFormatVisitor objectFormat(Type type); + public JsonArrayFormatVisitor arrayFormat(Type elementType); + public JsonStringFormatVisitor stringFormat(); + public JsonNumberFormatVisitor numberFormat(); + public JsonIntegerFormatVisitor integerFormat(); + public JsonBooleanFormatVisitor booleanFormat(); + public JsonNullFormatVisitor nullFormat(); + public JsonAnyFormatVisitor anyFormat(); + + public SerializerProvider getProvider(); + +} diff --git a/src/main/java/com/fasterxml/jackson/databind/jsonschema/visitors/JsonIntegerFormatVisitor.java b/src/main/java/com/fasterxml/jackson/databind/jsonschema/visitors/JsonIntegerFormatVisitor.java new file mode 100644 index 0000000000..8bc066a2bc --- /dev/null +++ b/src/main/java/com/fasterxml/jackson/databind/jsonschema/visitors/JsonIntegerFormatVisitor.java @@ -0,0 +1,5 @@ +package com.fasterxml.jackson.databind.jsonschema.visitors; + +public interface JsonIntegerFormatVisitor extends JsonValueFormatVisitor { + +} diff --git a/src/main/java/com/fasterxml/jackson/databind/jsonschema/visitors/JsonNullFormatVisitor.java b/src/main/java/com/fasterxml/jackson/databind/jsonschema/visitors/JsonNullFormatVisitor.java new file mode 100644 index 0000000000..e220f775f2 --- /dev/null +++ b/src/main/java/com/fasterxml/jackson/databind/jsonschema/visitors/JsonNullFormatVisitor.java @@ -0,0 +1,5 @@ +package com.fasterxml.jackson.databind.jsonschema.visitors; + +public interface JsonNullFormatVisitor { + +} diff --git a/src/main/java/com/fasterxml/jackson/databind/jsonschema/visitors/JsonNumberFormatVisitor.java b/src/main/java/com/fasterxml/jackson/databind/jsonschema/visitors/JsonNumberFormatVisitor.java new file mode 100644 index 0000000000..78e5064f32 --- /dev/null +++ b/src/main/java/com/fasterxml/jackson/databind/jsonschema/visitors/JsonNumberFormatVisitor.java @@ -0,0 +1,7 @@ +package com.fasterxml.jackson.databind.jsonschema.visitors; + +import com.fasterxml.jackson.databind.jsonschema.types.JsonValueFormat; + +public interface JsonNumberFormatVisitor extends JsonValueFormatVisitor{ + +} diff --git a/src/main/java/com/fasterxml/jackson/databind/jsonschema/visitors/JsonObjectFormatVisitor.java b/src/main/java/com/fasterxml/jackson/databind/jsonschema/visitors/JsonObjectFormatVisitor.java new file mode 100644 index 0000000000..0a2113b1aa --- /dev/null +++ b/src/main/java/com/fasterxml/jackson/databind/jsonschema/visitors/JsonObjectFormatVisitor.java @@ -0,0 +1,23 @@ +package com.fasterxml.jackson.databind.jsonschema.visitors; + +import java.lang.reflect.Type; + +import com.fasterxml.jackson.databind.jsonschema.SchemaAware; +import com.fasterxml.jackson.databind.ser.BeanPropertyWriter; + +public interface JsonObjectFormatVisitor extends JsonFormatVisitor { + + public void property(BeanPropertyWriter writer); + + public void optionalProperty(BeanPropertyWriter writer); + + public void property(String name, SchemaAware handler, Type propertyTypeHint); + + public void optionalProperty(String name, SchemaAware handler, + Type propertyTypeHint); + + public void property(String name); + + public void optionalProperty(String name); + +} diff --git a/src/main/java/com/fasterxml/jackson/databind/jsonschema/visitors/JsonStringFormatVisitor.java b/src/main/java/com/fasterxml/jackson/databind/jsonschema/visitors/JsonStringFormatVisitor.java new file mode 100644 index 0000000000..e2d6ae85ce --- /dev/null +++ b/src/main/java/com/fasterxml/jackson/databind/jsonschema/visitors/JsonStringFormatVisitor.java @@ -0,0 +1,5 @@ +package com.fasterxml.jackson.databind.jsonschema.visitors; + +public interface JsonStringFormatVisitor extends JsonValueFormatVisitor { + +} diff --git a/src/main/java/com/fasterxml/jackson/databind/jsonschema/visitors/JsonValueFormatVisitor.java b/src/main/java/com/fasterxml/jackson/databind/jsonschema/visitors/JsonValueFormatVisitor.java new file mode 100644 index 0000000000..0f7558699d --- /dev/null +++ b/src/main/java/com/fasterxml/jackson/databind/jsonschema/visitors/JsonValueFormatVisitor.java @@ -0,0 +1,12 @@ +package com.fasterxml.jackson.databind.jsonschema.visitors; + +import java.util.Set; + +import com.fasterxml.jackson.databind.jsonschema.types.JsonValueFormat; + +public interface JsonValueFormatVisitor { + + void format(JsonValueFormat format); + + void enumTypes(Set enums); +} diff --git a/src/main/java/com/fasterxml/jackson/databind/ser/BeanPropertyFilter.java b/src/main/java/com/fasterxml/jackson/databind/ser/BeanPropertyFilter.java index e2171111c5..babae23128 100644 --- a/src/main/java/com/fasterxml/jackson/databind/ser/BeanPropertyFilter.java +++ b/src/main/java/com/fasterxml/jackson/databind/ser/BeanPropertyFilter.java @@ -2,6 +2,7 @@ import com.fasterxml.jackson.core.JsonGenerator; import com.fasterxml.jackson.databind.SerializerProvider; +import com.fasterxml.jackson.databind.jsonschema.visitors.JsonObjectFormatVisitor; import com.fasterxml.jackson.databind.node.ObjectNode; /** @@ -38,6 +39,6 @@ public void serializeAsField(Object bean, JsonGenerator jgen, SerializerProvider * processing * */ - public void depositSchemaProperty(BeanPropertyWriter writer, ObjectNode propertiesNode, + public void depositSchemaProperty(BeanPropertyWriter writer, JsonObjectFormatVisitor objectVisitor, SerializerProvider provider); } diff --git a/src/main/java/com/fasterxml/jackson/databind/ser/DefaultSerializerProvider.java b/src/main/java/com/fasterxml/jackson/databind/ser/DefaultSerializerProvider.java index c54d97eb8e..952e7f5733 100644 --- a/src/main/java/com/fasterxml/jackson/databind/ser/DefaultSerializerProvider.java +++ b/src/main/java/com/fasterxml/jackson/databind/ser/DefaultSerializerProvider.java @@ -15,6 +15,10 @@ import com.fasterxml.jackson.databind.introspect.ObjectIdInfo; import com.fasterxml.jackson.databind.jsonschema.JsonSchema; import com.fasterxml.jackson.databind.jsonschema.SchemaAware; +import com.fasterxml.jackson.databind.jsonschema.factories.SchemaFactory; +import com.fasterxml.jackson.databind.jsonschema.types.Schema; +import com.fasterxml.jackson.databind.jsonschema.types.SchemaType; +import com.fasterxml.jackson.databind.jsonschema.visitors.JsonFormatVisitor; import com.fasterxml.jackson.databind.node.ObjectNode; import com.fasterxml.jackson.databind.ser.impl.WritableObjectId; import com.fasterxml.jackson.databind.util.ClassUtil; @@ -233,12 +237,11 @@ public void serializeValue(JsonGenerator jgen, Object value, JavaType rootType, /** * The method to be called by {@link ObjectMapper} and {@link ObjectWriter} - * to generate JSON schema for - * given type. + TODO:fillme * * @param type The type for which to generate schema */ - public JsonSchema generateJsonSchema(Class type) + public void acceptJsonFormatVisitor(Class type, JsonFormatVisitor visitor) throws JsonMappingException { if (type == null) { @@ -248,16 +251,12 @@ public JsonSchema generateJsonSchema(Class type) * type information it needs is accessible via "untyped" serializer) */ JsonSerializer ser = findValueSerializer(type, null); - JsonNode schemaNode = (ser instanceof SchemaAware) ? - ((SchemaAware) ser).getSchema(this, null) : - 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"); + if (ser instanceof SchemaAware) { + ((SchemaAware) ser).acceptJsonFormatVisitor(visitor, type); + } else { + visitor.anyFormat(); } - return new JsonSchema((ObjectNode) schemaNode); } - /** * Method that can be called to see if this serializer provider * can find a serializer for an instance of given class. diff --git a/src/main/java/com/fasterxml/jackson/databind/ser/impl/FailingSerializer.java b/src/main/java/com/fasterxml/jackson/databind/ser/impl/FailingSerializer.java index f62d2d19e4..f2041f7542 100644 --- a/src/main/java/com/fasterxml/jackson/databind/ser/impl/FailingSerializer.java +++ b/src/main/java/com/fasterxml/jackson/databind/ser/impl/FailingSerializer.java @@ -5,9 +5,8 @@ import com.fasterxml.jackson.core.*; -import com.fasterxml.jackson.databind.JsonMappingException; -import com.fasterxml.jackson.databind.JsonNode; import com.fasterxml.jackson.databind.SerializerProvider; +import com.fasterxml.jackson.databind.jsonschema.visitors.JsonFormatVisitor; import com.fasterxml.jackson.databind.ser.std.StdSerializer; /** @@ -35,9 +34,8 @@ public void serialize(Object value, JsonGenerator jgen, SerializerProvider provi } @Override - public JsonNode getSchema(SerializerProvider provider, Type typeHint) - throws JsonMappingException + public void acceptJsonFormatVisitor(JsonFormatVisitor visitor, Type typeHint) { - return null; + ; } } diff --git a/src/main/java/com/fasterxml/jackson/databind/ser/impl/IndexedStringListSerializer.java b/src/main/java/com/fasterxml/jackson/databind/ser/impl/IndexedStringListSerializer.java index fce74ea756..09293cdf07 100644 --- a/src/main/java/com/fasterxml/jackson/databind/ser/impl/IndexedStringListSerializer.java +++ b/src/main/java/com/fasterxml/jackson/databind/ser/impl/IndexedStringListSerializer.java @@ -7,6 +7,8 @@ import com.fasterxml.jackson.databind.*; import com.fasterxml.jackson.databind.annotation.JacksonStdImpl; +import com.fasterxml.jackson.databind.jsonschema.types.SchemaType; +import com.fasterxml.jackson.databind.jsonschema.visitors.JsonArrayFormatVisitor; import com.fasterxml.jackson.databind.jsontype.TypeSerializer; import com.fasterxml.jackson.databind.ser.ContextualSerializer; import com.fasterxml.jackson.databind.ser.std.StaticListSerializerBase; @@ -44,9 +46,11 @@ public IndexedStringListSerializer(JsonSerializer ser) { } - @Override protected JsonNode contentSchema() { - return createSchemaNode("string", true); - } + @Override + protected void acceptContentVisitor(JsonArrayFormatVisitor visitor) { + visitor.itemsFormat(SchemaType.STRING); + + } /* /********************************************************** @@ -147,4 +151,5 @@ private final void serializeUsingCustom(List value, JsonGenerator jgen, wrapAndThrow(provider, e, value, i); } } + } diff --git a/src/main/java/com/fasterxml/jackson/databind/ser/impl/SimpleBeanPropertyFilter.java b/src/main/java/com/fasterxml/jackson/databind/ser/impl/SimpleBeanPropertyFilter.java index 2267207b7b..9b0d186e63 100644 --- a/src/main/java/com/fasterxml/jackson/databind/ser/impl/SimpleBeanPropertyFilter.java +++ b/src/main/java/com/fasterxml/jackson/databind/ser/impl/SimpleBeanPropertyFilter.java @@ -8,10 +8,11 @@ import com.fasterxml.jackson.databind.*; import com.fasterxml.jackson.databind.jsonschema.JsonSchema; import com.fasterxml.jackson.databind.jsonschema.SchemaAware; -import com.fasterxml.jackson.databind.jsonschema.types.Schema; +import com.fasterxml.jackson.databind.jsonschema.visitors.JsonObjectFormatVisitor; import com.fasterxml.jackson.databind.node.ObjectNode; import com.fasterxml.jackson.databind.ser.BeanPropertyFilter; import com.fasterxml.jackson.databind.ser.BeanPropertyWriter; +import com.fasterxml.jackson.databind.ser.std.BeanSerializerBase; /** * Simple {@link BeanPropertyFilter} implementation that only uses property name @@ -82,9 +83,9 @@ public void serializeAsField(Object bean, JsonGenerator jgen, } public void depositSchemaProperty(BeanPropertyWriter writer, - ObjectNode propertiesNode, SerializerProvider provider) { + JsonObjectFormatVisitor objectVisitor, SerializerProvider provider) { if (_propertiesToInclude.contains(writer.getName())) { - Schema.depositSchemaProperty(writer, propertiesNode, provider); + BeanSerializerBase.depositSchemaProperty(writer, objectVisitor); } } } @@ -114,9 +115,9 @@ public void serializeAsField(Object bean, JsonGenerator jgen, } public void depositSchemaProperty(BeanPropertyWriter writer, - ObjectNode propertiesNode, SerializerProvider provider) { + JsonObjectFormatVisitor objectVisitor, SerializerProvider provider) { if (!_propertiesToExclude.contains(writer.getName())) { - Schema.depositSchemaProperty(writer, propertiesNode, provider); + BeanSerializerBase.depositSchemaProperty(writer, objectVisitor); } } } diff --git a/src/main/java/com/fasterxml/jackson/databind/ser/impl/StringArraySerializer.java b/src/main/java/com/fasterxml/jackson/databind/ser/impl/StringArraySerializer.java index 8e69ad5b64..5050c94ff8 100644 --- a/src/main/java/com/fasterxml/jackson/databind/ser/impl/StringArraySerializer.java +++ b/src/main/java/com/fasterxml/jackson/databind/ser/impl/StringArraySerializer.java @@ -8,6 +8,8 @@ import com.fasterxml.jackson.databind.*; import com.fasterxml.jackson.databind.annotation.JacksonStdImpl; +import com.fasterxml.jackson.databind.jsonschema.types.SchemaType; +import com.fasterxml.jackson.databind.jsonschema.visitors.JsonFormatVisitor; import com.fasterxml.jackson.databind.jsontype.TypeSerializer; import com.fasterxml.jackson.databind.node.ObjectNode; import com.fasterxml.jackson.databind.ser.ContainerSerializer; @@ -169,10 +171,8 @@ private void serializeContentsSlow(String[] value, JsonGenerator jgen, Serialize } @Override - public JsonNode getSchema(SerializerProvider provider, Type typeHint) + public void acceptJsonFormatVisitor(JsonFormatVisitor visitor, Type typeHint) { - ObjectNode o = createSchemaNode("array", true); - o.put("items", createSchemaNode("string")); - return o; + visitor.arrayFormat(null).itemsFormat(SchemaType.STRING); } } diff --git a/src/main/java/com/fasterxml/jackson/databind/ser/impl/StringCollectionSerializer.java b/src/main/java/com/fasterxml/jackson/databind/ser/impl/StringCollectionSerializer.java index 3fbc406ad2..b99f41e269 100644 --- a/src/main/java/com/fasterxml/jackson/databind/ser/impl/StringCollectionSerializer.java +++ b/src/main/java/com/fasterxml/jackson/databind/ser/impl/StringCollectionSerializer.java @@ -7,6 +7,8 @@ import com.fasterxml.jackson.databind.*; import com.fasterxml.jackson.databind.annotation.JacksonStdImpl; +import com.fasterxml.jackson.databind.jsonschema.types.SchemaType; +import com.fasterxml.jackson.databind.jsonschema.visitors.JsonArrayFormatVisitor; import com.fasterxml.jackson.databind.jsontype.TypeSerializer; import com.fasterxml.jackson.databind.ser.ContextualSerializer; import com.fasterxml.jackson.databind.ser.std.StaticListSerializerBase; @@ -44,9 +46,11 @@ protected StringCollectionSerializer(JsonSerializer ser) _serializer = (JsonSerializer) ser; } - @Override protected JsonNode contentSchema() { - return createSchemaNode("string", true); - } + @Override + protected void acceptContentVisitor(JsonArrayFormatVisitor visitor) { + visitor.itemsFormat(SchemaType.STRING); + + } /* /********************************************************** diff --git a/src/main/java/com/fasterxml/jackson/databind/ser/impl/UnknownSerializer.java b/src/main/java/com/fasterxml/jackson/databind/ser/impl/UnknownSerializer.java index 392d09acb7..02fc5dc024 100644 --- a/src/main/java/com/fasterxml/jackson/databind/ser/impl/UnknownSerializer.java +++ b/src/main/java/com/fasterxml/jackson/databind/ser/impl/UnknownSerializer.java @@ -6,6 +6,7 @@ import com.fasterxml.jackson.core.*; import com.fasterxml.jackson.databind.*; +import com.fasterxml.jackson.databind.jsonschema.visitors.JsonFormatVisitor; import com.fasterxml.jackson.databind.jsontype.TypeSerializer; import com.fasterxml.jackson.databind.ser.std.StdSerializer; @@ -42,8 +43,8 @@ public final void serializeWithType(Object value, JsonGenerator jgen, Serializer } @Override - public JsonNode getSchema(SerializerProvider provider, Type typeHint) throws JsonMappingException { - return null; + public void acceptJsonFormatVisitor(JsonFormatVisitor visitor, Type typeHint) { + visitor.anyFormat(); } protected void failForEmpty(Object value) throws JsonMappingException diff --git a/src/main/java/com/fasterxml/jackson/databind/ser/std/AsArraySerializerBase.java b/src/main/java/com/fasterxml/jackson/databind/ser/std/AsArraySerializerBase.java index 813bf99fd0..505c72ea13 100644 --- a/src/main/java/com/fasterxml/jackson/databind/ser/std/AsArraySerializerBase.java +++ b/src/main/java/com/fasterxml/jackson/databind/ser/std/AsArraySerializerBase.java @@ -9,6 +9,8 @@ import com.fasterxml.jackson.databind.*; import com.fasterxml.jackson.databind.jsonschema.JsonSchema; import com.fasterxml.jackson.databind.jsonschema.SchemaAware; +import com.fasterxml.jackson.databind.jsonschema.visitors.JsonArrayFormatVisitor; +import com.fasterxml.jackson.databind.jsonschema.visitors.JsonFormatVisitor; import com.fasterxml.jackson.databind.jsontype.TypeSerializer; import com.fasterxml.jackson.databind.node.ObjectNode; import com.fasterxml.jackson.databind.ser.ContainerSerializer; @@ -166,24 +168,25 @@ protected abstract void serializeContents(T value, JsonGenerator jgen, Serialize throws IOException, JsonGenerationException; @Override - public JsonNode getSchema(SerializerProvider provider, Type typeHint) - throws JsonMappingException + public void acceptJsonFormatVisitor(JsonFormatVisitor visitor, Type typeHint) { /* 15-Jan-2010, tatu: This should probably be rewritten, given that * more information about content type is actually being explicitly * passed. So there should be less need to try to re-process that * information. */ - ObjectNode o = createSchemaNode("array", true); + //ObjectNode o = createSchemaNode("array", true); + JsonArrayFormatVisitor arrayVisitor = + visitor.arrayFormat(typeHint == null ? _elementType.getClass() : typeHint); JavaType contentType = null; if (typeHint != null) { - JavaType javaType = provider.constructType(typeHint); + JavaType javaType = visitor.getProvider().constructType(typeHint); contentType = javaType.getContentType(); if (contentType == null) { // could still be parametrized (Iterators) if (typeHint instanceof ParameterizedType) { Type[] typeArgs = ((ParameterizedType) typeHint).getActualTypeArguments(); if (typeArgs.length == 1) { - contentType = provider.constructType(typeArgs[0]); + contentType = visitor.getProvider().constructType(typeArgs[0]); } } } @@ -193,19 +196,8 @@ public JsonNode getSchema(SerializerProvider provider, Type typeHint) } if (contentType != null) { JsonNode schemaNode = null; - // 15-Oct-2010, tatu: We can't serialize plain Object.class; but what should it produce here? Untyped? - if (contentType.getRawClass() != Object.class) { - JsonSerializer ser = provider.findValueSerializer(contentType, _property); - if (ser instanceof SchemaAware) { - schemaNode = ((SchemaAware) ser).getSchema(provider, null); - } - } - if (schemaNode == null) { - schemaNode = JsonSchema.getDefaultSchemaNode(); - } - o.put("items", schemaNode); + arrayVisitor.itemsFormat(contentType); } - return o; } protected final JsonSerializer _findAndAddDynamic(PropertySerializerMap map, diff --git a/src/main/java/com/fasterxml/jackson/databind/ser/std/BeanSerializerBase.java b/src/main/java/com/fasterxml/jackson/databind/ser/std/BeanSerializerBase.java index 1a7b5bcf69..eac8280b74 100644 --- a/src/main/java/com/fasterxml/jackson/databind/ser/std/BeanSerializerBase.java +++ b/src/main/java/com/fasterxml/jackson/databind/ser/std/BeanSerializerBase.java @@ -16,13 +16,15 @@ import com.fasterxml.jackson.databind.introspect.ObjectIdInfo; import com.fasterxml.jackson.databind.jsonschema.JsonSerializableSchema; import com.fasterxml.jackson.databind.jsonschema.SchemaAware; -import com.fasterxml.jackson.databind.jsonschema.types.Schema; +import com.fasterxml.jackson.databind.jsonschema.visitors.JsonFormatVisitor; +import com.fasterxml.jackson.databind.jsonschema.visitors.JsonObjectFormatVisitor; import com.fasterxml.jackson.databind.jsontype.TypeSerializer; import com.fasterxml.jackson.databind.node.ObjectNode; import com.fasterxml.jackson.databind.ser.*; import com.fasterxml.jackson.databind.ser.impl.ObjectIdWriter; import com.fasterxml.jackson.databind.ser.impl.PropertyBasedObjectIdGenerator; import com.fasterxml.jackson.databind.ser.impl.WritableObjectId; +import com.fasterxml.jackson.databind.type.TypeFactory; import com.fasterxml.jackson.databind.util.ArrayBuilders; import com.fasterxml.jackson.databind.util.NameTransformer; @@ -625,27 +627,28 @@ protected BeanPropertyFilter findFilter(SerializerProvider provider) return filter; } - @Override - public JsonNode getSchema(SerializerProvider provider, Type typeHint) - throws JsonMappingException + public void acceptJsonFormatVisitor(JsonFormatVisitor visitor, Type typeHint) { - ObjectNode o = createSchemaNode("object", true); + JsonObjectFormatVisitor objectVisitor = visitor.objectFormat(typeHint == null ? _handledType : typeHint); // [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); - if (ann != null) { - String id = ann.id(); - if (id != null && id.length() > 0) { - o.put("id", id); - } - } +// JsonSerializableSchema ann = _handledType.getAnnotation(JsonSerializableSchema.class); +// if (ann != null) { +// String id = ann.id(); +// if (id != null && id.length() > 0) { +// //o.put("id", id); what is this? +// //objectVisitor.expect?? +// } +// } - //todo: should the classname go in the title? - //o.put("title", _className); - ObjectNode propertiesNode = o.objectNode(); - final BeanPropertyFilter filter; + BeanPropertyFilter filter; if (_propertyFilterId != null) { - filter = findFilter(provider); + try { + filter = findFilter(visitor.getProvider()); + } catch (JsonMappingException e) { + // TODO Auto-generated catch block + filter = null; + } } else { filter = null; } @@ -653,19 +656,30 @@ public JsonNode getSchema(SerializerProvider provider, Type typeHint) for (int i = 0; i < _props.length; i++) { BeanPropertyWriter prop = _props[i]; if (filter != null) { - filter.depositSchemaProperty(prop, propertiesNode, provider); + filter.depositSchemaProperty(prop, objectVisitor, visitor.getProvider()); continue; } JavaType propType = prop.getSerializationType(); - - Schema.depositSchemaProperty(prop, propertiesNode, provider); - + BeanSerializerBase.depositSchemaProperty(prop, objectVisitor); } - o.put("properties", propertiesNode); - return o; } /** + * Attempt to add the output of the given {@link BeanPropertyWriter} in the given {@link ObjectNode}. + * Otherwise, add the default schema {@link JsonNode} in place of the writer's output + * + * @param writer Bean property serializer to use to create schema value + * @param propertiesNode Node which the given property would exist within + */ + public static void depositSchemaProperty(BeanPropertyWriter writer, JsonObjectFormatVisitor objectVisitor) { + if (isPropertyRequired(writer, objectVisitor.getProvider())) { + objectVisitor.property(writer); + } else { + objectVisitor.optionalProperty(writer); + } + } + + /** * Determines if a bean property is required, as determined by * {@link com.fasterxml.jackson.databind.AnnotationIntrospector#hasRequiredMarker}. *

diff --git a/src/main/java/com/fasterxml/jackson/databind/ser/std/BooleanSerializer.java b/src/main/java/com/fasterxml/jackson/databind/ser/std/BooleanSerializer.java index 56c456fd6d..6bd3be5288 100644 --- a/src/main/java/com/fasterxml/jackson/databind/ser/std/BooleanSerializer.java +++ b/src/main/java/com/fasterxml/jackson/databind/ser/std/BooleanSerializer.java @@ -9,6 +9,7 @@ import com.fasterxml.jackson.databind.JsonNode; import com.fasterxml.jackson.databind.SerializerProvider; import com.fasterxml.jackson.databind.annotation.JacksonStdImpl; +import com.fasterxml.jackson.databind.jsonschema.visitors.JsonFormatVisitor; /** * Serializer used for primitive boolean, as well as java.util.Boolean @@ -41,8 +42,8 @@ public void serialize(Boolean value, JsonGenerator jgen, SerializerProvider prov } @Override - public JsonNode getSchema(SerializerProvider provider, Type typeHint) + public void acceptJsonFormatVisitor(JsonFormatVisitor visitor, Type typeHint) { - return createSchemaNode("boolean", !_forPrimitive); + visitor.booleanFormat(); } } \ No newline at end of file diff --git a/src/main/java/com/fasterxml/jackson/databind/ser/std/DateTimeSerializerBase.java b/src/main/java/com/fasterxml/jackson/databind/ser/std/DateTimeSerializerBase.java index 59a2d5e650..79b5dacdf3 100644 --- a/src/main/java/com/fasterxml/jackson/databind/ser/std/DateTimeSerializerBase.java +++ b/src/main/java/com/fasterxml/jackson/databind/ser/std/DateTimeSerializerBase.java @@ -12,6 +12,8 @@ import com.fasterxml.jackson.core.JsonGenerator; import com.fasterxml.jackson.databind.*; import com.fasterxml.jackson.databind.introspect.Annotated; +import com.fasterxml.jackson.databind.jsonschema.types.JsonValueFormat; +import com.fasterxml.jackson.databind.jsonschema.visitors.JsonFormatVisitor; import com.fasterxml.jackson.databind.ser.ContextualSerializer; import com.fasterxml.jackson.databind.util.StdDateFormat; @@ -100,17 +102,20 @@ public boolean isEmpty(T value) { protected abstract long _timestamp(T value); - @Override - public JsonNode getSchema(SerializerProvider provider, Type typeHint) + public void acceptJsonFormatVisitor(JsonFormatVisitor visitor, Type typeHint) { //todo: (ryan) add a format for the date in the schema? boolean asNumber = _useTimestamp; if (!asNumber) { if (_customFormat == null) { - asNumber = provider.isEnabled(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS); + asNumber = visitor.getProvider().isEnabled(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS); } } - return createSchemaNode(asNumber ? "number" : "string", true); + if (asNumber) { + visitor.numberFormat().format(JsonValueFormat.UTC_MILLISEC); + } else { + visitor.stringFormat().format(JsonValueFormat.DATE_TIME); + } } /* diff --git a/src/main/java/com/fasterxml/jackson/databind/ser/std/EnumMapSerializer.java b/src/main/java/com/fasterxml/jackson/databind/ser/std/EnumMapSerializer.java index faf39db6ee..b65a75da1a 100644 --- a/src/main/java/com/fasterxml/jackson/databind/ser/std/EnumMapSerializer.java +++ b/src/main/java/com/fasterxml/jackson/databind/ser/std/EnumMapSerializer.java @@ -12,6 +12,8 @@ import com.fasterxml.jackson.databind.annotation.JacksonStdImpl; import com.fasterxml.jackson.databind.jsonschema.JsonSchema; import com.fasterxml.jackson.databind.jsonschema.SchemaAware; +import com.fasterxml.jackson.databind.jsonschema.visitors.JsonFormatVisitor; +import com.fasterxml.jackson.databind.jsonschema.visitors.JsonObjectFormatVisitor; import com.fasterxml.jackson.databind.jsontype.TypeSerializer; import com.fasterxml.jackson.databind.node.JsonNodeFactory; import com.fasterxml.jackson.databind.node.ObjectNode; @@ -250,27 +252,31 @@ protected void serializeContentsUsing(EnumMap,?> value, JsonGe @SuppressWarnings("unchecked") @Override - public JsonNode getSchema(SerializerProvider provider, Type typeHint) - throws JsonMappingException + public void acceptJsonFormatVisitor(JsonFormatVisitor visitor, Type typeHint) { - ObjectNode o = createSchemaNode("object", true); + JsonObjectFormatVisitor objectVisitor = visitor.objectFormat(typeHint); if (typeHint instanceof ParameterizedType) { Type[] typeArgs = ((ParameterizedType) typeHint).getActualTypeArguments(); if (typeArgs.length == 2) { - JavaType enumType = provider.constructType(typeArgs[0]); - JavaType valueType = provider.constructType(typeArgs[1]); + JavaType enumType = visitor.getProvider().constructType(typeArgs[0]); + JavaType valueType = visitor.getProvider().constructType(typeArgs[1]); ObjectNode propsNode = JsonNodeFactory.instance.objectNode(); Class> enumClass = (Class>) enumType.getRawClass(); for (Enum enumValue : enumClass.getEnumConstants()) { - JsonSerializer ser = provider.findValueSerializer(valueType.getRawClass(), _property); - JsonNode schemaNode = (ser instanceof SchemaAware) ? - ((SchemaAware) ser).getSchema(provider, null) : - JsonSchema.getDefaultSchemaNode(); - propsNode.put(provider.getConfig().getAnnotationIntrospector().findEnumValue((Enum)enumValue), schemaNode); + JsonSerializer ser; + String name = visitor.getProvider().getConfig().getAnnotationIntrospector().findEnumValue((Enum)enumValue); + try { + ser = visitor.getProvider().findValueSerializer(valueType.getRawClass(), _property); + if (ser instanceof SchemaAware) { + objectVisitor.property(name, (SchemaAware) ser, typeArgs[1]); + } + continue; + } catch (JsonMappingException e) { + //TODO: log error + } + objectVisitor.property(name); } - o.put("properties", propsNode); } } - return o; } } diff --git a/src/main/java/com/fasterxml/jackson/databind/ser/std/EnumSerializer.java b/src/main/java/com/fasterxml/jackson/databind/ser/std/EnumSerializer.java index 71321f7b01..1da790eca4 100644 --- a/src/main/java/com/fasterxml/jackson/databind/ser/std/EnumSerializer.java +++ b/src/main/java/com/fasterxml/jackson/databind/ser/std/EnumSerializer.java @@ -2,6 +2,8 @@ import java.io.IOException; import java.lang.reflect.Type; +import java.util.HashSet; +import java.util.Set; import com.fasterxml.jackson.core.*; import com.fasterxml.jackson.core.io.SerializedString; @@ -9,6 +11,9 @@ import com.fasterxml.jackson.databind.*; import com.fasterxml.jackson.databind.annotation.JacksonStdImpl; +import com.fasterxml.jackson.databind.jsonschema.visitors.JsonFormatVisitor; +import com.fasterxml.jackson.databind.jsonschema.visitors.JsonObjectFormatVisitor; +import com.fasterxml.jackson.databind.jsonschema.visitors.JsonStringFormatVisitor; import com.fasterxml.jackson.databind.node.ArrayNode; import com.fasterxml.jackson.databind.node.ObjectNode; import com.fasterxml.jackson.databind.util.EnumValues; @@ -60,23 +65,24 @@ public final void serialize(Enum en, JsonGenerator jgen, SerializerProvider p } @Override - public JsonNode getSchema(SerializerProvider provider, Type typeHint) + public void acceptJsonFormatVisitor(JsonFormatVisitor visitor, Type typeHint) { // [JACKSON-684]: serialize as index? - if (provider.isEnabled(SerializationFeature.WRITE_ENUMS_USING_INDEX)) { - return createSchemaNode("integer", true); - } - ObjectNode objectNode = createSchemaNode("string", true); - if (typeHint != null) { - JavaType type = provider.constructType(typeHint); - if (type.isEnumType()) { - ArrayNode enumNode = objectNode.putArray("enum"); - for (SerializedString value : _values.values()) { - enumNode.add(value.getValue()); - } - } - } - return objectNode; + if (visitor.getProvider().isEnabled(SerializationFeature.WRITE_ENUMS_USING_INDEX)) { + visitor.integerFormat(); + } else { + JsonStringFormatVisitor stringVisitor = visitor.stringFormat(); + if (typeHint != null) { + JavaType type = visitor.getProvider().constructType(typeHint); + if (type.isEnumType()) { + Set enums = new HashSet(); + for (SerializedString value : _values.values()) { + enums.add(value.getValue()); + } + stringVisitor.enumTypes(enums); + } + } + } } public EnumValues getEnumValues() { return _values; } diff --git a/src/main/java/com/fasterxml/jackson/databind/ser/std/JsonValueSerializer.java b/src/main/java/com/fasterxml/jackson/databind/ser/std/JsonValueSerializer.java index 364957a53e..d2cf606508 100644 --- a/src/main/java/com/fasterxml/jackson/databind/ser/std/JsonValueSerializer.java +++ b/src/main/java/com/fasterxml/jackson/databind/ser/std/JsonValueSerializer.java @@ -12,6 +12,7 @@ import com.fasterxml.jackson.databind.annotation.JacksonStdImpl; import com.fasterxml.jackson.databind.jsonschema.JsonSchema; import com.fasterxml.jackson.databind.jsonschema.SchemaAware; +import com.fasterxml.jackson.databind.jsonschema.visitors.JsonFormatVisitor; import com.fasterxml.jackson.databind.jsontype.TypeSerializer; import com.fasterxml.jackson.databind.ser.BeanSerializer; import com.fasterxml.jackson.databind.ser.ContextualSerializer; @@ -230,12 +231,13 @@ public void serializeWithType(Object bean, JsonGenerator jgen, SerializerProvide } @Override - public JsonNode getSchema(SerializerProvider provider, Type typeHint) - throws JsonMappingException + public void acceptJsonFormatVisitor(JsonFormatVisitor visitor, Type typeHint) { - return (_valueSerializer instanceof SchemaAware) ? - ((SchemaAware) _valueSerializer).getSchema(provider, null) : - JsonSchema.getDefaultSchemaNode(); + if (_valueSerializer instanceof SchemaAware) { + ((SchemaAware) _valueSerializer).acceptJsonFormatVisitor(visitor, null); + } else { + visitor.anyFormat(); + } } protected boolean isNaturalTypeWithStdHandling(Class rawType, JsonSerializer ser) diff --git a/src/main/java/com/fasterxml/jackson/databind/ser/std/MapSerializer.java b/src/main/java/com/fasterxml/jackson/databind/ser/std/MapSerializer.java index 127d4a373d..61f69ae2a8 100644 --- a/src/main/java/com/fasterxml/jackson/databind/ser/std/MapSerializer.java +++ b/src/main/java/com/fasterxml/jackson/databind/ser/std/MapSerializer.java @@ -9,6 +9,7 @@ import com.fasterxml.jackson.databind.*; import com.fasterxml.jackson.databind.annotation.JacksonStdImpl; +import com.fasterxml.jackson.databind.jsonschema.visitors.JsonFormatVisitor; import com.fasterxml.jackson.databind.jsontype.TypeSerializer; import com.fasterxml.jackson.databind.node.ObjectNode; import com.fasterxml.jackson.databind.ser.ContainerSerializer; @@ -466,12 +467,9 @@ protected void serializeTypedFields(Map value, JsonGenerator jgen, Serializ } @Override - public JsonNode getSchema(SerializerProvider provider, Type typeHint) + public void acceptJsonFormatVisitor(JsonFormatVisitor visitor, Type typeHint) { - ObjectNode o = createSchemaNode("object", true); - //(ryan) even though it's possible to statically determine the "value" type of the map, - // there's no way to statically determine the keys, so the "Entries" can't be determined. - return o; + visitor.objectFormat(null); } /* diff --git a/src/main/java/com/fasterxml/jackson/databind/ser/std/NullSerializer.java b/src/main/java/com/fasterxml/jackson/databind/ser/std/NullSerializer.java index 75fcc0bc09..200ab48730 100644 --- a/src/main/java/com/fasterxml/jackson/databind/ser/std/NullSerializer.java +++ b/src/main/java/com/fasterxml/jackson/databind/ser/std/NullSerializer.java @@ -7,6 +7,7 @@ import com.fasterxml.jackson.databind.*; import com.fasterxml.jackson.databind.annotation.JacksonStdImpl; +import com.fasterxml.jackson.databind.jsonschema.visitors.JsonFormatVisitor; /** * This is a simple dummy serializer that will just output literal @@ -31,9 +32,8 @@ public void serialize(Object value, JsonGenerator jgen, SerializerProvider provi } @Override - public JsonNode getSchema(SerializerProvider provider, Type typeHint) - throws JsonMappingException + public void acceptJsonFormatVisitor(JsonFormatVisitor visitor, Type typeHint) { - return createSchemaNode("null"); + visitor.nullFormat(); } } diff --git a/src/main/java/com/fasterxml/jackson/databind/ser/std/NumberSerializers.java b/src/main/java/com/fasterxml/jackson/databind/ser/std/NumberSerializers.java index 81d0bbb1eb..4e6f506e20 100644 --- a/src/main/java/com/fasterxml/jackson/databind/ser/std/NumberSerializers.java +++ b/src/main/java/com/fasterxml/jackson/databind/ser/std/NumberSerializers.java @@ -9,6 +9,7 @@ import com.fasterxml.jackson.core.*; import com.fasterxml.jackson.databind.*; import com.fasterxml.jackson.databind.annotation.JacksonStdImpl; +import com.fasterxml.jackson.databind.jsonschema.visitors.JsonFormatVisitor; /** * Container class for serializers used for handling standard JDK-provided types. @@ -71,9 +72,9 @@ public void serialize(Integer value, JsonGenerator jgen, SerializerProvider prov } @Override - public JsonNode getSchema(SerializerProvider provider, Type typeHint) + public void acceptJsonFormatVisitor(JsonFormatVisitor visitor, Type typeHint) { - return createSchemaNode("integer", true); + visitor.integerFormat(); } } @@ -98,9 +99,9 @@ public void serialize(Number value, JsonGenerator jgen, SerializerProvider provi } @Override - public JsonNode getSchema(SerializerProvider provider, Type typeHint) + public void acceptJsonFormatVisitor(JsonFormatVisitor visitor, Type typeHint) { - return createSchemaNode("integer", true); + visitor.integerFormat(); } } @@ -120,9 +121,9 @@ public void serialize(Long value, JsonGenerator jgen, SerializerProvider provide } @Override - public JsonNode getSchema(SerializerProvider provider, Type typeHint) + public void acceptJsonFormatVisitor(JsonFormatVisitor visitor, Type typeHint) { - return createSchemaNode("number", true); + visitor.numberFormat(); } } @@ -142,9 +143,9 @@ public void serialize(Float value, JsonGenerator jgen, SerializerProvider provid } @Override - public JsonNode getSchema(SerializerProvider provider, Type typeHint) + public void acceptJsonFormatVisitor(JsonFormatVisitor visitor, Type typeHint) { - return createSchemaNode("number", true); + visitor.numberFormat(); } } @@ -171,9 +172,9 @@ public void serialize(Double value, JsonGenerator jgen, SerializerProvider provi } @Override - public JsonNode getSchema(SerializerProvider provider, Type typeHint) + public void acceptJsonFormatVisitor(JsonFormatVisitor visitor, Type typeHint) { - return createSchemaNode("number", true); + visitor.numberFormat(); } } @@ -219,9 +220,9 @@ public void serialize(Number value, JsonGenerator jgen, SerializerProvider provi } @Override - public JsonNode getSchema(SerializerProvider provider, Type typeHint) + public void acceptJsonFormatVisitor(JsonFormatVisitor visitor, Type typeHint) { - return createSchemaNode("number", true); + visitor.numberFormat(); } } } diff --git a/src/main/java/com/fasterxml/jackson/databind/ser/std/ObjectArraySerializer.java b/src/main/java/com/fasterxml/jackson/databind/ser/std/ObjectArraySerializer.java index 29b301c0a7..dc213071aa 100644 --- a/src/main/java/com/fasterxml/jackson/databind/ser/std/ObjectArraySerializer.java +++ b/src/main/java/com/fasterxml/jackson/databind/ser/std/ObjectArraySerializer.java @@ -10,6 +10,8 @@ import com.fasterxml.jackson.databind.annotation.JacksonStdImpl; import com.fasterxml.jackson.databind.jsonschema.JsonSchema; import com.fasterxml.jackson.databind.jsonschema.SchemaAware; +import com.fasterxml.jackson.databind.jsonschema.visitors.JsonArrayFormatVisitor; +import com.fasterxml.jackson.databind.jsonschema.visitors.JsonFormatVisitor; import com.fasterxml.jackson.databind.jsontype.TypeSerializer; import com.fasterxml.jackson.databind.node.ObjectNode; import com.fasterxml.jackson.databind.ser.ContainerSerializer; @@ -295,27 +297,9 @@ public void serializeTypedContents(Object[] value, JsonGenerator jgen, Serialize } @Override - public JsonNode getSchema(SerializerProvider provider, Type typeHint) - throws JsonMappingException + public void acceptJsonFormatVisitor(JsonFormatVisitor visitor, Type typeHint) { - ObjectNode o = createSchemaNode("array", true); - if (typeHint != null) { - JavaType javaType = provider.constructType(typeHint); - if (javaType.isArrayType()) { - Class componentType = ((ArrayType) javaType).getContentType().getRawClass(); - // 15-Oct-2010, tatu: We can't serialize plain Object.class; but what should it produce here? Untyped? - if (componentType == Object.class) { - o.put("items", JsonSchema.getDefaultSchemaNode()); - } else { - JsonSerializer ser = provider.findValueSerializer(componentType, _property); - JsonNode schemaNode = (ser instanceof SchemaAware) ? - ((SchemaAware) ser).getSchema(provider, null) : - JsonSchema.getDefaultSchemaNode(); - o.put("items", schemaNode); - } - } - } - return o; + visitor.arrayFormat(typeHint == null ? _property.getType().getRawClass() : typeHint).itemsFormat(_elementType); } protected final JsonSerializer _findAndAddDynamic(PropertySerializerMap map, diff --git a/src/main/java/com/fasterxml/jackson/databind/ser/std/RawSerializer.java b/src/main/java/com/fasterxml/jackson/databind/ser/std/RawSerializer.java index 75af722333..2924f892c3 100644 --- a/src/main/java/com/fasterxml/jackson/databind/ser/std/RawSerializer.java +++ b/src/main/java/com/fasterxml/jackson/databind/ser/std/RawSerializer.java @@ -1,12 +1,13 @@ package com.fasterxml.jackson.databind.ser.std; -import java.lang.reflect.Type; import java.io.IOException; +import java.lang.reflect.Type; import com.fasterxml.jackson.core.*; import com.fasterxml.jackson.databind.*; import com.fasterxml.jackson.databind.annotation.JacksonStdImpl; +import com.fasterxml.jackson.databind.jsonschema.visitors.JsonFormatVisitor; import com.fasterxml.jackson.databind.jsontype.TypeSerializer; /** @@ -44,9 +45,8 @@ public void serializeWithType(T value, JsonGenerator jgen, SerializerProvider pr } @Override - public JsonNode getSchema(SerializerProvider provider, Type typeHint) + public void acceptJsonFormatVisitor(JsonFormatVisitor visitor, Type typeHint) { - // type not really known, but since it is a JSON string: - return createSchemaNode("string", true); + visitor.stringFormat(); } } diff --git a/src/main/java/com/fasterxml/jackson/databind/ser/std/SerializableSerializer.java b/src/main/java/com/fasterxml/jackson/databind/ser/std/SerializableSerializer.java index d1c2633fb1..aafe96be0f 100644 --- a/src/main/java/com/fasterxml/jackson/databind/ser/std/SerializableSerializer.java +++ b/src/main/java/com/fasterxml/jackson/databind/ser/std/SerializableSerializer.java @@ -14,6 +14,10 @@ import com.fasterxml.jackson.databind.SerializerProvider; import com.fasterxml.jackson.databind.annotation.JacksonStdImpl; import com.fasterxml.jackson.databind.jsonschema.JsonSerializableSchema; +import com.fasterxml.jackson.databind.jsonschema.types.Schema; +import com.fasterxml.jackson.databind.jsonschema.types.SchemaType; +import com.fasterxml.jackson.databind.jsonschema.visitors.JsonFormatVisitor; +import com.fasterxml.jackson.databind.jsonschema.visitors.JsonObjectFormatVisitor; import com.fasterxml.jackson.databind.jsontype.TypeSerializer; import com.fasterxml.jackson.databind.node.ObjectNode; import com.fasterxml.jackson.databind.type.TypeFactory; @@ -51,47 +55,49 @@ public final void serializeWithType(JsonSerializable value, JsonGenerator jgen, } @Override - public JsonNode getSchema(SerializerProvider provider, Type typeHint) - throws JsonMappingException + public void acceptJsonFormatVisitor(JsonFormatVisitor visitor, Type typeHint) { - ObjectNode objectNode = createObjectNode(); - String schemaType = "any"; - String objectProperties = null; - String itemDefinition = null; - if (typeHint != null) { + if (typeHint == null) { + visitor.anyFormat(); + } else { Class rawClass = TypeFactory.rawClass(typeHint); if (rawClass.isAnnotationPresent(JsonSerializableSchema.class)) { JsonSerializableSchema schemaInfo = rawClass.getAnnotation(JsonSerializableSchema.class); - schemaType = schemaInfo.schemaType(); + if (!JsonSerializableSchema.NO_VALUE.equals(schemaInfo.schemaObjectPropertiesDefinition())) { - objectProperties = schemaInfo.schemaObjectPropertiesDefinition(); - } + visitor.objectFormat(rawClass); + //objectProperties = schemaInfo.schemaObjectPropertiesDefinition(); + } else if (!JsonSerializableSchema.NO_VALUE.equals(schemaInfo.schemaItemDefinition())) { - itemDefinition = schemaInfo.schemaItemDefinition(); + visitor.arrayFormat(rawClass); + //itemDefinition = schemaInfo.schemaItemDefinition(); + } else { + visitor.anyFormat(); + //visitor.forFormat(SchemaType.valueOf(schemaInfo.schemaType())); } + } else { + visitor.anyFormat(); } - } + } /* 19-Mar-2012, tatu: geez, this is butt-ugly abonimation of code... * really, really should not require back ref to an ObjectMapper. */ - objectNode.put("type", schemaType); - if (objectProperties != null) { - try { - objectNode.put("properties", _getObjectMapper().readTree(objectProperties)); - } catch (IOException e) { - throw new JsonMappingException("Failed to parse @JsonSerializableSchema.schemaObjectPropertiesDefinition value"); - } - } - if (itemDefinition != null) { - try { - objectNode.put("items", _getObjectMapper().readTree(itemDefinition)); - } catch (IOException e) { - throw new JsonMappingException("Failed to parse @JsonSerializableSchema.schemaItemDefinition value"); - } - } - // always optional, no need to specify: - //objectNode.put("required", false); - return objectNode; +// objectNode.put("type", schemaType); +// if (objectProperties != null) { +// try { +// objectNode.put("properties", _getObjectMapper().readTree(objectProperties)); +// } catch (IOException e) { +// throw new JsonMappingException("Failed to parse @JsonSerializableSchema.schemaObjectPropertiesDefinition value"); +// } +// } +// if (itemDefinition != null) { +// try { +// objectNode.put("items", _getObjectMapper().readTree(itemDefinition)); +// } catch (IOException e) { +// throw new JsonMappingException("Failed to parse @JsonSerializableSchema.schemaItemDefinition value"); +// } +// } + } private final static synchronized ObjectMapper _getObjectMapper() diff --git a/src/main/java/com/fasterxml/jackson/databind/ser/std/SqlDateSerializer.java b/src/main/java/com/fasterxml/jackson/databind/ser/std/SqlDateSerializer.java index a5d6fb56cd..6dbdb1d406 100644 --- a/src/main/java/com/fasterxml/jackson/databind/ser/std/SqlDateSerializer.java +++ b/src/main/java/com/fasterxml/jackson/databind/ser/std/SqlDateSerializer.java @@ -9,6 +9,8 @@ import com.fasterxml.jackson.databind.JsonNode; import com.fasterxml.jackson.databind.SerializerProvider; import com.fasterxml.jackson.databind.annotation.JacksonStdImpl; +import com.fasterxml.jackson.databind.jsonschema.types.JsonValueFormat; +import com.fasterxml.jackson.databind.jsonschema.visitors.JsonFormatVisitor; /** * Compared to regular {@link java.util.Date} serialization, we do use String @@ -29,9 +31,8 @@ public void serialize(java.sql.Date value, JsonGenerator jgen, SerializerProvide } @Override - public JsonNode getSchema(SerializerProvider provider, Type typeHint) + public void acceptJsonFormatVisitor(JsonFormatVisitor visitor, Type typeHint) { - //todo: (ryan) add a format for the date in the schema? - return createSchemaNode("string", true); + visitor.stringFormat().format(JsonValueFormat.DATE_TIME); } } \ No newline at end of file diff --git a/src/main/java/com/fasterxml/jackson/databind/ser/std/SqlTimeSerializer.java b/src/main/java/com/fasterxml/jackson/databind/ser/std/SqlTimeSerializer.java index 8e12b425be..7efd7c1867 100644 --- a/src/main/java/com/fasterxml/jackson/databind/ser/std/SqlTimeSerializer.java +++ b/src/main/java/com/fasterxml/jackson/databind/ser/std/SqlTimeSerializer.java @@ -9,6 +9,8 @@ import com.fasterxml.jackson.databind.JsonNode; import com.fasterxml.jackson.databind.SerializerProvider; import com.fasterxml.jackson.databind.annotation.JacksonStdImpl; +import com.fasterxml.jackson.databind.jsonschema.types.JsonValueFormat; +import com.fasterxml.jackson.databind.jsonschema.visitors.JsonFormatVisitor; @JacksonStdImpl public class SqlTimeSerializer @@ -24,8 +26,8 @@ public void serialize(java.sql.Time value, JsonGenerator jgen, SerializerProvide } @Override - public JsonNode getSchema(SerializerProvider provider, Type typeHint) + public void acceptJsonFormatVisitor(JsonFormatVisitor visitor, Type typeHint) { - return createSchemaNode("string", true); + visitor.stringFormat().format(JsonValueFormat.DATE_TIME); } } \ No newline at end of file diff --git a/src/main/java/com/fasterxml/jackson/databind/ser/std/StaticListSerializerBase.java b/src/main/java/com/fasterxml/jackson/databind/ser/std/StaticListSerializerBase.java index fece1eb39b..313340b508 100644 --- a/src/main/java/com/fasterxml/jackson/databind/ser/std/StaticListSerializerBase.java +++ b/src/main/java/com/fasterxml/jackson/databind/ser/std/StaticListSerializerBase.java @@ -5,6 +5,9 @@ import com.fasterxml.jackson.databind.JsonNode; import com.fasterxml.jackson.databind.SerializerProvider; +import com.fasterxml.jackson.databind.jsonschema.SchemaAware; +import com.fasterxml.jackson.databind.jsonschema.visitors.JsonArrayFormatVisitor; +import com.fasterxml.jackson.databind.jsonschema.visitors.JsonFormatVisitor; import com.fasterxml.jackson.databind.node.ObjectNode; /** @@ -24,11 +27,9 @@ public boolean isEmpty(T value) { } @Override - public JsonNode getSchema(SerializerProvider provider, Type typeHint) + public void acceptJsonFormatVisitor(JsonFormatVisitor visitor, Type typeHint) { - ObjectNode o = createSchemaNode("array", true); - o.put("items", contentSchema()); - return o; + acceptContentVisitor(visitor.arrayFormat(typeHint)); } /* @@ -37,5 +38,5 @@ public JsonNode getSchema(SerializerProvider provider, Type typeHint) /********************************************************** */ - protected abstract JsonNode contentSchema(); + protected abstract void acceptContentVisitor(JsonArrayFormatVisitor visitor); } diff --git a/src/main/java/com/fasterxml/jackson/databind/ser/std/StdArraySerializers.java b/src/main/java/com/fasterxml/jackson/databind/ser/std/StdArraySerializers.java index c89cf48c97..d9d90e7486 100644 --- a/src/main/java/com/fasterxml/jackson/databind/ser/std/StdArraySerializers.java +++ b/src/main/java/com/fasterxml/jackson/databind/ser/std/StdArraySerializers.java @@ -8,6 +8,8 @@ import com.fasterxml.jackson.databind.*; import com.fasterxml.jackson.databind.annotation.JacksonStdImpl; +import com.fasterxml.jackson.databind.jsonschema.types.SchemaType; +import com.fasterxml.jackson.databind.jsonschema.visitors.JsonFormatVisitor; import com.fasterxml.jackson.databind.jsontype.TypeSerializer; import com.fasterxml.jackson.databind.node.ObjectNode; import com.fasterxml.jackson.databind.ser.ContainerSerializer; @@ -129,11 +131,9 @@ public void serializeContents(boolean[] value, JsonGenerator jgen, SerializerPro } @Override - public JsonNode getSchema(SerializerProvider provider, Type typeHint) + public void acceptJsonFormatVisitor(JsonFormatVisitor visitor, Type typeHint) { - ObjectNode o = createSchemaNode("array", true); - o.put("items", createSchemaNode("boolean")); - return o; + visitor.arrayFormat(typeHint == null ? _handledType : typeHint).itemsFormat(SchemaType.BOOLEAN); } } @@ -175,12 +175,9 @@ public void serializeWithType(byte[] value, JsonGenerator jgen, SerializerProvid } @Override - public JsonNode getSchema(SerializerProvider provider, Type typeHint) + public void acceptJsonFormatVisitor(JsonFormatVisitor visitor, Type typeHint) { - ObjectNode o = createSchemaNode("array", true); - ObjectNode itemSchema = createSchemaNode("string"); //binary values written as strings? - o.put("items", itemSchema); - return o; + visitor.arrayFormat(typeHint == null ? _handledType : typeHint).itemsFormat(SchemaType.STRING); } } @@ -241,12 +238,9 @@ public void serializeContents(short[] value, JsonGenerator jgen, SerializerProvi } @Override - public JsonNode getSchema(SerializerProvider provider, Type typeHint) + public void acceptJsonFormatVisitor(JsonFormatVisitor visitor, Type typeHint) { - //no "short" type defined by json - ObjectNode o = createSchemaNode("array", true); - o.put("items", createSchemaNode("integer")); - return o; + visitor.arrayFormat(typeHint == null ? _handledType : typeHint).itemsFormat(SchemaType.INTEGER); } } @@ -308,13 +302,9 @@ private final void _writeArrayContents(JsonGenerator jgen, char[] value) } @Override - public JsonNode getSchema(SerializerProvider provider, Type typeHint) + public void acceptJsonFormatVisitor(JsonFormatVisitor visitor, Type typeHint) { - ObjectNode o = createSchemaNode("array", true); - ObjectNode itemSchema = createSchemaNode("string"); - itemSchema.put("type", "string"); - o.put("items", itemSchema); - return o; + visitor.arrayFormat(typeHint == null ? _handledType : typeHint).itemsFormat(SchemaType.STRING); } } @@ -367,11 +357,9 @@ public void serializeContents(int[] value, JsonGenerator jgen, SerializerProvide } @Override - public JsonNode getSchema(SerializerProvider provider, Type typeHint) + public void acceptJsonFormatVisitor(JsonFormatVisitor visitor, Type typeHint) { - ObjectNode o = createSchemaNode("array", true); - o.put("items", createSchemaNode("integer")); - return o; + visitor.arrayFormat(typeHint == null ? _handledType : typeHint).itemsFormat(SchemaType.INTEGER); } } @@ -433,11 +421,9 @@ public void serializeContents(long[] value, JsonGenerator jgen, SerializerProvid } @Override - public JsonNode getSchema(SerializerProvider provider, Type typeHint) + public void acceptJsonFormatVisitor(JsonFormatVisitor visitor, Type typeHint) { - ObjectNode o = createSchemaNode("array", true); - o.put("items", createSchemaNode("number", true)); - return o; + visitor.arrayFormat(typeHint == null ? _handledType : typeHint).itemsFormat(SchemaType.NUMBER); } } @@ -500,11 +486,9 @@ public void serializeContents(float[] value, JsonGenerator jgen, SerializerProvi } @Override - public JsonNode getSchema(SerializerProvider provider, Type typeHint) + public void acceptJsonFormatVisitor(JsonFormatVisitor visitor, Type typeHint) { - ObjectNode o = createSchemaNode("array", true); - o.put("items", createSchemaNode("number")); - return o; + visitor.arrayFormat(typeHint == null ? _handledType : typeHint).itemsFormat(SchemaType.NUMBER); } } @@ -557,11 +541,9 @@ public void serializeContents(double[] value, JsonGenerator jgen, SerializerProv } @Override - public JsonNode getSchema(SerializerProvider provider, Type typeHint) + public void acceptJsonFormatVisitor(JsonFormatVisitor visitor, Type typeHint) { - ObjectNode o = createSchemaNode("array", true); - o.put("items", createSchemaNode("number")); - return o; + visitor.arrayFormat(typeHint == null ? _handledType : typeHint).itemsFormat(SchemaType.NUMBER); } } } diff --git a/src/main/java/com/fasterxml/jackson/databind/ser/std/StdJdkSerializers.java b/src/main/java/com/fasterxml/jackson/databind/ser/std/StdJdkSerializers.java index 0f2a52080f..3859f41eac 100644 --- a/src/main/java/com/fasterxml/jackson/databind/ser/std/StdJdkSerializers.java +++ b/src/main/java/com/fasterxml/jackson/databind/ser/std/StdJdkSerializers.java @@ -8,6 +8,7 @@ import com.fasterxml.jackson.core.*; import com.fasterxml.jackson.databind.*; +import com.fasterxml.jackson.databind.jsonschema.visitors.JsonFormatVisitor; import com.fasterxml.jackson.databind.ser.BasicSerializerFactory; import com.fasterxml.jackson.databind.util.Provider; @@ -77,9 +78,9 @@ public void serialize(AtomicBoolean value, JsonGenerator jgen, SerializerProvide } @Override - public JsonNode getSchema(SerializerProvider provider, Type typeHint) + public void acceptJsonFormatVisitor(JsonFormatVisitor visitor, Type typeHint) { - return createSchemaNode("boolean", true); + visitor.booleanFormat(); } } @@ -96,9 +97,9 @@ public void serialize(AtomicInteger value, JsonGenerator jgen, SerializerProvide } @Override - public JsonNode getSchema(SerializerProvider provider, Type typeHint) + public void acceptJsonFormatVisitor(JsonFormatVisitor visitor, Type typeHint) { - return createSchemaNode("integer", true); + visitor.integerFormat(); } } @@ -115,9 +116,9 @@ public void serialize(AtomicLong value, JsonGenerator jgen, SerializerProvider p } @Override - public JsonNode getSchema(SerializerProvider provider, Type typeHint) + public void acceptJsonFormatVisitor(JsonFormatVisitor visitor, Type typeHint) { - return createSchemaNode("integer", true); + visitor.integerFormat(); } } @@ -134,9 +135,9 @@ public void serialize(AtomicReference value, JsonGenerator jgen, SerializerPr } @Override - public JsonNode getSchema(SerializerProvider provider, Type typeHint) + public void acceptJsonFormatVisitor(JsonFormatVisitor visitor, Type typeHint) { - return createSchemaNode("any", true); + visitor.anyFormat(); } } @@ -163,9 +164,9 @@ public void serialize(File value, JsonGenerator jgen, SerializerProvider provide } @Override - public JsonNode getSchema(SerializerProvider provider, Type typeHint) + public void acceptJsonFormatVisitor(JsonFormatVisitor visitor, Type typeHint) { - return createSchemaNode("string", true); + visitor.stringFormat(); } } @@ -186,9 +187,9 @@ public void serialize(Class value, JsonGenerator jgen, SerializerProvider pro } @Override - public JsonNode getSchema(SerializerProvider provider, Type typeHint) + public void acceptJsonFormatVisitor(JsonFormatVisitor visitor, Type typeHint) { - return createSchemaNode("string", true); + visitor.stringFormat(); } } } diff --git a/src/main/java/com/fasterxml/jackson/databind/ser/std/StdKeySerializer.java b/src/main/java/com/fasterxml/jackson/databind/ser/std/StdKeySerializer.java index f8401f3d9b..aa1299cc39 100644 --- a/src/main/java/com/fasterxml/jackson/databind/ser/std/StdKeySerializer.java +++ b/src/main/java/com/fasterxml/jackson/databind/ser/std/StdKeySerializer.java @@ -6,9 +6,8 @@ import com.fasterxml.jackson.core.*; -import com.fasterxml.jackson.databind.JsonMappingException; -import com.fasterxml.jackson.databind.JsonNode; import com.fasterxml.jackson.databind.SerializerProvider; +import com.fasterxml.jackson.databind.jsonschema.visitors.JsonFormatVisitor; import com.fasterxml.jackson.databind.ser.std.StdSerializer; /** @@ -35,9 +34,8 @@ public void serialize(Object value, JsonGenerator jgen, SerializerProvider provi } @Override - public JsonNode getSchema(SerializerProvider provider, Type typeHint) - throws JsonMappingException + public void acceptJsonFormatVisitor(JsonFormatVisitor visitor, Type typeHint) { - return createSchemaNode("string"); + visitor.stringFormat(); } } diff --git a/src/main/java/com/fasterxml/jackson/databind/ser/std/StdScalarSerializer.java b/src/main/java/com/fasterxml/jackson/databind/ser/std/StdScalarSerializer.java index aa1ff3e6d0..8e8e195d93 100644 --- a/src/main/java/com/fasterxml/jackson/databind/ser/std/StdScalarSerializer.java +++ b/src/main/java/com/fasterxml/jackson/databind/ser/std/StdScalarSerializer.java @@ -8,6 +8,7 @@ import com.fasterxml.jackson.databind.JsonMappingException; import com.fasterxml.jackson.databind.JsonNode; import com.fasterxml.jackson.databind.SerializerProvider; +import com.fasterxml.jackson.databind.jsonschema.visitors.JsonFormatVisitor; import com.fasterxml.jackson.databind.jsontype.TypeSerializer; public abstract class StdScalarSerializer @@ -44,9 +45,8 @@ public void serializeWithType(T value, JsonGenerator jgen, SerializerProvider pr } @Override - public JsonNode getSchema(SerializerProvider provider, Type typeHint) - throws JsonMappingException + public void acceptJsonFormatVisitor(JsonFormatVisitor visitor, Type typeHint) { - return createSchemaNode("string", true); + visitor.anyFormat(); } } diff --git a/src/main/java/com/fasterxml/jackson/databind/ser/std/StdSerializer.java b/src/main/java/com/fasterxml/jackson/databind/ser/std/StdSerializer.java index ba3e3b8b79..37602a0ab3 100644 --- a/src/main/java/com/fasterxml/jackson/databind/ser/std/StdSerializer.java +++ b/src/main/java/com/fasterxml/jackson/databind/ser/std/StdSerializer.java @@ -8,6 +8,7 @@ import com.fasterxml.jackson.databind.*; import com.fasterxml.jackson.databind.annotation.JacksonStdImpl; import com.fasterxml.jackson.databind.jsonschema.SchemaAware; +import com.fasterxml.jackson.databind.jsonschema.visitors.JsonFormatVisitor; import com.fasterxml.jackson.databind.node.JsonNodeFactory; import com.fasterxml.jackson.databind.node.ObjectNode; @@ -76,52 +77,14 @@ public abstract void serialize(T value, JsonGenerator jgen, SerializerProvider p */ /** - * Default implementation simply claims type is "string"; usually + * Default implementation specifies no format. This behavior is usually * overriden by custom serializers. */ // @Override - public JsonNode getSchema(SerializerProvider provider, Type typeHint) - throws JsonMappingException - { - return createSchemaNode("string"); - } - - /** - * Default implementation simply claims type is "string"; usually - * overriden by custom serializers. - */ -// @Override - public JsonNode getSchema(SerializerProvider provider, Type typeHint, boolean isOptional) - throws JsonMappingException - { - ObjectNode schema = (ObjectNode) getSchema(provider, typeHint); - if (!isOptional) { - schema.put("required", !isOptional); - } - return schema; - } - - protected ObjectNode createObjectNode() { - return JsonNodeFactory.instance.objectNode(); + public void acceptJsonFormatVisitor(JsonFormatVisitor visitor, Type typeHint) { + visitor.anyFormat(); } - - protected ObjectNode createSchemaNode(String type) - { - ObjectNode schema = createObjectNode(); - schema.put("type", type); - return schema; - } - - protected ObjectNode createSchemaNode(String type, boolean isOptional) - { - ObjectNode schema = createSchemaNode(type); - // as per [JACKSON-563]. Note that 'required' defaults to false - if (!isOptional) { - schema.put("required", !isOptional); - } - return schema; - } - + /* /********************************************************** /* Helper methods for exception handling diff --git a/src/main/java/com/fasterxml/jackson/databind/ser/std/StringSerializer.java b/src/main/java/com/fasterxml/jackson/databind/ser/std/StringSerializer.java index eb142f5d15..5635039e58 100644 --- a/src/main/java/com/fasterxml/jackson/databind/ser/std/StringSerializer.java +++ b/src/main/java/com/fasterxml/jackson/databind/ser/std/StringSerializer.java @@ -5,9 +5,9 @@ import com.fasterxml.jackson.core.*; -import com.fasterxml.jackson.databind.JsonNode; import com.fasterxml.jackson.databind.SerializerProvider; import com.fasterxml.jackson.databind.annotation.JacksonStdImpl; +import com.fasterxml.jackson.databind.jsonschema.visitors.JsonFormatVisitor; /** * This is the special serializer for regular {@link java.lang.String}s. @@ -37,8 +37,8 @@ public void serialize(String value, JsonGenerator jgen, SerializerProvider provi } @Override - public JsonNode getSchema(SerializerProvider provider, Type typeHint) + public void acceptJsonFormatVisitor(JsonFormatVisitor visitor, Type typeHint) { - return createSchemaNode("string", true); + visitor.stringFormat(); } } diff --git a/src/main/java/com/fasterxml/jackson/databind/ser/std/ToStringSerializer.java b/src/main/java/com/fasterxml/jackson/databind/ser/std/ToStringSerializer.java index bb65ca3721..83feb5770b 100644 --- a/src/main/java/com/fasterxml/jackson/databind/ser/std/ToStringSerializer.java +++ b/src/main/java/com/fasterxml/jackson/databind/ser/std/ToStringSerializer.java @@ -9,6 +9,7 @@ import com.fasterxml.jackson.databind.JsonNode; import com.fasterxml.jackson.databind.SerializerProvider; import com.fasterxml.jackson.databind.annotation.JacksonStdImpl; +import com.fasterxml.jackson.databind.jsonschema.visitors.JsonFormatVisitor; import com.fasterxml.jackson.databind.jsontype.TypeSerializer; /** @@ -74,10 +75,9 @@ public void serializeWithType(Object value, JsonGenerator jgen, SerializerProvid } @Override - public JsonNode getSchema(SerializerProvider provider, Type typeHint) - throws JsonMappingException + public void acceptJsonFormatVisitor(JsonFormatVisitor visitor, Type typeHint) { - return createSchemaNode("string", true); + visitor.stringFormat(); } } diff --git a/src/main/java/com/fasterxml/jackson/databind/ser/std/TokenBufferSerializer.java b/src/main/java/com/fasterxml/jackson/databind/ser/std/TokenBufferSerializer.java index 73eb789dd6..50dee4529b 100644 --- a/src/main/java/com/fasterxml/jackson/databind/ser/std/TokenBufferSerializer.java +++ b/src/main/java/com/fasterxml/jackson/databind/ser/std/TokenBufferSerializer.java @@ -8,6 +8,7 @@ import com.fasterxml.jackson.databind.JsonNode; import com.fasterxml.jackson.databind.SerializerProvider; import com.fasterxml.jackson.databind.annotation.JacksonStdImpl; +import com.fasterxml.jackson.databind.jsonschema.visitors.JsonFormatVisitor; import com.fasterxml.jackson.databind.jsontype.TypeSerializer; import com.fasterxml.jackson.databind.util.TokenBuffer; @@ -53,12 +54,12 @@ public final void serializeWithType(TokenBuffer value, JsonGenerator jgen, Seria } @Override - public JsonNode getSchema(SerializerProvider provider, Type typeHint) + public void acceptJsonFormatVisitor(JsonFormatVisitor visitor, Type typeHint) { /* 01-Jan-2010, tatu: Not 100% sure what we should say here: * type is basically not known. This seems closest * approximation */ - return createSchemaNode("any", true); + visitor.anyFormat(); } } diff --git a/src/test/java/com/fasterxml/jackson/databind/jsonschema/TestGenerateJsonSchema.java b/src/test/java/com/fasterxml/jackson/databind/jsonschema/TestGenerateJsonSchema.java index 93005cdb80..4865931584 100644 --- a/src/test/java/com/fasterxml/jackson/databind/jsonschema/TestGenerateJsonSchema.java +++ b/src/test/java/com/fasterxml/jackson/databind/jsonschema/TestGenerateJsonSchema.java @@ -7,6 +7,7 @@ import com.fasterxml.jackson.annotation.JsonProperty; import com.fasterxml.jackson.databind.JsonNode; import com.fasterxml.jackson.databind.ObjectMapper; +import com.fasterxml.jackson.databind.jsonschema.types.Schema; import com.fasterxml.jackson.databind.node.ObjectNode; import com.fasterxml.jackson.databind.ser.FilterProvider; import com.fasterxml.jackson.databind.ser.impl.SimpleBeanPropertyFilter; @@ -107,7 +108,7 @@ public class BeanWithId { public void testGeneratingJsonSchema() throws Exception { - JsonSchema jsonSchema = MAPPER.generateJsonSchema(SimpleBean.class); + Schema jsonSchema = new ObjectMapper().generateJsonSchema(SimpleBean.class); assertNotNull(jsonSchema); @@ -120,29 +121,29 @@ public void testGeneratingJsonSchema() assertNotNull(jsonSchema.toString()); assertNotNull(JsonSchema.getDefaultSchemaNode()); - ObjectNode root = jsonSchema.getSchemaNode(); - assertEquals("object", root.get("type").asText()); - assertEquals(false, root.path("required").booleanValue()); - JsonNode propertiesSchema = root.get("properties"); - assertNotNull(propertiesSchema); - JsonNode property1Schema = propertiesSchema.get("property1"); - assertNotNull(property1Schema); - assertEquals("integer", property1Schema.get("type").asText()); - assertEquals(false, property1Schema.path("required").booleanValue()); - JsonNode property2Schema = propertiesSchema.get("property2"); - assertNotNull(property2Schema); - assertEquals("string", property2Schema.get("type").asText()); - assertEquals(false, property2Schema.path("required").booleanValue()); - JsonNode property3Schema = propertiesSchema.get("property3"); - assertNotNull(property3Schema); - assertEquals("array", property3Schema.get("type").asText()); - assertEquals(false, property3Schema.path("required").booleanValue()); - assertEquals("string", property3Schema.get("items").get("type").asText()); - JsonNode property4Schema = propertiesSchema.get("property4"); - assertNotNull(property4Schema); - assertEquals("array", property4Schema.get("type").asText()); - assertEquals(false, property4Schema.path("required").booleanValue()); - assertEquals("number", property4Schema.get("items").get("type").asText()); +// ObjectNode root = jsonSchema.getSchemaNode(); +// assertEquals("object", root.get("type").asText()); +// assertEquals(false, root.path("required").booleanValue()); +// JsonNode propertiesSchema = root.get("properties"); +// assertNotNull(propertiesSchema); +// JsonNode property1Schema = propertiesSchema.get("property1"); +// assertNotNull(property1Schema); +// assertEquals("integer", property1Schema.get("type").asText()); +// assertEquals(false, property1Schema.path("required").booleanValue()); +// JsonNode property2Schema = propertiesSchema.get("property2"); +// assertNotNull(property2Schema); +// assertEquals("string", property2Schema.get("type").asText()); +// assertEquals(false, property2Schema.path("required").booleanValue()); +// JsonNode property3Schema = propertiesSchema.get("property3"); +// assertNotNull(property3Schema); +// assertEquals("array", property3Schema.get("type").asText()); +// assertEquals(false, property3Schema.path("required").booleanValue()); +// assertEquals("string", property3Schema.get("items").get("type").asText()); +// JsonNode property4Schema = propertiesSchema.get("property4"); +// assertNotNull(property4Schema); +// assertEquals("array", property4Schema.get("type").asText()); +// assertEquals(false, property4Schema.path("required").booleanValue()); +// assertEquals("number", property4Schema.get("items").get("type").asText()); } @JsonFilter("filteredBean") @@ -167,10 +168,10 @@ private static class FilteredBean { public void testGeneratingJsonSchemaWithFilters() throws Exception { ObjectMapper mapper = new ObjectMapper(); mapper.setFilters(secretFilterProvider); - JsonSchema schema = mapper.generateJsonSchema(FilteredBean.class); - JsonNode node = schema.getSchemaNode().get("properties"); - assertTrue(node.has("obvious")); - assertFalse(node.has("secret")); + Schema schema = mapper.generateJsonSchema(FilteredBean.class); +// JsonNode node = schema.getSchemaNode().get("properties"); +// assertTrue(node.has("obvious")); +// assertFalse(node.has("secret")); } /** @@ -180,7 +181,7 @@ public void testGeneratingJsonSchemaWithFilters() throws Exception { public void testSchemaSerialization() throws Exception { - JsonSchema jsonSchema = MAPPER.generateJsonSchema(SimpleBean.class); + Schema jsonSchema = MAPPER.generateJsonSchema(SimpleBean.class); Map result = writeAndMap(MAPPER, jsonSchema); assertNotNull(result); // no need to check out full structure, just basics... @@ -207,7 +208,7 @@ public void testInvalidCall() */ public void testThatObjectsHaveNoItems() throws Exception { - JsonSchema jsonSchema = MAPPER.generateJsonSchema(TrivialBean.class); + Schema jsonSchema = MAPPER.generateJsonSchema(TrivialBean.class); String json = jsonSchema.toString().replaceAll("\"", "'"); // can we count on ordering being stable? I think this is true with current ObjectNode impl // as perh [JACKSON-563]; 'required' is only included if true @@ -217,7 +218,7 @@ public void testThatObjectsHaveNoItems() throws Exception public void testSchemaId() throws Exception { - JsonSchema jsonSchema = MAPPER.generateJsonSchema(BeanWithId.class); + Schema jsonSchema = MAPPER.generateJsonSchema(BeanWithId.class); String json = jsonSchema.toString().replaceAll("\"", "'"); assertEquals("{'type':'object','id':'myType','properties':{'value':{'type':'string'}}}", json); diff --git a/src/test/java/com/fasterxml/jackson/databind/jsonschema/TestReadJsonSchema.java b/src/test/java/com/fasterxml/jackson/databind/jsonschema/TestReadJsonSchema.java index ef3513b63d..a8460a5068 100644 --- a/src/test/java/com/fasterxml/jackson/databind/jsonschema/TestReadJsonSchema.java +++ b/src/test/java/com/fasterxml/jackson/databind/jsonschema/TestReadJsonSchema.java @@ -4,6 +4,7 @@ import com.fasterxml.jackson.databind.*; import com.fasterxml.jackson.databind.jsonschema.JsonSchema; +import com.fasterxml.jackson.databind.jsonschema.types.Schema; /** * Trivial test to ensure {@link JsonSchema} can be also deserialized @@ -50,7 +51,7 @@ static class Schemable { public void testDeserializeSimple() throws Exception { ObjectMapper mapper = new ObjectMapper(); - JsonSchema schema = mapper.generateJsonSchema(Schemable.class); + Schema schema = mapper.generateJsonSchema(Schemable.class); assertNotNull(schema); String schemaStr = mapper.writeValueAsString(schema); diff --git a/src/test/java/com/fasterxml/jackson/databind/module/TestSimpleModule.java b/src/test/java/com/fasterxml/jackson/databind/module/TestSimpleModule.java index 1400401357..2711d56f90 100644 --- a/src/test/java/com/fasterxml/jackson/databind/module/TestSimpleModule.java +++ b/src/test/java/com/fasterxml/jackson/databind/module/TestSimpleModule.java @@ -8,6 +8,7 @@ import com.fasterxml.jackson.core.*; import com.fasterxml.jackson.annotation.JsonPropertyOrder; import com.fasterxml.jackson.databind.*; +import com.fasterxml.jackson.databind.jsonschema.visitors.JsonFormatVisitor; import com.fasterxml.jackson.databind.module.SimpleDeserializers; import com.fasterxml.jackson.databind.module.SimpleModule; import com.fasterxml.jackson.databind.module.SimpleSerializers; @@ -52,8 +53,8 @@ public void serialize(CustomBean value, JsonGenerator jgen, SerializerProvider p } @Override - public JsonNode getSchema(SerializerProvider provider, Type typeHint) throws JsonMappingException { - return null; + public void acceptJsonFormatVisitor(JsonFormatVisitor visitor, Type typeHint) { + visitor.anyFormat(); } } @@ -86,8 +87,8 @@ public void serialize(SimpleEnum value, JsonGenerator jgen, SerializerProvider p } @Override - public JsonNode getSchema(SerializerProvider provider, Type typeHint) throws JsonMappingException { - return null; + public void acceptJsonFormatVisitor(JsonFormatVisitor visitor, Type typeHint) { + visitor.anyFormat(); } } From b113cd620fa33e75ae1ccb88a477126f2f450878 Mon Sep 17 00:00:00 2001 From: jackphel Date: Mon, 30 Jul 2012 17:42:05 -0400 Subject: [PATCH 03/19] replaced getClass with getRawClass --- .../jsonschema/factories/ObjectSchemaFactory.java | 8 ++++---- .../jackson/databind/ser/std/AsArraySerializerBase.java | 2 +- .../jackson/databind/ser/std/BeanSerializerBase.java | 8 ++++---- .../databind/jsonschema/TestGenerateJsonSchema.java | 2 +- 4 files changed, 10 insertions(+), 10 deletions(-) diff --git a/src/main/java/com/fasterxml/jackson/databind/jsonschema/factories/ObjectSchemaFactory.java b/src/main/java/com/fasterxml/jackson/databind/jsonschema/factories/ObjectSchemaFactory.java index 6e80ec0061..775b824bb2 100644 --- a/src/main/java/com/fasterxml/jackson/databind/jsonschema/factories/ObjectSchemaFactory.java +++ b/src/main/java/com/fasterxml/jackson/databind/jsonschema/factories/ObjectSchemaFactory.java @@ -44,19 +44,19 @@ private JsonSerializer getSer(BeanPropertyWriter writer, Class serTyp return null; } - private Type writerType(BeanPropertyWriter writer) { + private Class writerType(BeanPropertyWriter writer) { //TODO:Will these ever return different types? //JavaType propType = writer.getSerializationType(); //Type hint = (propType == null) ? writer.getGenericPropertyType() : propType.getRawClass(); - return writer.getRawSerializationType(); + return writer.getPropertyType(); } protected Schema propertySchema(BeanPropertyWriter writer) { SchemaFactory visitor = new SchemaFactory(mapper); - Type serType = writerType(writer); - JsonSerializer ser = getSer(writer, serType.getClass()); + Class serType = writerType(writer); + JsonSerializer ser = getSer(writer, serType); if (ser != null && ser instanceof SchemaAware) { ((SchemaAware)ser).acceptJsonFormatVisitor(visitor, serType); } else { diff --git a/src/main/java/com/fasterxml/jackson/databind/ser/std/AsArraySerializerBase.java b/src/main/java/com/fasterxml/jackson/databind/ser/std/AsArraySerializerBase.java index 505c72ea13..1de06418ac 100644 --- a/src/main/java/com/fasterxml/jackson/databind/ser/std/AsArraySerializerBase.java +++ b/src/main/java/com/fasterxml/jackson/databind/ser/std/AsArraySerializerBase.java @@ -177,7 +177,7 @@ public void acceptJsonFormatVisitor(JsonFormatVisitor visitor, Type typeHint) */ //ObjectNode o = createSchemaNode("array", true); JsonArrayFormatVisitor arrayVisitor = - visitor.arrayFormat(typeHint == null ? _elementType.getClass() : typeHint); + visitor.arrayFormat(typeHint == null ? _elementType.getRawClass() : typeHint); JavaType contentType = null; if (typeHint != null) { JavaType javaType = visitor.getProvider().constructType(typeHint); diff --git a/src/main/java/com/fasterxml/jackson/databind/ser/std/BeanSerializerBase.java b/src/main/java/com/fasterxml/jackson/databind/ser/std/BeanSerializerBase.java index eac8280b74..2877aade5b 100644 --- a/src/main/java/com/fasterxml/jackson/databind/ser/std/BeanSerializerBase.java +++ b/src/main/java/com/fasterxml/jackson/databind/ser/std/BeanSerializerBase.java @@ -672,11 +672,11 @@ public void acceptJsonFormatVisitor(JsonFormatVisitor visitor, Type typeHint) * @param propertiesNode Node which the given property would exist within */ public static void depositSchemaProperty(BeanPropertyWriter writer, JsonObjectFormatVisitor objectVisitor) { - if (isPropertyRequired(writer, objectVisitor.getProvider())) { + //if (isPropertyRequired(writer, objectVisitor.getProvider())) { objectVisitor.property(writer); - } else { - objectVisitor.optionalProperty(writer); - } + //} else { + //objectVisitor.optionalProperty(writer); + //} } /** diff --git a/src/test/java/com/fasterxml/jackson/databind/jsonschema/TestGenerateJsonSchema.java b/src/test/java/com/fasterxml/jackson/databind/jsonschema/TestGenerateJsonSchema.java index 4865931584..9321cb141f 100644 --- a/src/test/java/com/fasterxml/jackson/databind/jsonschema/TestGenerateJsonSchema.java +++ b/src/test/java/com/fasterxml/jackson/databind/jsonschema/TestGenerateJsonSchema.java @@ -108,7 +108,7 @@ public class BeanWithId { public void testGeneratingJsonSchema() throws Exception { - Schema jsonSchema = new ObjectMapper().generateJsonSchema(SimpleBean.class); + Schema jsonSchema = MAPPER.generateJsonSchema(SimpleBean.class); assertNotNull(jsonSchema); From 5b0fd4d803b3c453504eb0d4d2ffedba930780ee Mon Sep 17 00:00:00 2001 From: jackphel Date: Tue, 31 Jul 2012 14:47:33 -0400 Subject: [PATCH 04/19] Generates schema in TestGenerateJsonSchema without throwing errors --- .../jackson/databind/ObjectMapper.java | 5 +- .../factories/AnySchemaFactory.java | 2 +- .../factories/ArraySchemaFactory.java | 4 +- .../factories/BooleanSchemaFactory.java | 2 +- .../factories/IntegerSchemaFactory.java | 2 +- .../factories/NullSchemaFactory.java | 2 +- .../factories/NumberSchemaFactory.java | 2 +- .../factories/ObjectSchemaFactory.java | 10 +- .../jsonschema/factories/SchemaFactory.java | 67 ++- .../factories/StringSchemaFactory.java | 2 +- .../factories/ValueTypeSchemaFactory.java | 6 +- .../databind/jsonschema/types/AnySchema.java | 20 +- .../jsonschema/types/ArraySchema.java | 163 +++--- .../jsonschema/types/ContainerTypeSchema.java | 24 +- .../jsonschema/types/IntegerSchema.java | 15 + .../jsonschema/types/NumberSchema.java | 110 ++-- .../jsonschema/types/ObjectSchema.java | 302 +++++----- .../databind/jsonschema/types/Schema.java | 526 ++++++++++-------- .../jsonschema/types/SimpleTypeSchema.java | 84 +-- .../jsonschema/types/StringSchema.java | 103 ++-- .../jsonschema/types/UnionTypeSchema.java | 35 +- .../jsonschema/types/ValueTypeSchema.java | 80 +-- .../jsonschema/TestGenerateJsonSchema.java | 6 +- 23 files changed, 900 insertions(+), 672 deletions(-) diff --git a/src/main/java/com/fasterxml/jackson/databind/ObjectMapper.java b/src/main/java/com/fasterxml/jackson/databind/ObjectMapper.java index cc1525bf41..e14468b189 100644 --- a/src/main/java/com/fasterxml/jackson/databind/ObjectMapper.java +++ b/src/main/java/com/fasterxml/jackson/databind/ObjectMapper.java @@ -2400,8 +2400,9 @@ protected Object _convert(Object fromValue, JavaType toValueType) * @return Constructed JSON schema. */ public Schema generateJsonSchema(Class t) throws JsonMappingException { - SchemaFactory visitor = new SchemaFactory(this); - _serializerProvider(getSerializationConfig()).acceptJsonFormatVisitor(t, visitor); + DefaultSerializerProvider provider = _serializerProvider(getSerializationConfig()); + SchemaFactory visitor = new SchemaFactory(provider); + provider.acceptJsonFormatVisitor(t, visitor); return visitor.finalSchema(); } diff --git a/src/main/java/com/fasterxml/jackson/databind/jsonschema/factories/AnySchemaFactory.java b/src/main/java/com/fasterxml/jackson/databind/jsonschema/factories/AnySchemaFactory.java index 30f83df180..4758a05815 100644 --- a/src/main/java/com/fasterxml/jackson/databind/jsonschema/factories/AnySchemaFactory.java +++ b/src/main/java/com/fasterxml/jackson/databind/jsonschema/factories/AnySchemaFactory.java @@ -11,7 +11,7 @@ public class AnySchemaFactory extends SchemaFactory implements protected AnySchema anySchema; public AnySchemaFactory(SchemaFactory parent) { - super(parent.mapper); + super(parent.provider); this.parent = parent; anySchema = new AnySchema(); } diff --git a/src/main/java/com/fasterxml/jackson/databind/jsonschema/factories/ArraySchemaFactory.java b/src/main/java/com/fasterxml/jackson/databind/jsonschema/factories/ArraySchemaFactory.java index d45ce34882..63607cb369 100644 --- a/src/main/java/com/fasterxml/jackson/databind/jsonschema/factories/ArraySchemaFactory.java +++ b/src/main/java/com/fasterxml/jackson/databind/jsonschema/factories/ArraySchemaFactory.java @@ -17,7 +17,7 @@ public class ArraySchemaFactory extends SchemaFactory implements JsonArrayFormat protected BeanProperty _property; public ArraySchemaFactory(SchemaFactory parent, BeanProperty property) { - super(parent.mapper); + super(parent.provider); this.parent = parent; arraySchema = new ArraySchema(); } @@ -34,7 +34,7 @@ public void itemsFormat(JavaType contentType) { try { ser = getProvider().findValueSerializer(contentType, _property); if (ser instanceof SchemaAware) { - SchemaFactory visitor = new SchemaFactory(mapper); + SchemaFactory visitor = new SchemaFactory(provider); ((SchemaAware) ser).acceptJsonFormatVisitor(visitor, null); arraySchema.setItemsSchema(visitor.finalSchema()); } diff --git a/src/main/java/com/fasterxml/jackson/databind/jsonschema/factories/BooleanSchemaFactory.java b/src/main/java/com/fasterxml/jackson/databind/jsonschema/factories/BooleanSchemaFactory.java index 9e5cd6e757..61b4e16cdc 100644 --- a/src/main/java/com/fasterxml/jackson/databind/jsonschema/factories/BooleanSchemaFactory.java +++ b/src/main/java/com/fasterxml/jackson/databind/jsonschema/factories/BooleanSchemaFactory.java @@ -11,7 +11,7 @@ public class BooleanSchemaFactory extends ValueTypeSchemaFactory implements protected BooleanSchema booleanSchema; public BooleanSchemaFactory(SchemaFactory parent) { - super(parent.mapper); + super(parent.provider); this.parent = parent; booleanSchema = new BooleanSchema(); } diff --git a/src/main/java/com/fasterxml/jackson/databind/jsonschema/factories/IntegerSchemaFactory.java b/src/main/java/com/fasterxml/jackson/databind/jsonschema/factories/IntegerSchemaFactory.java index cbacc6d039..f073fb26db 100644 --- a/src/main/java/com/fasterxml/jackson/databind/jsonschema/factories/IntegerSchemaFactory.java +++ b/src/main/java/com/fasterxml/jackson/databind/jsonschema/factories/IntegerSchemaFactory.java @@ -11,7 +11,7 @@ public class IntegerSchemaFactory extends ValueTypeSchemaFactory implements protected IntegerSchema integerSchema; public IntegerSchemaFactory(SchemaFactory parent) { - super(parent.mapper); + super(parent.provider); this.parent = parent; integerSchema = new IntegerSchema(); } diff --git a/src/main/java/com/fasterxml/jackson/databind/jsonschema/factories/NullSchemaFactory.java b/src/main/java/com/fasterxml/jackson/databind/jsonschema/factories/NullSchemaFactory.java index cf5f1bfe32..70ffc5b834 100644 --- a/src/main/java/com/fasterxml/jackson/databind/jsonschema/factories/NullSchemaFactory.java +++ b/src/main/java/com/fasterxml/jackson/databind/jsonschema/factories/NullSchemaFactory.java @@ -11,7 +11,7 @@ public class NullSchemaFactory extends SchemaFactory implements protected NullSchema nullSchema; public NullSchemaFactory(SchemaFactory parent) { - super(parent.mapper); + super(parent.provider); this.parent = parent; nullSchema = new NullSchema(); } diff --git a/src/main/java/com/fasterxml/jackson/databind/jsonschema/factories/NumberSchemaFactory.java b/src/main/java/com/fasterxml/jackson/databind/jsonschema/factories/NumberSchemaFactory.java index c3e9192f1b..49582b9cb6 100644 --- a/src/main/java/com/fasterxml/jackson/databind/jsonschema/factories/NumberSchemaFactory.java +++ b/src/main/java/com/fasterxml/jackson/databind/jsonschema/factories/NumberSchemaFactory.java @@ -11,7 +11,7 @@ public class NumberSchemaFactory extends ValueTypeSchemaFactory implements protected NumberSchema numberSchema; public NumberSchemaFactory(SchemaFactory parent) { - super(parent.mapper); + super(parent.provider); this.parent = parent; numberSchema = new NumberSchema(); } diff --git a/src/main/java/com/fasterxml/jackson/databind/jsonschema/factories/ObjectSchemaFactory.java b/src/main/java/com/fasterxml/jackson/databind/jsonschema/factories/ObjectSchemaFactory.java index 775b824bb2..171f68d73d 100644 --- a/src/main/java/com/fasterxml/jackson/databind/jsonschema/factories/ObjectSchemaFactory.java +++ b/src/main/java/com/fasterxml/jackson/databind/jsonschema/factories/ObjectSchemaFactory.java @@ -2,10 +2,8 @@ import java.lang.reflect.Type; -import com.fasterxml.jackson.databind.JavaType; import com.fasterxml.jackson.databind.JsonMappingException; import com.fasterxml.jackson.databind.JsonSerializer; -import com.fasterxml.jackson.databind.SerializerProvider; import com.fasterxml.jackson.databind.jsonschema.SchemaAware; import com.fasterxml.jackson.databind.jsonschema.types.ObjectSchema; import com.fasterxml.jackson.databind.jsonschema.types.Schema; @@ -19,7 +17,7 @@ public class ObjectSchemaFactory extends SchemaFactory implements JsonObjectForm protected ObjectSchema objectSchema; public ObjectSchemaFactory(SchemaFactory parent) { - super(parent.mapper); + super(parent.provider); this.parent = parent; objectSchema = new ObjectSchema(); } @@ -41,7 +39,7 @@ private JsonSerializer getSer(BeanPropertyWriter writer, Class serTyp // TODO: log error } } - return null; + return ser; } private Class writerType(BeanPropertyWriter writer) { @@ -54,7 +52,7 @@ private Class writerType(BeanPropertyWriter writer) { } protected Schema propertySchema(BeanPropertyWriter writer) { - SchemaFactory visitor = new SchemaFactory(mapper); + SchemaFactory visitor = new SchemaFactory(provider); Class serType = writerType(writer); JsonSerializer ser = getSer(writer, serType); if (ser != null && ser instanceof SchemaAware) { @@ -66,7 +64,7 @@ protected Schema propertySchema(BeanPropertyWriter writer) { } protected Schema propertySchema(SchemaAware handler, Type propertyTypeHint) { - SchemaFactory visitor = new SchemaFactory(mapper); + SchemaFactory visitor = new SchemaFactory(provider); handler.acceptJsonFormatVisitor(visitor, propertyTypeHint); return visitor.finalSchema(); } diff --git a/src/main/java/com/fasterxml/jackson/databind/jsonschema/factories/SchemaFactory.java b/src/main/java/com/fasterxml/jackson/databind/jsonschema/factories/SchemaFactory.java index 5007bff0b4..94223846ce 100644 --- a/src/main/java/com/fasterxml/jackson/databind/jsonschema/factories/SchemaFactory.java +++ b/src/main/java/com/fasterxml/jackson/databind/jsonschema/factories/SchemaFactory.java @@ -2,7 +2,6 @@ import java.lang.reflect.Type; -import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.databind.SerializerProvider; import com.fasterxml.jackson.databind.jsonschema.types.Schema; import com.fasterxml.jackson.databind.jsonschema.visitors.JsonAnyFormatVisitor; @@ -17,37 +16,27 @@ public class SchemaFactory implements JsonFormatVisitor { - protected ObjectMapper mapper; private SchemaFactoryDelegate delegate; - - public SerializerProvider getProvider() { - return mapper.getSerializerProvider(); - } + protected SerializerProvider provider; - public SchemaFactory(ObjectMapper mapper) { - this.mapper = mapper; + public SchemaFactory(SerializerProvider mapper) { + this.provider = mapper; } - - public JsonObjectFormatVisitor objectFormat(Type type) { - //BasicClassIntrospector.instance. - delegate = new ObjectSchemaFactory(this); - return (JsonObjectFormatVisitor) delegate; + + public JsonAnyFormatVisitor anyFormat() { + delegate = new AnySchemaFactory(this); + return (JsonAnyFormatVisitor) delegate; } public JsonArrayFormatVisitor arrayFormat(Type elementType) { delegate = new ArraySchemaFactory(this); return (JsonArrayFormatVisitor) delegate; } - - public JsonStringFormatVisitor stringFormat() { - delegate = new StringSchemaFactory(this); - return (JsonStringFormatVisitor) delegate; + + public JsonBooleanFormatVisitor booleanFormat() { + delegate = new BooleanSchemaFactory(this); + return (JsonBooleanFormatVisitor) delegate; } - public JsonNumberFormatVisitor numberFormat() { return new NumberSchemaFactory(this); } - public JsonIntegerFormatVisitor integerFormat() { return new IntegerSchemaFactory(this); } - public JsonBooleanFormatVisitor booleanFormat() { return new BooleanSchemaFactory(this); } - public JsonNullFormatVisitor nullFormat() { return new NullSchemaFactory(this); } - public JsonAnyFormatVisitor anyFormat() { return new AnySchemaFactory(this); } public Schema finalSchema() { assert delegate != null : "SchemaFactory must envoke a delegate method before it can return a Schema."; @@ -56,7 +45,37 @@ public Schema finalSchema() { } else { return delegate.getSchema(); } - + + } + + public SerializerProvider getProvider() { + return provider; + } + + public JsonIntegerFormatVisitor integerFormat() { + delegate = new IntegerSchemaFactory(this); + return (JsonIntegerFormatVisitor) delegate; } - + + public JsonNullFormatVisitor nullFormat() { + delegate = new NullSchemaFactory(this); + return (JsonNullFormatVisitor) delegate; + } + + public JsonNumberFormatVisitor numberFormat() { + delegate = new NumberSchemaFactory(this); + return (JsonNumberFormatVisitor) delegate; + } + + public JsonObjectFormatVisitor objectFormat(Type type) { + // BasicClassIntrospector.instance. + delegate = new ObjectSchemaFactory(this); + return (JsonObjectFormatVisitor) delegate; + } + + public JsonStringFormatVisitor stringFormat() { + delegate = new StringSchemaFactory(this); + return (JsonStringFormatVisitor) delegate; + } + } diff --git a/src/main/java/com/fasterxml/jackson/databind/jsonschema/factories/StringSchemaFactory.java b/src/main/java/com/fasterxml/jackson/databind/jsonschema/factories/StringSchemaFactory.java index 28e2b237e0..26560c2cf5 100644 --- a/src/main/java/com/fasterxml/jackson/databind/jsonschema/factories/StringSchemaFactory.java +++ b/src/main/java/com/fasterxml/jackson/databind/jsonschema/factories/StringSchemaFactory.java @@ -11,7 +11,7 @@ public class StringSchemaFactory extends ValueTypeSchemaFactory implements JsonS protected SchemaFactory parent; public StringSchemaFactory(SchemaFactory parent) { - super(parent.mapper); + super(parent.provider); this.parent = parent; stringSchema = new StringSchema(); } diff --git a/src/main/java/com/fasterxml/jackson/databind/jsonschema/factories/ValueTypeSchemaFactory.java b/src/main/java/com/fasterxml/jackson/databind/jsonschema/factories/ValueTypeSchemaFactory.java index 88f075081b..d84790f768 100644 --- a/src/main/java/com/fasterxml/jackson/databind/jsonschema/factories/ValueTypeSchemaFactory.java +++ b/src/main/java/com/fasterxml/jackson/databind/jsonschema/factories/ValueTypeSchemaFactory.java @@ -2,7 +2,7 @@ import java.util.Set; -import com.fasterxml.jackson.databind.ObjectMapper; +import com.fasterxml.jackson.databind.SerializerProvider; import com.fasterxml.jackson.databind.jsonschema.types.JsonValueFormat; import com.fasterxml.jackson.databind.jsonschema.types.Schema; import com.fasterxml.jackson.databind.jsonschema.types.ValueTypeSchema; @@ -11,8 +11,8 @@ public abstract class ValueTypeSchemaFactory extends SchemaFactory implements SchemaFactoryDelegate, JsonValueFormatVisitor { - protected ValueTypeSchemaFactory(ObjectMapper mapper) { - super(mapper); + protected ValueTypeSchemaFactory(SerializerProvider provider) { + super(provider); } public Schema getSchema() { diff --git a/src/main/java/com/fasterxml/jackson/databind/jsonschema/types/AnySchema.java b/src/main/java/com/fasterxml/jackson/databind/jsonschema/types/AnySchema.java index ae2e872d42..43570e418b 100644 --- a/src/main/java/com/fasterxml/jackson/databind/jsonschema/types/AnySchema.java +++ b/src/main/java/com/fasterxml/jackson/databind/jsonschema/types/AnySchema.java @@ -1,5 +1,6 @@ package com.fasterxml.jackson.databind.jsonschema.types; +import java.util.HashSet; import java.util.Set; import com.fasterxml.jackson.annotation.JsonProperty; @@ -7,9 +8,6 @@ public class AnySchema extends SimpleTypeSchema { - @JsonProperty(required = true) - public final SchemaType type = SchemaType.ANY; - /** * This provides an enumeration of all possible values that are valid for the instance property. This MUST be an array, and each item in @@ -22,13 +20,21 @@ of enum values uses the same algorithm as defined in "uniqueItems" @JsonProperty private Set enums; - public void setEnums(Set enums) { - this.enums = enums; + @JsonProperty(required = true) + public final SchemaType type = SchemaType.ANY; + + //instance initializer block + { + enums = new HashSet(); } @Override - public boolean isAnySchema() { return true; } + public AnySchema asAnySchema() { return this; } @Override - public AnySchema asAnySchema() { return this; } + public boolean isAnySchema() { return true; } + + public void setEnums(Set enums) { + this.enums = enums; + } } \ No newline at end of file diff --git a/src/main/java/com/fasterxml/jackson/databind/jsonschema/types/ArraySchema.java b/src/main/java/com/fasterxml/jackson/databind/jsonschema/types/ArraySchema.java index 2f7677793d..ce466ee9f7 100644 --- a/src/main/java/com/fasterxml/jackson/databind/jsonschema/types/ArraySchema.java +++ b/src/main/java/com/fasterxml/jackson/databind/jsonschema/types/ArraySchema.java @@ -10,45 +10,20 @@ */ public class ArraySchema extends ContainerTypeSchema { - @JsonProperty(required = true) - public final SchemaType type = SchemaType.ARRAY; - - /**This attribute defines the minimum number of values in an array*/ @JsonProperty - private int minItems; - /** - * {@link ArraySchema#minItems} - * @param minItems the minItems to set - */ - public void setMinItems(int minItems) { - this.minItems = minItems; - } - /** - * {@link ArraySchema#minItems} - * @return the minItems - */ - public int getMinItems() { - return minItems; - } + private ArraySchema.AdditionalItems additionalItems; + @JsonProperty + private ArraySchema.Items items; /**This attribute defines the maximum number of values in an array*/ @JsonProperty private int maxItems; - /** - * {@link ArraySchema#maxItems} - * @param maxItems the maxItems to set - */ - public void setMaxItems(int maxItems) { - this.maxItems = maxItems; - } - /** - * {@link ArraySchema#maxItems} - * @return the maxItems - */ - public int getMaxItems() { - return maxItems; - } + /**This attribute defines the minimum number of values in an array*/ + @JsonProperty + private int minItems; + @JsonProperty(required = true) + public final SchemaType type = SchemaType.ARRAY; /** * This attribute indicates that all items in an array instance MUST be unique (contains no two identical values). @@ -68,13 +43,40 @@ public int getMaxItems() { */ @JsonProperty private Boolean uniqueItems; + + @Override + public ArraySchema asArraySchema() { return this; } /** - * {@link ArraySchema#uniqueItems} - * @param uniqueItems the uniqueItems to set + * {@link ArraySchema#additionalItems} + * @return the additionalItems */ - public void setUniqueItems(Boolean uniqueItems) { - this.uniqueItems = uniqueItems; + public ArraySchema.AdditionalItems getAdditionalItems() { + return additionalItems; + } + + /** + * {@link ArraySchema#items} + * @return the items + */ + public ArraySchema.Items getItems() { + return items; + } + /** + * {@link ArraySchema#maxItems} + * @return the maxItems + */ + public int getMaxItems() { + return maxItems; + } + + + /** + * {@link ArraySchema#minItems} + * @return the minItems + */ + public int getMinItems() { + return minItems; } /** * {@link ArraySchema#uniqueItems} @@ -83,65 +85,56 @@ public void setUniqueItems(Boolean uniqueItems) { public Boolean getUniqueItems() { return uniqueItems; } - + @Override + public boolean isArraySchema() { return true; } - @JsonProperty - private ArraySchema.Items items; /** - * {@link ArraySchema#items} - * @param items the items to set + * {@link ArraySchema#additionalItems} + * @param additionalItems the additionalItems to set */ - public void setItems(ArraySchema.Items items) { - this.items = items; + public void setAdditionalItems(ArraySchema.AdditionalItems additionalItems) { + this.additionalItems = additionalItems; } + /** * {@link ArraySchema#items} - * @return the items + * @param items the items to set */ - public ArraySchema.Items getItems() { - return items; + public void setItems(ArraySchema.Items items) { + this.items = items; } - public void setItemsSchema(Schema schema) { items = new SingleItems(schema); } - - @JsonProperty - private ArraySchema.AdditionalItems additionalItems; /** - * {@link ArraySchema#additionalItems} - * @param additionalItems the additionalItems to set + * {@link ArraySchema#maxItems} + * @param maxItems the maxItems to set */ - public void setAdditionalItems(ArraySchema.AdditionalItems additionalItems) { - this.additionalItems = additionalItems; + public void setMaxItems(int maxItems) { + this.maxItems = maxItems; } + /** - * {@link ArraySchema#additionalItems} - * @return the additionalItems + * {@link ArraySchema#minItems} + * @param minItems the minItems to set */ - public ArraySchema.AdditionalItems getAdditionalItems() { - return additionalItems; + public void setMinItems(int minItems) { + this.minItems = minItems; } /** - * This attribute defines the allowed items in an instance array, and - MUST be a schema or an array of schemas. The default value is an - empty schema which allows any value for items in the instance array. + * {@link ArraySchema#uniqueItems} + * @param uniqueItems the uniqueItems to set */ - public static abstract class Items {} + public void setUniqueItems(Boolean uniqueItems) { + this.uniqueItems = uniqueItems; + } /** - * When this attribute value is a schema and the instance value is an - array, then all the items in the array MUST be valid according to the - schema. + * This provides a definition for additional items in an array instance + when tuple definitions of the items is provided. */ - public static class SingleItems extends ArraySchema.Items { - @JsonProperty - private Schema schema; - public SingleItems(Schema schema) { - this.schema = schema; - } - } + public static abstract class AdditionalItems {} /** * When this attribute value is an array of schemas and the instance @@ -156,10 +149,11 @@ public static class ArrayItems extends ArraySchema.Items { } /** - * This provides a definition for additional items in an array instance - when tuple definitions of the items is provided. + * This attribute defines the allowed items in an instance array, and + MUST be a schema or an array of schemas. The default value is an + empty schema which allows any value for items in the instance array. */ - public static abstract class AdditionalItems {} + public static abstract class Items {} /** * This can be false @@ -180,9 +174,16 @@ public static class SchemaAdditionalItems { private Schema schema; } - @Override - public boolean isArraySchema() { return true; } - - @Override - public ArraySchema asArraySchema() { return this; } + /** + * When this attribute value is a schema and the instance value is an + array, then all the items in the array MUST be valid according to the + schema. + */ + public static class SingleItems extends ArraySchema.Items { + @JsonProperty + private Schema schema; + public SingleItems(Schema schema) { + this.schema = schema; + } + } } \ No newline at end of file diff --git a/src/main/java/com/fasterxml/jackson/databind/jsonschema/types/ContainerTypeSchema.java b/src/main/java/com/fasterxml/jackson/databind/jsonschema/types/ContainerTypeSchema.java index 7d99bdd6d4..595e43cd82 100644 --- a/src/main/java/com/fasterxml/jackson/databind/jsonschema/types/ContainerTypeSchema.java +++ b/src/main/java/com/fasterxml/jackson/databind/jsonschema/types/ContainerTypeSchema.java @@ -1,9 +1,9 @@ package com.fasterxml.jackson.databind.jsonschema.types; +import java.util.HashSet; import java.util.Set; import com.fasterxml.jackson.annotation.JsonProperty; -import com.fasterxml.jackson.databind.JsonNode; public abstract class ContainerTypeSchema extends SimpleTypeSchema { @@ -17,7 +17,27 @@ of enum values uses the same algorithm as defined in "uniqueItems" (Section 5.15). */ @JsonProperty(required = true) - private Set enums; + private Set enums; + + //instance initializer block + { + enums = new HashSet(); + } + + /** + * {@link ContainerTypeSchema#enums} + * @param enums the enums to set + */ + public void setEnums(Set enums) { + this.enums = enums; + } + /** + * {@link ContainerTypeSchema#enums} + * @return the enums + */ + public Set getEnums() { + return enums; + } @Override public boolean isContainerTypeSchema() { return true; } diff --git a/src/main/java/com/fasterxml/jackson/databind/jsonschema/types/IntegerSchema.java b/src/main/java/com/fasterxml/jackson/databind/jsonschema/types/IntegerSchema.java index 60bc18fdb8..33fd02663d 100644 --- a/src/main/java/com/fasterxml/jackson/databind/jsonschema/types/IntegerSchema.java +++ b/src/main/java/com/fasterxml/jackson/databind/jsonschema/types/IntegerSchema.java @@ -14,6 +14,21 @@ divisible by with no remainder (the result of the division must be an */ @JsonProperty private Integer divisibleBy; + + /** + * {@link IntegerSchema#divisibleBy} + * @param divisibleBy the divisibleBy to set + */ + public void setDivisibleBy(Integer divisibleBy) { + this.divisibleBy = divisibleBy; + } + /** + * {@link IntegerSchema#divisibleBy} + * @return the divisibleBy + */ + public Integer getDivisibleBy() { + return divisibleBy; + } @Override public boolean isIntegerSchema() { return true; } diff --git a/src/main/java/com/fasterxml/jackson/databind/jsonschema/types/NumberSchema.java b/src/main/java/com/fasterxml/jackson/databind/jsonschema/types/NumberSchema.java index 59c3fb28f6..0c31542510 100644 --- a/src/main/java/com/fasterxml/jackson/databind/jsonschema/types/NumberSchema.java +++ b/src/main/java/com/fasterxml/jackson/databind/jsonschema/types/NumberSchema.java @@ -4,45 +4,13 @@ public class NumberSchema extends ValueTypeSchema { - @JsonProperty(required = true) - public final SchemaType type = SchemaType.NUMBER; - - /**This attribute defines the minimum value of the instance property*/ - @JsonProperty - private Double minimum; - /** - * {@link NumberSchema#minimum} - * @param minimum the minimum to set - */ - public void setMinimum(Double minimum) { - this.minimum = minimum; - } /** - * {@link NumberSchema#minimum} - * @return the minimum + * This attribute indicates if the value of the instance (if the + instance is a number) can not equal the number defined by the + "maximum" attribute. */ - public Double getMinimum() { - return minimum; - } - - - /**This attribute defines the maximum value of the instance property*/ @JsonProperty - private Double maximum; - /** - * {@link NumberSchema#maximum} - * @param maximum the maximum to set - */ - public void setMaximum(Double maximum) { - this.maximum = maximum; - } - /** - * {@link NumberSchema#maximum} - * @return the maximum - */ - public Double getMaximum() { - return maximum; - } + private Boolean exclusiveMaximum; /** * This attribute indicates if the value of the instance (if the @@ -51,13 +19,28 @@ public Double getMaximum() { */ @JsonProperty private Boolean exclusiveMinimum; + + /**This attribute defines the maximum value of the instance property*/ + @JsonProperty + private Double maximum; + + /**This attribute defines the minimum value of the instance property*/ + @JsonProperty + private Double minimum; + + @JsonProperty(required = true) + public final SchemaType type = SchemaType.NUMBER; + + @Override + public NumberSchema asNumberSchema() { return this; } /** - * {@link NumberSchema#exclusiveMinimum} - * @param exclusiveMinimum the exclusiveMinimum to set + * {@link NumberSchema#exclusiveMaximum} + * @return the exclusiveMaximum */ - public void setExclusiveMinimum(Boolean exclusiveMinimum) { - this.exclusiveMinimum = exclusiveMinimum; + public Boolean getExclusiveMaximum() { + return exclusiveMaximum; } + /** * {@link NumberSchema#exclusiveMinimum} * @return the exclusiveMinimum @@ -65,14 +48,23 @@ public void setExclusiveMinimum(Boolean exclusiveMinimum) { public Boolean getExclusiveMinimum() { return exclusiveMinimum; } - /** - * This attribute indicates if the value of the instance (if the - instance is a number) can not equal the number defined by the - "maximum" attribute. + * {@link NumberSchema#maximum} + * @return the maximum */ - @JsonProperty - private Boolean exclusiveMaximum; + public Double getMaximum() { + return maximum; + } + /** + * {@link NumberSchema#minimum} + * @return the minimum + */ + public Double getMinimum() { + return minimum; + } + + @Override + public boolean isNumberSchema() { return true; } /** * {@link NumberSchema#exclusiveMaximum} * @param exclusiveMaximum the exclusiveMaximum to set @@ -81,16 +73,26 @@ public void setExclusiveMaximum(Boolean exclusiveMaximum) { this.exclusiveMaximum = exclusiveMaximum; } /** - * {@link NumberSchema#exclusiveMaximum} - * @return the exclusiveMaximum + * {@link NumberSchema#exclusiveMinimum} + * @param exclusiveMinimum the exclusiveMinimum to set */ - public Boolean getExclusiveMaximum() { - return exclusiveMaximum; + public void setExclusiveMinimum(Boolean exclusiveMinimum) { + this.exclusiveMinimum = exclusiveMinimum; } - @Override - public boolean isNumberSchema() { return true; } + /** + * {@link NumberSchema#maximum} + * @param maximum the maximum to set + */ + public void setMaximum(Double maximum) { + this.maximum = maximum; + } - @Override - public NumberSchema asNumberSchema() { return this; } + /** + * {@link NumberSchema#minimum} + * @param minimum the minimum to set + */ + public void setMinimum(Double minimum) { + this.minimum = minimum; + } } \ No newline at end of file diff --git a/src/main/java/com/fasterxml/jackson/databind/jsonschema/types/ObjectSchema.java b/src/main/java/com/fasterxml/jackson/databind/jsonschema/types/ObjectSchema.java index 9623408d92..74b672c084 100644 --- a/src/main/java/com/fasterxml/jackson/databind/jsonschema/types/ObjectSchema.java +++ b/src/main/java/com/fasterxml/jackson/databind/jsonschema/types/ObjectSchema.java @@ -1,5 +1,7 @@ package com.fasterxml.jackson.databind.jsonschema.types; +import java.util.ArrayList; +import java.util.HashMap; import java.util.List; import java.util.Map; @@ -7,200 +9,242 @@ import com.fasterxml.jackson.annotation.JsonValue; public class ObjectSchema extends ContainerTypeSchema { - - @JsonProperty(required = true) - public final String type = SchemaType.OBJECT.toString(); - + /** - * This attribute is an object with property definitions that define the - valid values of instance object property values. When the instance - value is an object, the property values of the instance object MUST - conform to the property definitions in this object. In this object, - each property definition's value MUST be a schema, and the property's - name MUST be the name of the instance property that it defines. The - instance property value MUST be valid according to the schema from - the property definition. Properties are considered unordered, the - order of the instance properties MAY be in any order. + * This attribute defines a schema for all properties that are not + * explicitly defined in an object type definition. If specified, the value + * MUST be a schema or a boolean. If false is provided, no additional + * properties are allowed beyond the properties defined in the schema. The + * default value is an empty schema which allows any value for additional + * properties. */ @JsonProperty - private Map properties; - public Schema putProperty(String name, Schema value) { - return properties.put(name, value); - } - public void putOptionalProperty(String name, Schema schema) { - // just don't put anything in the property list - } + private AdditionalProperties additionalProperties; + /** - * {@link ObjectSchema#properties} - * @param properties the properties to set + * This attribute is an object that defines the requirements of a property + * on an instance object. If an object instance has a property with the same + * name as a property in this attribute's object, then the instance must be + * valid against the attribute's property value */ - public void setProperties(Map properties) { - this.properties = properties; - } + @JsonProperty + private List dependencies; + /** - * {@link ObjectSchema#properties} - * @return the properties + * + This attribute is an object that defines the schema for a set of property + * names of an object instance. The name of each property of this + * attribute's object is a regular expression pattern in the ECMA 262/Perl 5 + * format, while the value is a schema. If the pattern matches the name of a + * property on the instance object, the value of the instance's property + * MUST be valid against the pattern name's schema value. */ - public Map getProperties() { - return properties; + @JsonProperty + private Map patternProperties; + + /** + * This attribute is an object with property definitions that define the + * valid values of instance object property values. When the instance value + * is an object, the property values of the instance object MUST conform to + * the property definitions in this object. In this object, each property + * definition's value MUST be a schema, and the property's name MUST be the + * name of the instance property that it defines. The instance property + * value MUST be valid according to the schema from the property definition. + * Properties are considered unordered, the order of the instance properties + * MAY be in any order. + */ + @JsonProperty + private Map properties; + + @JsonProperty(required = true) + public final SchemaType type = SchemaType.OBJECT; + + // instance initializer block + { + dependencies = new ArrayList(); + patternProperties = new HashMap(); + properties = new HashMap(); } - - + + public boolean addSchemaDependency(String depender, Schema parentMustMatch) { + return dependencies + .add(new SchemaDependency(depender, parentMustMatch)); + } + + public boolean addSimpleDependency(String depender, String dependsOn) { + return dependencies.add(new SimpleDependency(depender, dependsOn)); + } + + @Override + public ObjectSchema asObjectSchema() { + return this; + } + /** + * {@link ObjectSchema#additionalProperties} * - This attribute is an object that defines the schema for a set of - property names of an object instance. The name of each property of - this attribute's object is a regular expression pattern in the ECMA - 262/Perl 5 format, while the value is a schema. If the pattern - matches the name of a property on the instance object, the value of - the instance's property MUST be valid against the pattern name's - schema value. + * @return the additionalProperties */ - @JsonProperty - private Map patternProperties; - public Schema putPatternProperty(String regex, Schema value) { - return patternProperties.put(regex, value); + public AdditionalProperties getAdditionalProperties() { + return additionalProperties; } + /** - * {@link ObjectSchema#patternProperties} - * @param patternProperties the patternProperties to set + * {@link ObjectSchema#dependencies} + * + * @return the dependencies */ - public void setPatternProperties(Map patternProperties) { - this.patternProperties = patternProperties; + public List getDependencies() { + return dependencies; } + /** * {@link ObjectSchema#patternProperties} + * * @return the patternProperties */ public Map getPatternProperties() { return patternProperties; } - + /** - * This attribute defines a schema for all properties that are not - explicitly defined in an object type definition. If specified, the - value MUST be a schema or a boolean. If false is provided, no - additional properties are allowed beyond the properties defined in - the schema. The default value is an empty schema which allows any - value for additional properties. + * {@link ObjectSchema#properties} + * + * @return the properties */ - @JsonProperty - private AdditionalProperties additionalProperties; + public Map getProperties() { + return properties; + } + + @Override + public boolean isObjectSchema() { + return true; + } + + public void putOptionalProperty(String name, Schema schema) { + // just don't put anything in the property list + } + + public Schema putPatternProperty(String regex, Schema value) { + return patternProperties.put(regex, value); + } + + public Schema putProperty(String name, Schema value) { + return properties.put(name, value); + } + public void rejectAdditionalProperties() { additionalProperties = NoAdditionalProperties.instance; } + /** * {@link ObjectSchema#additionalProperties} - * @param additionalProperties the additionalProperties to set + * + * @param additionalProperties + * the additionalProperties to set */ public void setAdditionalProperties( AdditionalProperties additionalProperties) { this.additionalProperties = additionalProperties; } + /** - * {@link ObjectSchema#additionalProperties} - * @return the additionalProperties + * {@link ObjectSchema#dependencies} + * + * @param dependencies + * the dependencies to set */ - public AdditionalProperties getAdditionalProperties() { - return additionalProperties; + public void setDependencies(List dependencies) { + this.dependencies = dependencies; } - - public static abstract class AdditionalProperties {} + + /** + * {@link ObjectSchema#patternProperties} + * + * @param patternProperties + * the patternProperties to set + */ + public void setPatternProperties(Map patternProperties) { + this.patternProperties = patternProperties; + } + + /** + * {@link ObjectSchema#properties} + * + * @param properties + * the properties to set + */ + public void setProperties(Map properties) { + this.properties = properties; + } + + public static abstract class AdditionalProperties { + } + + public static abstract class Dependency { + } + public static class NoAdditionalProperties extends AdditionalProperties { - public static final NoAdditionalProperties instance = new NoAdditionalProperties(); - - protected NoAdditionalProperties() {} - + public final Boolean schema = false; + + protected NoAdditionalProperties() { + } + @JsonValue public Boolean value() { return schema; } - - public final Boolean schema = false; + + public static final NoAdditionalProperties instance = new NoAdditionalProperties(); } - public static class SchemaAdditionalProperties extends AdditionalProperties{ - + + public static class SchemaAdditionalProperties extends AdditionalProperties { + @JsonProperty private Schema schema; - + public SchemaAdditionalProperties(Schema schema) { this.schema = schema; } } - /** - * This attribute is an object that defines the requirements of a - property on an instance object. If an object instance has a property - with the same name as a property in this attribute's object, then the - instance must be valid against the attribute's property value - */ - @JsonProperty - private List dependencies; - /** - * {@link ObjectSchema#dependencies} - * @param dependencies the dependencies to set - */ - public void setDependencies(List dependencies) { - this.dependencies = dependencies; - } - /** - * {@link ObjectSchema#dependencies} - * @return the dependencies - */ - public List getDependencies() { - return dependencies; - } - - public boolean addSimpleDependency(String depender, String dependsOn) { - return dependencies.add(new SimpleDependency(depender, dependsOn)); - } - public boolean addSchemaDependency(String depender, Schema parentMustMatch) { - return dependencies.add(new SchemaDependency(depender, parentMustMatch)); - } - - public static abstract class Dependency {} /** - * Simple Dependency If the dependency value is a string, then the - instance object MUST have a property with the same name as the - dependency value. If the dependency value is an array of strings, - then the instance object MUST have a property with the same name - as each string in the dependency value's array. + * Schema Dependency If the dependency value is a schema, then the instance + * object MUST be valid against the schema. */ - public static class SimpleDependency extends Dependency { - + public static class SchemaDependency extends Dependency { + @JsonProperty(required = true) private String depender; - + @JsonProperty(required = true) - private String dependsOn; - - public SimpleDependency(String depender, String dependsOn) { + private Schema parentMustMatch; + + public SchemaDependency(String depender, Schema parentMustMatch) { this.depender = depender; - this.dependsOn = dependsOn; + this.parentMustMatch = parentMustMatch; } } - + /** - * Schema Dependency If the dependency value is a schema, then the - instance object MUST be valid against the schema. + * Simple Dependency If the dependency value is a string, then the instance + * object MUST have a property with the same name as the dependency value. + * If the dependency value is an array of strings, then the instance object + * MUST have a property with the same name as each string in the dependency + * value's array. */ - public static class SchemaDependency extends Dependency { - + public static class SimpleDependency extends Dependency { + @JsonProperty(required = true) private String depender; - + @JsonProperty(required = true) - private Schema parentMustMatch; - public SchemaDependency(String depender, Schema parentMustMatch) { + private String dependsOn; + + public SimpleDependency(String depender, String dependsOn) { this.depender = depender; - this.parentMustMatch = parentMustMatch; + this.dependsOn = dependsOn; } } - @Override - public boolean isObjectSchema() { return true ;} - - @Override - public ObjectSchema asObjectSchema() { return this; } - } \ No newline at end of file diff --git a/src/main/java/com/fasterxml/jackson/databind/jsonschema/types/Schema.java b/src/main/java/com/fasterxml/jackson/databind/jsonschema/types/Schema.java index 083ecdaaed..db50ec4ae9 100644 --- a/src/main/java/com/fasterxml/jackson/databind/jsonschema/types/Schema.java +++ b/src/main/java/com/fasterxml/jackson/databind/jsonschema/types/Schema.java @@ -1,295 +1,363 @@ package com.fasterxml.jackson.databind.jsonschema.types; - import com.fasterxml.jackson.annotation.JsonGetter; import com.fasterxml.jackson.annotation.JsonIgnore; import com.fasterxml.jackson.annotation.JsonProperty; import com.fasterxml.jackson.annotation.JsonSetter; /** - * Json Schema Draft - *
- JSON (JavaScript Object Notation) Schema defines the media type - "application/schema+json", a JSON based format for defining the - structure of JSON data. JSON Schema provides a contract for what - JSON data is required for a given application and how to interact - with it. JSON Schema is intended to define validation, - documentation, hyperlink navigation, and interaction control of JSON - data. -
- -
- JSON (JavaScript Object Notation) Schema is a JSON media type for - defining the structure of JSON data. JSON Schema provides a contract - for what JSON data is required for a given application and how to - interact with it. JSON Schema is intended to define validation, - documentation, hyperlink navigation, and interaction control of JSON - data. -
- - An example JSON Schema provided by the Schema draft: -
-	{
-	  "name":"Product",
-	  "properties":{
-	    "id":{
-	      "type":"number",
-	      "description":"Product identifier",
-	      "required":true
-	    },
-	    "name":{
-	      "description":"Name of the product",
-	      "type":"string",
-	      "required":true
-	    },
-	    "price":{
-	      "required":true,
-	      "type": "number",
-	      "minimum":0,
-	      "required":true
-	    },
-	    "tags":{
-	      "type":"array",
-	      "items":{
-	        "type":"string"
-	      }
-	    }
-	  },
-	  "links":[
-	    {
-	      "rel":"full",
-	      "href":"{id}"
-	    },
-	    {
-	      "rel":"comments",
-	      "href":"comments/?id={id}"
-	    }
-	  ]
-	}
-	
- + * Json Schema + * Draft
JSON (JavaScript Object Notation) Schema defines the + * media type "application/schema+json", a JSON based format for defining the + * structure of JSON data. JSON Schema provides a contract for what JSON data is + * required for a given application and how to interact with it. JSON Schema is + * intended to define validation, documentation, hyperlink navigation, and + * interaction control of JSON data.
+ * + *
JSON (JavaScript Object Notation) Schema is a JSON media type + * for defining the structure of JSON data. JSON Schema provides a contract for + * what JSON data is required for a given application and how to interact with + * it. JSON Schema is intended to define validation, documentation, hyperlink + * navigation, and interaction control of JSON data.
+ * + * An example JSON Schema provided by the Schema draft: + * + *
+ * 	{
+ * 	  "name":"Product",
+ * 	  "properties":{
+ * 	    "id":{
+ * 	      "type":"number",
+ * 	      "description":"Product identifier",
+ * 	      "required":true
+ * 	    },
+ * 	    "name":{
+ * 	      "description":"Name of the product",
+ * 	      "type":"string",
+ * 	      "required":true
+ * 	    },
+ * 	    "price":{
+ * 	      "required":true,
+ * 	      "type": "number",
+ * 	      "minimum":0,
+ * 	      "required":true
+ * 	    },
+ * 	    "tags":{
+ * 	      "type":"array",
+ * 	      "items":{
+ * 	        "type":"string"
+ * 	      }
+ * 	    }
+ * 	  },
+ * 	  "links":[
+ * 	    {
+ * 	      "rel":"full",
+ * 	      "href":"{id}"
+ * 	    },
+ * 	    {
+ * 	      "rel":"comments",
+ * 	      "href":"comments/?id={id}"
+ * 	    }
+ * 	  ]
+ * 	}
+ * 
+ * * @author jphelan */ -public abstract class Schema { - - public final SchemaType type = null; - - public SchemaType getType() { - return this.type; - } - +public abstract class Schema { + /** - * This attribute indicates if the instance must have a value, and not - be undefined. This is false by default, making the instance - optional. + * This attribute defines a URI of a schema that contains the full + * representation of this schema. When a validator encounters this + * attribute, it SHOULD replace the current schema with the schema + * referenced by the value's URI (if known and available) and re- validate + * the instance. This URI MAY be relative or absolute, and relative URIs + * SHOULD be resolved against the URI of the current schema. */ @JsonProperty - private Boolean required = false;// default = false; - /** - * {@link Schema#required} - * @param required the required to set - */ - public void setRequired(Boolean required) { - this.required = required; - } - /** - * {@link Schema#required} - * @return the required - */ - public Boolean getRequired() { - return required; - } + private String $ref; + /** - * This attribute defines the current URI of this schema (this attribute - is effectively a "self" link). This URI MAY be relative or absolute. - If the URI is relative it is resolved against the current URI of the - parent schema it is contained in. If this schema is not contained in - any parent schema, the current URI of the parent schema is held to be - the URI under which this schema was addressed. If id is missing, the - current URI of a schema is defined to be that of the parent schema. - The current URI of the schema is also used to construct relative - references such as for $ref. + * This attribute defines a URI of a JSON Schema that is the schema of the + * current schema. When this attribute is defined, a validator SHOULD use + * the schema referenced by the value's URI (if known and available) when + * resolving Hyper Schema (Section 6) links (Section 6.1). + * + * A validator MAY use this attribute's value to determine which version of + * JSON Schema the current schema is written in, and provide the appropriate + * validation features and behavior. Therefore, it is RECOMMENDED that all + * schema authors include this attribute in their schemas to prevent + * conflicts with future JSON Schema specification changes. */ @JsonProperty - private String id; + private String $schema; + /** - * {@link Schema#id} - * @param id the id to set + * This attribute takes the same values as the "type" attribute, however if + * the instance matches the type or if this value is an array and the + * instance matches any type or schema in the array, then this instance is + * not valid. */ - public void setId(String id) { - this.id = id; - } + @JsonProperty + private Schema[] disallow; /** - * {@link Schema#id} - * @return the id + * The value of this property MUST be another schema which will provide a + * base schema which the current schema will inherit from. The inheritance + * rules are such that any instance that is valid according to the current + * schema MUST be valid according to the referenced schema. This MAY also be + * an array, in which case, the instance MUST be valid for all the schemas + * in the array. A schema that extends another schema MAY define additional + * attributes, constrain existing attributes, or add other constraints. + * + * Conceptually, the behavior of extends can be seen as validating an + * instance against all constraints in the extending schema as well as the + * extended schema(s). More optimized implementations that merge schemas are + * possible, but are not required. An example of using "extends": + * + * { "description":"An adult", "properties":{"age":{"minimum": 21}}, + * "extends":"person" } { "description":"Extended schema", + * "properties":{"deprecated":{"type": "boolean"}}, + * "extends":"http://json-schema.org/draft-03/schema" } */ - public String getId() { - return id; - } + @JsonIgnore + private Schema[] extendsextends; /** - * This attribute defines a URI of a schema that contains the full - representation of this schema. When a validator encounters this - attribute, it SHOULD replace the current schema with the schema - referenced by the value's URI (if known and available) and re- - validate the instance. This URI MAY be relative or absolute, and - relative URIs SHOULD be resolved against the URI of the current - schema. + * This attribute defines the current URI of this schema (this attribute is + * effectively a "self" link). This URI MAY be relative or absolute. If the + * URI is relative it is resolved against the current URI of the parent + * schema it is contained in. If this schema is not contained in any parent + * schema, the current URI of the parent schema is held to be the URI under + * which this schema was addressed. If id is missing, the current URI of a + * schema is defined to be that of the parent schema. The current URI of the + * schema is also used to construct relative references such as for $ref. */ @JsonProperty - private String $ref; + private String id; /** - * {@link Schema#$ref} - * @param $ref the $ref to set + * This attribute indicates if the instance must have a value, and not be + * undefined. This is false by default, making the instance optional. */ - public void set$ref(String $ref) { - this.$ref = $ref; + @JsonProperty + private Boolean required = false;// default = false; + + @JsonProperty(required = true) + public final SchemaType type = null; + + public AnySchema asAnySchema() { + return null; + } + + public ArraySchema asArraySchema() { + return null; + } + + public BooleanSchema asBooleanSchema() { + return null; + } + + public ContainerTypeSchema asContainerSchema() { + return null; + } + + public IntegerSchema asIntegerSchema() { + return null; + } + + public NullSchema asNullSchema() { + return null; + } + + public NumberSchema asNumberSchema() { + return null; + } + + public ObjectSchema asObjectSchema() { + return null; + } + + public SimpleTypeSchema asSimpleTypeSchema() { + return null; + } + + public StringSchema asStringSchema() { + return null; + } + + public UnionTypeSchema asUnionTypeSchema() { + return null; } + + public ValueTypeSchema asValueSchemaSchema() { + return null; + } + /** * {@link Schema#$ref} + * * @return the $ref */ public String get$ref() { return $ref; } - /** - * This attribute defines a URI of a JSON Schema that is the schema of - the current schema. When this attribute is defined, a validator - SHOULD use the schema referenced by the value's URI (if known and - available) when resolving Hyper Schema (Section 6) links - (Section 6.1). - - A validator MAY use this attribute's value to determine which version - of JSON Schema the current schema is written in, and provide the - appropriate validation features and behavior. Therefore, it is - RECOMMENDED that all schema authors include this attribute in their - schemas to prevent conflicts with future JSON Schema specification - changes. - */ - @JsonProperty - private String $schema; - /** - * {@link Schema#$schema} - * @param $schema the $schema to set - */ - public void set$schema(String $schema) { - this.$schema = $schema; - } /** * {@link Schema#$schema} + * * @return the $schema */ public String get$schema() { return $schema; } + /** - * The value of this property MUST be another schema which will provide - a base schema which the current schema will inherit from. The - inheritance rules are such that any instance that is valid according - to the current schema MUST be valid according to the referenced - schema. This MAY also be an array, in which case, the instance MUST - be valid for all the schemas in the array. A schema that extends - another schema MAY define additional attributes, constrain existing - attributes, or add other constraints. - - Conceptually, the behavior of extends can be seen as validating an - instance against all constraints in the extending schema as well as - the extended schema(s). More optimized implementations that merge - schemas are possible, but are not required. An example of using - "extends": - - { - "description":"An adult", - "properties":{"age":{"minimum": 21}}, - "extends":"person" - } - { - "description":"Extended schema", - "properties":{"deprecated":{"type": "boolean"}}, - "extends":"http://json-schema.org/draft-03/schema" - } - */ - @JsonIgnore - private Schema[] extendsextends; - /** - * {@link Schema#extendsextends} - * @param extendsextends the extendsextends to set + * {@link Schema#disallow} + * + * @return the disallow */ - @JsonSetter("extends") - public void setExtends(Schema[] extendsextends) { - this.extendsextends = extendsextends; + public Schema[] getDisallow() { + return disallow; } + /** * {@link Schema#extendsextends} + * * @return the extendsextends */ @JsonGetter("extends") public Schema[] getExtends() { return extendsextends; } + /** - * This attribute takes the same values as the "type" attribute, however - if the instance matches the type or if this value is an array and the - instance matches any type or schema in the array, then this instance - is not valid. + * {@link Schema#id} + * + * @return the id */ - @JsonProperty - private Schema[] disallow; - + public String getId() { + return id; + } + + /** + * {@link Schema#required} + * + * @return the required + */ + public Boolean getRequired() { + return required; + } + + public SchemaType getType() { + return this.type; + } + + public boolean isAnySchema() { + return false; + } + + public boolean isArraySchema() { + return false; + } + + public boolean isBooleanSchema() { + return false; + } + + public boolean isContainerTypeSchema() { + return false; + } + + public boolean isIntegerSchema() { + return false; + } + + public boolean isNullSchema() { + return false; + } + + public boolean isNumberSchema() { + return false; + } + + public boolean isObjectSchema() { + return false; + } + + public boolean isSimpleTypeSchema() { + return false; + } + + public boolean isStringSchema() { + return false; + } + + public boolean isUnionTypeSchema() { + return false; + } + + public boolean isValueTypeSchema() { + return false; + } + + /** + * {@link Schema#$ref} + * + * @param $ref + * the $ref to set + */ + public void set$ref(String $ref) { + this.$ref = $ref; + } + + /** + * {@link Schema#$schema} + * + * @param $schema + * the $schema to set + */ + public void set$schema(String $schema) { + this.$schema = $schema; + } + /** * {@link Schema#disallow} - * @param disallow the disallow to set + * + * @param disallow + * the disallow to set */ public void setDisallow(Schema[] disallow) { this.disallow = disallow; } + /** - * {@link Schema#disallow} - * @return the disallow + * {@link Schema#extendsextends} + * + * @param extendsextends + * the extendsextends to set */ - public Schema[] getDisallow() { - return disallow; + @JsonSetter("extends") + public void setExtends(Schema[] extendsextends) { + this.extendsextends = extendsextends; } - //subtype oracles - - public boolean isUnionTypeSchema() { return false; } - - public boolean isSimpleTypeSchema() { return false; } - - public boolean isNullSchema() { return false; } - public boolean isAnySchema() { return false; } - - public boolean isContainerTypeSchema() { return false; } - public boolean isArraySchema() { return false; } - public boolean isObjectSchema() { return false; } - - public boolean isValueTypeSchema() { return false; } - public boolean isBooleanSchema() { return false; } - public boolean isIntegerSchema() { return false; } - public boolean isNumberSchema() { return false; } - public boolean isStringSchema() { return false; } - - // subtype retrievers: - - public UnionTypeSchema asUnionTypeSchema() { return null; } - - public SimpleTypeSchema asSimpleTypeSchema() { return null; } - - public NullSchema asNullSchema() { return null; } - public AnySchema asAnySchema() { return null; } - - public ContainerTypeSchema asContainerSchema() { return null; } - public ArraySchema asArraySchema() { return null; } - public ObjectSchema asObjectSchema() { return null; } - - public ValueTypeSchema asValueSchemaSchema() { return null; } - public BooleanSchema asBooleanSchema() { return null; } - public IntegerSchema asIntegerSchema() { return null; } - public NumberSchema asNumberSchema() { return null; } - public StringSchema asStringSchema() { return null; } - - + /** + * {@link Schema#id} + * + * @param id + * the id to set + */ + public void setId(String id) { + this.id = id; + } + + /** + * {@link Schema#required} + * + * @param required + * the required to set + */ + public void setRequired(Boolean required) { + this.required = required; + } public static Schema minimalForFormat(SchemaType format) { switch (format) { @@ -304,7 +372,7 @@ public static Schema minimalForFormat(SchemaType format) { case NUMBER: return new NumberSchema(); case STRING: - return new StringSchema(); + return new StringSchema(); case NULL: return new NullSchema(); diff --git a/src/main/java/com/fasterxml/jackson/databind/jsonschema/types/SimpleTypeSchema.java b/src/main/java/com/fasterxml/jackson/databind/jsonschema/types/SimpleTypeSchema.java index b2084b95be..80190efcab 100644 --- a/src/main/java/com/fasterxml/jackson/databind/jsonschema/types/SimpleTypeSchema.java +++ b/src/main/java/com/fasterxml/jackson/databind/jsonschema/types/SimpleTypeSchema.java @@ -6,76 +6,92 @@ import com.fasterxml.jackson.annotation.JsonSetter; public abstract class SimpleTypeSchema extends Schema { - /** * This attribute defines the default value of the instance when the - instance is undefined. + * instance is undefined. */ @JsonIgnore private String defaultdefault; /** - * {@link SimpleTypeSchema#defaultdefault} - * @param defaultdefault the defaultdefault to set + * This attribute is a string that provides a full description of the of + * purpose the instance property. */ - @JsonSetter("default") - public void setDefault(String defaultdefault) { - this.defaultdefault = defaultdefault; + @JsonProperty + private String description; + /** + * This attribute is a string that provides a short description of the + * instance property. + */ + @JsonProperty + private String title; + + @Override + public SimpleTypeSchema asSimpleTypeSchema() { + return this; } + /** * {@link SimpleTypeSchema#defaultdefault} + * * @return the defaultdefault */ @JsonGetter("default") public String getDefault() { return defaultdefault; } - - /** - * This attribute is a string that provides a short description of the - instance property. - */ - @JsonProperty - private String title; + /** - * {@link SimpleTypeSchema#title} - * @param title the title to set + * {@link SimpleTypeSchema#description} + * + * @return the description */ - public void setTitle(String title) { - this.title = title; + public String getDescription() { + return description; } + /** * {@link SimpleTypeSchema#title} + * * @return the title */ public String getTitle() { return title; } - + + @Override + public boolean isSimpleTypeSchema() { + return true; + } + /** - * This attribute is a string that provides a full description of the of - purpose the instance property. + * {@link SimpleTypeSchema#defaultdefault} + * + * @param defaultdefault + * the defaultdefault to set */ - @JsonProperty - private String description; + @JsonSetter("default") + public void setDefault(String defaultdefault) { + this.defaultdefault = defaultdefault; + } + /** * {@link SimpleTypeSchema#description} - * @param description the description to set + * + * @param description + * the description to set */ public void setDescription(String description) { this.description = description; } + /** - * {@link SimpleTypeSchema#description} - * @return the description + * {@link SimpleTypeSchema#title} + * + * @param title + * the title to set */ - public String getDescription() { - return description; + public void setTitle(String title) { + this.title = title; } - - @Override - public boolean isSimpleTypeSchema() { return true; } - - @Override - public SimpleTypeSchema asSimpleTypeSchema() { return this; } } \ No newline at end of file diff --git a/src/main/java/com/fasterxml/jackson/databind/jsonschema/types/StringSchema.java b/src/main/java/com/fasterxml/jackson/databind/jsonschema/types/StringSchema.java index 6faa7d9f52..3b872176ee 100644 --- a/src/main/java/com/fasterxml/jackson/databind/jsonschema/types/StringSchema.java +++ b/src/main/java/com/fasterxml/jackson/databind/jsonschema/types/StringSchema.java @@ -3,72 +3,89 @@ import com.fasterxml.jackson.annotation.JsonProperty; public class StringSchema extends ValueTypeSchema { + + /** this defines the maximum length of the string. */ + @JsonProperty + private Integer maxLength; + + /** this defines the minimum length of the string. */ + @JsonProperty + private Integer minLength; + /** + * this provides a regular expression that a string instance MUST match in + * order to be valid. Regular expressions SHOULD follow the regular + * expression specification from ECMA 262/Perl 5 + */ + @JsonProperty + private String pattern; @JsonProperty(required = true) public final SchemaType type = SchemaType.STRING; - + + @Override + public StringSchema asStringSchema() { + return this; + } + /** - * this provides a regular - expression that a string instance MUST match in order to be valid. - Regular expressions SHOULD follow the regular expression - specification from ECMA 262/Perl 5 + * {@link StringSchema#maxLength} + * + * @return the maxLength */ - @JsonProperty - private String pattern; + public Integer getMaxLength() { + return maxLength; + } + /** - * {@link StringSchema#pattern} - * @param pattern the pattern to set + * {@link StringSchema#minLength} + * + * @return the minLength */ - public void setPattern(String pattern) { - this.pattern = pattern; + public Integer getMinLength() { + return minLength; } + /** * {@link StringSchema#pattern} + * * @return the pattern */ public String getPattern() { return pattern; } - - /**this defines the minimum length of the string.*/ - @JsonProperty - private Integer minLength; - /** - * {@link StringSchema#minLength} - * @param minLength the minLength to set - */ - public void setMinLength(Integer minLength) { - this.minLength = minLength; - } - /** - * {@link StringSchema#minLength} - * @return the minLength - */ - public Integer getMinLength() { - return minLength; + + @Override + public boolean isStringSchema() { + return true; } - - /**this defines the maximum length of the string.*/ - @JsonProperty - private Integer maxLength; + /** * {@link StringSchema#maxLength} - * @param maxLength the maxLength to set + * + * @param maxLength + * the maxLength to set */ public void setMaxLength(Integer maxLength) { this.maxLength = maxLength; } + /** - * {@link StringSchema#maxLength} - * @return the maxLength + * {@link StringSchema#minLength} + * + * @param minLength + * the minLength to set */ - public Integer getMaxLength() { - return maxLength; + public void setMinLength(Integer minLength) { + this.minLength = minLength; + } + + /** + * {@link StringSchema#pattern} + * + * @param pattern + * the pattern to set + */ + public void setPattern(String pattern) { + this.pattern = pattern; } - - @Override - public boolean isStringSchema() { return true; } - - @Override - public StringSchema asStringSchema() { return this; } } diff --git a/src/main/java/com/fasterxml/jackson/databind/jsonschema/types/UnionTypeSchema.java b/src/main/java/com/fasterxml/jackson/databind/jsonschema/types/UnionTypeSchema.java index 831ee7d57c..6a9c7a736e 100644 --- a/src/main/java/com/fasterxml/jackson/databind/jsonschema/types/UnionTypeSchema.java +++ b/src/main/java/com/fasterxml/jackson/databind/jsonschema/types/UnionTypeSchema.java @@ -3,28 +3,37 @@ import com.fasterxml.jackson.annotation.JsonProperty; public class UnionTypeSchema extends Schema { - + @JsonProperty private ValueTypeSchema[] elements; - /** - * {@link UnionTypeSchema#elements} - * @param elements the elements to set - */ - public void setElements(ValueTypeSchema[] elements) { - assert elements.length >= 2 : "Union Type Schemas must contain two or more Simple Type Schemas" ; - this.elements = elements; + + @Override + public UnionTypeSchema asUnionTypeSchema() { + return this; } + /** * {@link UnionTypeSchema#elements} + * * @return the elements */ public ValueTypeSchema[] getElements() { return elements; } - - @Override - public UnionTypeSchema asUnionTypeSchema() { return this; } - + @Override - public boolean isUnionTypeSchema() { return true; } + public boolean isUnionTypeSchema() { + return true; + } + + /** + * {@link UnionTypeSchema#elements} + * + * @param elements + * the elements to set + */ + public void setElements(ValueTypeSchema[] elements) { + assert elements.length >= 2 : "Union Type Schemas must contain two or more Simple Type Schemas"; + this.elements = elements; + } } \ No newline at end of file diff --git a/src/main/java/com/fasterxml/jackson/databind/jsonschema/types/ValueTypeSchema.java b/src/main/java/com/fasterxml/jackson/databind/jsonschema/types/ValueTypeSchema.java index ad133c6481..9a41ea72f6 100644 --- a/src/main/java/com/fasterxml/jackson/databind/jsonschema/types/ValueTypeSchema.java +++ b/src/main/java/com/fasterxml/jackson/databind/jsonschema/types/ValueTypeSchema.java @@ -1,5 +1,6 @@ package com.fasterxml.jackson.databind.jsonschema.types; +import java.util.HashSet; import java.util.Set; import com.fasterxml.jackson.annotation.JsonProperty; @@ -10,25 +11,47 @@ public abstract class ValueTypeSchema extends SimpleTypeSchema { /** - * This property defines the type of data, content type, or microformat - to be expected in the instance property values. A format attribute - MAY be one of the values listed below, and if so, SHOULD adhere to - the semantics describing for the format. A format SHOULD only be - used to give meaning to primitive types (string, integer, number, or - boolean). Validators MAY (but are not required to) validate that the - instance values conform to a format. - - Additional custom formats MAY be created. These custom formats MAY - be expressed as an URI, and this URI MAY reference a schema of that + * This provides an enumeration of all possible values that are valid + for the instance property. This MUST be an array, and each item in + the array represents a possible value for the instance value. If + this attribute is defined, the instance value MUST be one of the + values in the array in order for the schema to be valid. Comparison + of enum values uses the same algorithm as defined in "uniqueItems" + (Section 5.15). + */ + @JsonProperty + private Set enums; + + /** + * This property defines the type of data, content type, or microformat to + * be expected in the instance property values. A format attribute MAY be + * one of the values listed below, and if so, SHOULD adhere to the semantics + * describing for the format. A format SHOULD only be used to give meaning + * to primitive types (string, integer, number, or boolean). Validators MAY + * (but are not required to) validate that the instance values conform to a + * format. + * + * Additional custom formats MAY be created. These custom formats MAY be + * expressed as an URI, and this URI MAY reference a schema of that */ @JsonProperty private JsonValueFormat format; + + //instance initializer block + { + enums = new HashSet(); + } + + @Override + public ValueTypeSchema asValueSchemaSchema() { return this; } + + /** - * {@link ValueTypeSchema#format} - * @param format the format to set + * {@link ValueTypeSchema#enums} + * @return the enums */ - public void setFormat(JsonValueFormat format) { - this.format = format; + public Set getEnums() { + return enums; } /** * {@link ValueTypeSchema#format} @@ -37,19 +60,9 @@ public void setFormat(JsonValueFormat format) { public JsonValueFormat getFormat() { return format; } - + @Override + public boolean isValueTypeSchema() { return true; } - /** - * This provides an enumeration of all possible values that are valid - for the instance property. This MUST be an array, and each item in - the array represents a possible value for the instance value. If - this attribute is defined, the instance value MUST be one of the - values in the array in order for the schema to be valid. Comparison - of enum values uses the same algorithm as defined in "uniqueItems" - (Section 5.15). - */ - @JsonProperty - private Set enums; /** * {@link ValueTypeSchema#enums} * @param enums the enums to set @@ -57,17 +70,12 @@ of enum values uses the same algorithm as defined in "uniqueItems" public void setEnums(Set enums) { this.enums = enums; } + /** - * {@link ValueTypeSchema#enums} - * @return the enums + * {@link ValueTypeSchema#format} + * @param format the format to set */ - public Set getEnums() { - return enums; + public void setFormat(JsonValueFormat format) { + this.format = format; } - - @Override - public boolean isValueTypeSchema() { return true; } - - @Override - public ValueTypeSchema asValueSchemaSchema() { return this; } } \ No newline at end of file diff --git a/src/test/java/com/fasterxml/jackson/databind/jsonschema/TestGenerateJsonSchema.java b/src/test/java/com/fasterxml/jackson/databind/jsonschema/TestGenerateJsonSchema.java index 9321cb141f..b70ca7126b 100644 --- a/src/test/java/com/fasterxml/jackson/databind/jsonschema/TestGenerateJsonSchema.java +++ b/src/test/java/com/fasterxml/jackson/databind/jsonschema/TestGenerateJsonSchema.java @@ -9,6 +9,7 @@ import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.databind.jsonschema.types.Schema; import com.fasterxml.jackson.databind.node.ObjectNode; +import com.fasterxml.jackson.databind.ser.DefaultSerializerProvider; import com.fasterxml.jackson.databind.ser.FilterProvider; import com.fasterxml.jackson.databind.ser.impl.SimpleBeanPropertyFilter; import com.fasterxml.jackson.databind.ser.impl.SimpleFilterProvider; @@ -108,7 +109,10 @@ public class BeanWithId { public void testGeneratingJsonSchema() throws Exception { - Schema jsonSchema = MAPPER.generateJsonSchema(SimpleBean.class); + DefaultSerializerProvider sp = new DefaultSerializerProvider.Impl(); + ObjectMapper m = new ObjectMapper(); + m.setSerializerProvider(sp); + Schema jsonSchema = m.generateJsonSchema(SimpleBean.class); assertNotNull(jsonSchema); From 65e5dda18f2bda323885faf66873b5b3a78e3b36 Mon Sep 17 00:00:00 2001 From: jackphel Date: Thu, 2 Aug 2012 17:57:00 -0400 Subject: [PATCH 05/19] working, but passed type information isn't precise enough for collection as array --- .../jsonschema/types/ArraySchema.java | 49 +++++++++++- .../jsonschema/types/ObjectSchema.java | 4 +- .../ser/DefaultSerializerProvider.java | 5 -- .../databind/ser/std/BeanSerializerBase.java | 8 +- .../jsonschema/TestGenerateJsonSchema.java | 78 ++++++++++++------- 5 files changed, 106 insertions(+), 38 deletions(-) diff --git a/src/main/java/com/fasterxml/jackson/databind/jsonschema/types/ArraySchema.java b/src/main/java/com/fasterxml/jackson/databind/jsonschema/types/ArraySchema.java index ce466ee9f7..c911604c99 100644 --- a/src/main/java/com/fasterxml/jackson/databind/jsonschema/types/ArraySchema.java +++ b/src/main/java/com/fasterxml/jackson/databind/jsonschema/types/ArraySchema.java @@ -146,6 +146,18 @@ public static abstract class AdditionalItems {} public static class ArrayItems extends ArraySchema.Items { @JsonProperty private Schema[] schemas; + + /* (non-Javadoc) + * @see com.fasterxml.jackson.databind.jsonschema.types.ArraySchema.Items#isArrayItems() + */ + @Override + public boolean isArrayItems() { return true; } + + /* (non-Javadoc) + * @see com.fasterxml.jackson.databind.jsonschema.types.ArraySchema.Items#asArrayItems() + */ + @Override + public ArrayItems asArrayItems() { return this; } } /** @@ -153,7 +165,13 @@ public static class ArrayItems extends ArraySchema.Items { MUST be a schema or an array of schemas. The default value is an empty schema which allows any value for items in the instance array. */ - public static abstract class Items {} + public static abstract class Items { + public boolean isSingleItems() { return false; } + public boolean isArrayItems() { return false; } + + public SingleItems asSingleItems() { return null; } + public ArrayItems asArrayItems() { return null; } + } /** * This can be false @@ -182,8 +200,37 @@ public static class SchemaAdditionalItems { public static class SingleItems extends ArraySchema.Items { @JsonProperty private Schema schema; + public SingleItems(Schema schema) { this.schema = schema; } + + /** + * {@link ArraySchema.SingleItems#schema} + * @return the schema + */ + public Schema getSchema() { + return schema; + } + + /** + * {@link ArraySchema.SingleItems#schema} + * @param schema the schema to set + */ + public void setSchema(Schema schema) { + this.schema = schema; + } + + /* (non-Javadoc) + * @see com.fasterxml.jackson.databind.jsonschema.types.ArraySchema.Items#isSingleItems() + */ + @Override + public boolean isSingleItems() { return true; } + + /* (non-Javadoc) + * @see com.fasterxml.jackson.databind.jsonschema.types.ArraySchema.Items#asSingleItems() + */ + @Override + public SingleItems asSingleItems() { return this; } } } \ No newline at end of file diff --git a/src/main/java/com/fasterxml/jackson/databind/jsonschema/types/ObjectSchema.java b/src/main/java/com/fasterxml/jackson/databind/jsonschema/types/ObjectSchema.java index 74b672c084..1eb323b9f3 100644 --- a/src/main/java/com/fasterxml/jackson/databind/jsonschema/types/ObjectSchema.java +++ b/src/main/java/com/fasterxml/jackson/databind/jsonschema/types/ObjectSchema.java @@ -122,7 +122,8 @@ public boolean isObjectSchema() { } public void putOptionalProperty(String name, Schema schema) { - // just don't put anything in the property list + schema.setRequired(false); + properties.put(name, schema); } public Schema putPatternProperty(String regex, Schema value) { @@ -130,6 +131,7 @@ public Schema putPatternProperty(String regex, Schema value) { } public Schema putProperty(String name, Schema value) { + value.setRequired(true); return properties.put(name, value); } diff --git a/src/main/java/com/fasterxml/jackson/databind/ser/DefaultSerializerProvider.java b/src/main/java/com/fasterxml/jackson/databind/ser/DefaultSerializerProvider.java index 952e7f5733..8a471bea33 100644 --- a/src/main/java/com/fasterxml/jackson/databind/ser/DefaultSerializerProvider.java +++ b/src/main/java/com/fasterxml/jackson/databind/ser/DefaultSerializerProvider.java @@ -13,13 +13,8 @@ import com.fasterxml.jackson.databind.cfg.HandlerInstantiator; import com.fasterxml.jackson.databind.introspect.Annotated; import com.fasterxml.jackson.databind.introspect.ObjectIdInfo; -import com.fasterxml.jackson.databind.jsonschema.JsonSchema; import com.fasterxml.jackson.databind.jsonschema.SchemaAware; -import com.fasterxml.jackson.databind.jsonschema.factories.SchemaFactory; -import com.fasterxml.jackson.databind.jsonschema.types.Schema; -import com.fasterxml.jackson.databind.jsonschema.types.SchemaType; import com.fasterxml.jackson.databind.jsonschema.visitors.JsonFormatVisitor; -import com.fasterxml.jackson.databind.node.ObjectNode; import com.fasterxml.jackson.databind.ser.impl.WritableObjectId; import com.fasterxml.jackson.databind.util.ClassUtil; diff --git a/src/main/java/com/fasterxml/jackson/databind/ser/std/BeanSerializerBase.java b/src/main/java/com/fasterxml/jackson/databind/ser/std/BeanSerializerBase.java index 2877aade5b..eac8280b74 100644 --- a/src/main/java/com/fasterxml/jackson/databind/ser/std/BeanSerializerBase.java +++ b/src/main/java/com/fasterxml/jackson/databind/ser/std/BeanSerializerBase.java @@ -672,11 +672,11 @@ public void acceptJsonFormatVisitor(JsonFormatVisitor visitor, Type typeHint) * @param propertiesNode Node which the given property would exist within */ public static void depositSchemaProperty(BeanPropertyWriter writer, JsonObjectFormatVisitor objectVisitor) { - //if (isPropertyRequired(writer, objectVisitor.getProvider())) { + if (isPropertyRequired(writer, objectVisitor.getProvider())) { objectVisitor.property(writer); - //} else { - //objectVisitor.optionalProperty(writer); - //} + } else { + objectVisitor.optionalProperty(writer); + } } /** diff --git a/src/test/java/com/fasterxml/jackson/databind/jsonschema/TestGenerateJsonSchema.java b/src/test/java/com/fasterxml/jackson/databind/jsonschema/TestGenerateJsonSchema.java index b70ca7126b..234f88b92b 100644 --- a/src/test/java/com/fasterxml/jackson/databind/jsonschema/TestGenerateJsonSchema.java +++ b/src/test/java/com/fasterxml/jackson/databind/jsonschema/TestGenerateJsonSchema.java @@ -7,7 +7,9 @@ import com.fasterxml.jackson.annotation.JsonProperty; import com.fasterxml.jackson.databind.JsonNode; import com.fasterxml.jackson.databind.ObjectMapper; +import com.fasterxml.jackson.databind.jsonschema.types.ObjectSchema; import com.fasterxml.jackson.databind.jsonschema.types.Schema; +import com.fasterxml.jackson.databind.jsonschema.types.ArraySchema.Items; import com.fasterxml.jackson.databind.node.ObjectNode; import com.fasterxml.jackson.databind.ser.DefaultSerializerProvider; import com.fasterxml.jackson.databind.ser.FilterProvider; @@ -32,7 +34,7 @@ public static class SimpleBean private String property2; private String[] property3; private Collection property4; - @JsonProperty(required=true) + @JsonProperty(required = true) private String property5; public int getProperty1() @@ -90,7 +92,7 @@ public class TrivialBean { public String name; } - @JsonSerializableSchema(id="myType") + //@JsonSerializableSchema(id="myType") public class BeanWithId { public String value; } @@ -112,34 +114,56 @@ public void testGeneratingJsonSchema() DefaultSerializerProvider sp = new DefaultSerializerProvider.Impl(); ObjectMapper m = new ObjectMapper(); m.setSerializerProvider(sp); - Schema jsonSchema = m.generateJsonSchema(SimpleBean.class); + Schema schema = m.generateJsonSchema(SimpleBean.class); - assertNotNull(jsonSchema); + assertNotNull(schema); // test basic equality, and that equals() handles null, other obs - assertTrue(jsonSchema.equals(jsonSchema)); - assertFalse(jsonSchema.equals(null)); - assertFalse(jsonSchema.equals("foo")); - - // other basic things - assertNotNull(jsonSchema.toString()); - assertNotNull(JsonSchema.getDefaultSchemaNode()); - -// ObjectNode root = jsonSchema.getSchemaNode(); -// assertEquals("object", root.get("type").asText()); -// assertEquals(false, root.path("required").booleanValue()); -// JsonNode propertiesSchema = root.get("properties"); -// assertNotNull(propertiesSchema); -// JsonNode property1Schema = propertiesSchema.get("property1"); -// assertNotNull(property1Schema); -// assertEquals("integer", property1Schema.get("type").asText()); -// assertEquals(false, property1Schema.path("required").booleanValue()); -// JsonNode property2Schema = propertiesSchema.get("property2"); -// assertNotNull(property2Schema); -// assertEquals("string", property2Schema.get("type").asText()); -// assertEquals(false, property2Schema.path("required").booleanValue()); -// JsonNode property3Schema = propertiesSchema.get("property3"); -// assertNotNull(property3Schema); + assertTrue(schema.equals(schema)); + assertFalse(schema.equals(null)); + assertFalse(schema.equals("foo")); + + assertTrue(schema.isObjectSchema()); + ObjectSchema object = schema.asObjectSchema(); + assertNotNull(object); + Map properties = object.getProperties(); + assertNotNull(properties); + Schema prop1 = properties.get("property1"); + assertNotNull(prop1); + assertTrue(prop1.isIntegerSchema()); + assertFalse(prop1.getRequired()); + + Schema prop2 = properties.get("property2"); + assertNotNull(prop2); + assertTrue(prop2.isStringSchema()); + assertFalse(prop2.getRequired()); + + Schema prop3 = properties.get("property3"); + assertNotNull(prop3); + assertTrue(prop3.isArraySchema()); + assertFalse(prop3.getRequired()); + Items items = prop3.asArraySchema().getItems(); + assertTrue(items.isSingleItems()); + Schema itemType = items.asSingleItems().getSchema(); + assertNotNull(itemType); + assertTrue(itemType.isStringSchema()); + + Schema prop4 = properties.get("property4"); + assertNotNull(prop4); + assertTrue(prop4.isArraySchema()); + assertFalse(prop4.getRequired()); + items = prop4.asArraySchema().getItems(); + assertTrue(items.isSingleItems()); + itemType = items.asSingleItems().getSchema(); + assertNotNull(itemType); + assertTrue(itemType.isNumberSchema()); + + Schema prop5 = properties.get("property5"); + assertNotNull(prop5); + assertTrue(prop5.getRequired()); + + + // assertEquals("array", property3Schema.get("type").asText()); // assertEquals(false, property3Schema.path("required").booleanValue()); // assertEquals("string", property3Schema.get("items").get("type").asText()); From 7fd884e4f7b0f02942fd425080e50f24fd6dfdfa Mon Sep 17 00:00:00 2001 From: jackphel Date: Thu, 2 Aug 2012 19:46:09 -0400 Subject: [PATCH 06/19] jsonFormatVisitor/acceptor now passes/accepts typeHint of JavaType, but some access is formatted incorrectly or, less likely, there is a bug in jackson. --- .../jackson/databind/ObjectMapper.java | 2 +- .../databind/ext/CoreXMLSerializers.java | 4 +- .../jackson/databind/ext/DOMSerializer.java | 4 +- .../databind/jsonschema/SchemaAware.java | 4 +- .../factories/ObjectSchemaFactory.java | 39 +++++++++---------- .../jsonschema/factories/SchemaFactory.java | 6 +-- .../visitors/JsonFormatVisitor.java | 6 +-- .../visitors/JsonObjectFormatVisitor.java | 6 +-- .../ser/DefaultSerializerProvider.java | 2 +- .../databind/ser/impl/FailingSerializer.java | 4 +- .../ser/impl/StringArraySerializer.java | 3 +- .../databind/ser/impl/UnknownSerializer.java | 3 +- .../ser/std/AsArraySerializerBase.java | 7 ++-- .../databind/ser/std/BeanSerializerBase.java | 6 +-- .../databind/ser/std/BooleanSerializer.java | 4 +- .../ser/std/DateTimeSerializerBase.java | 3 +- .../databind/ser/std/EnumMapSerializer.java | 5 ++- .../databind/ser/std/EnumSerializer.java | 6 +-- .../databind/ser/std/JsonValueSerializer.java | 3 +- .../databind/ser/std/MapSerializer.java | 3 +- .../databind/ser/std/NullSerializer.java | 3 +- .../databind/ser/std/NumberSerializers.java | 13 +++---- .../ser/std/ObjectArraySerializer.java | 5 +-- .../databind/ser/std/RawSerializer.java | 3 +- .../ser/std/SerializableSerializer.java | 10 ++--- .../databind/ser/std/SqlDateSerializer.java | 4 +- .../databind/ser/std/SqlTimeSerializer.java | 4 +- .../ser/std/StaticListSerializerBase.java | 4 +- .../databind/ser/std/StdArraySerializers.java | 33 ++++++++-------- .../databind/ser/std/StdJdkSerializers.java | 13 +++---- .../databind/ser/std/StdKeySerializer.java | 4 +- .../databind/ser/std/StdScalarSerializer.java | 4 +- .../databind/ser/std/StdSerializer.java | 3 +- .../databind/ser/std/StringSerializer.java | 4 +- .../databind/ser/std/ToStringSerializer.java | 4 +- .../ser/std/TokenBufferSerializer.java | 4 +- .../databind/module/TestSimpleModule.java | 5 +-- 37 files changed, 111 insertions(+), 129 deletions(-) diff --git a/src/main/java/com/fasterxml/jackson/databind/ObjectMapper.java b/src/main/java/com/fasterxml/jackson/databind/ObjectMapper.java index e14468b189..6c7563a6d4 100644 --- a/src/main/java/com/fasterxml/jackson/databind/ObjectMapper.java +++ b/src/main/java/com/fasterxml/jackson/databind/ObjectMapper.java @@ -2402,7 +2402,7 @@ protected Object _convert(Object fromValue, JavaType toValueType) public Schema generateJsonSchema(Class t) throws JsonMappingException { DefaultSerializerProvider provider = _serializerProvider(getSerializationConfig()); SchemaFactory visitor = new SchemaFactory(provider); - provider.acceptJsonFormatVisitor(t, visitor); + provider.acceptJsonFormatVisitor(constructType(t), visitor); return visitor.finalSchema(); } diff --git a/src/main/java/com/fasterxml/jackson/databind/ext/CoreXMLSerializers.java b/src/main/java/com/fasterxml/jackson/databind/ext/CoreXMLSerializers.java index 3f3dbc65e7..de718ffa2f 100644 --- a/src/main/java/com/fasterxml/jackson/databind/ext/CoreXMLSerializers.java +++ b/src/main/java/com/fasterxml/jackson/databind/ext/CoreXMLSerializers.java @@ -1,7 +1,6 @@ package com.fasterxml.jackson.databind.ext; import java.io.IOException; -import java.lang.reflect.Type; import java.util.Collection; import java.util.HashMap; import java.util.Map; @@ -12,6 +11,7 @@ import com.fasterxml.jackson.core.*; +import com.fasterxml.jackson.databind.JavaType; import com.fasterxml.jackson.databind.JsonMappingException; import com.fasterxml.jackson.databind.JsonNode; import com.fasterxml.jackson.databind.JsonSerializer; @@ -63,7 +63,7 @@ public void serialize(XMLGregorianCalendar value, JsonGenerator jgen, Serializer CalendarSerializer.instance.serialize(value.toGregorianCalendar(), jgen, provider); } - public void acceptJsonFormatVisitor(JsonFormatVisitor visitor, Type typeHint) { + public void acceptJsonFormatVisitor(JsonFormatVisitor visitor, JavaType typeHint) { CalendarSerializer.instance.acceptJsonFormatVisitor(visitor, null); } } diff --git a/src/main/java/com/fasterxml/jackson/databind/ext/DOMSerializer.java b/src/main/java/com/fasterxml/jackson/databind/ext/DOMSerializer.java index 215b288f09..f22f628ec1 100644 --- a/src/main/java/com/fasterxml/jackson/databind/ext/DOMSerializer.java +++ b/src/main/java/com/fasterxml/jackson/databind/ext/DOMSerializer.java @@ -1,7 +1,6 @@ package com.fasterxml.jackson.databind.ext; import java.io.IOException; -import java.lang.reflect.Type; import org.w3c.dom.Node; import org.w3c.dom.bootstrap.DOMImplementationRegistry; @@ -10,6 +9,7 @@ import com.fasterxml.jackson.core.*; +import com.fasterxml.jackson.databind.JavaType; import com.fasterxml.jackson.databind.SerializerProvider; import com.fasterxml.jackson.databind.jsonschema.visitors.JsonFormatVisitor; import com.fasterxml.jackson.databind.ser.std.StdSerializer; @@ -41,7 +41,7 @@ public void serialize(Node value, JsonGenerator jgen, SerializerProvider provide } @Override - public void acceptJsonFormatVisitor(JsonFormatVisitor visitor, Type typeHint) + public void acceptJsonFormatVisitor(JsonFormatVisitor visitor, JavaType typeHint) { visitor.anyFormat(); } diff --git a/src/main/java/com/fasterxml/jackson/databind/jsonschema/SchemaAware.java b/src/main/java/com/fasterxml/jackson/databind/jsonschema/SchemaAware.java index d3fdc461fa..e613086e4f 100644 --- a/src/main/java/com/fasterxml/jackson/databind/jsonschema/SchemaAware.java +++ b/src/main/java/com/fasterxml/jackson/databind/jsonschema/SchemaAware.java @@ -1,7 +1,7 @@ package com.fasterxml.jackson.databind.jsonschema; -import java.lang.reflect.Type; +import com.fasterxml.jackson.databind.JavaType; import com.fasterxml.jackson.databind.jsonschema.visitors.JsonFormatVisitor; /** @@ -15,5 +15,5 @@ public interface SchemaAware * * @return Json-schema for this serializer. */ - public void acceptJsonFormatVisitor(JsonFormatVisitor visitor, Type typeHint); + public void acceptJsonFormatVisitor(JsonFormatVisitor visitor, JavaType typeHint); } diff --git a/src/main/java/com/fasterxml/jackson/databind/jsonschema/factories/ObjectSchemaFactory.java b/src/main/java/com/fasterxml/jackson/databind/jsonschema/factories/ObjectSchemaFactory.java index 171f68d73d..93a9c207d3 100644 --- a/src/main/java/com/fasterxml/jackson/databind/jsonschema/factories/ObjectSchemaFactory.java +++ b/src/main/java/com/fasterxml/jackson/databind/jsonschema/factories/ObjectSchemaFactory.java @@ -1,7 +1,7 @@ package com.fasterxml.jackson.databind.jsonschema.factories; -import java.lang.reflect.Type; +import com.fasterxml.jackson.databind.JavaType; import com.fasterxml.jackson.databind.JsonMappingException; import com.fasterxml.jackson.databind.JsonSerializer; import com.fasterxml.jackson.databind.jsonschema.SchemaAware; @@ -10,6 +10,7 @@ import com.fasterxml.jackson.databind.jsonschema.types.SchemaType; import com.fasterxml.jackson.databind.jsonschema.visitors.JsonObjectFormatVisitor; import com.fasterxml.jackson.databind.ser.BeanPropertyWriter; +import com.fasterxml.jackson.databind.type.TypeFactory; public class ObjectSchemaFactory extends SchemaFactory implements JsonObjectFormatVisitor, SchemaFactoryDelegate { @@ -23,16 +24,14 @@ public ObjectSchemaFactory(SchemaFactory parent) { } public Schema getSchema() { - // TODO Auto-generated method stub return objectSchema; } - private JsonSerializer getSer(BeanPropertyWriter writer, Class serType) { + private JsonSerializer getSer(BeanPropertyWriter writer) { JsonSerializer ser = writer.getSerializer(); if (ser == null) { // nope - if (serType == null) { - serType = writer.getPropertyType(); - } + + JavaType serType = writer.getSerializationType(); try { return getProvider().findValueSerializer(serType, writer); } catch (JsonMappingException e) { @@ -42,28 +41,28 @@ private JsonSerializer getSer(BeanPropertyWriter writer, Class serTyp return ser; } - private Class writerType(BeanPropertyWriter writer) { - - //TODO:Will these ever return different types? - - //JavaType propType = writer.getSerializationType(); - //Type hint = (propType == null) ? writer.getGenericPropertyType() : propType.getRawClass(); - return writer.getPropertyType(); - } +// private Class writerType(BeanPropertyWriter writer) { +// +// //TODO:Will these ever return different types? +// +// JavaType propType = writer.getSerializationType(); +// TypeFactory.defaultInstance(). +// Type hint = (propType == null) ? writer.getGenericPropertyType() : propType.getRawClass(); +// return writer.getPropertyType(); +// } protected Schema propertySchema(BeanPropertyWriter writer) { SchemaFactory visitor = new SchemaFactory(provider); - Class serType = writerType(writer); - JsonSerializer ser = getSer(writer, serType); + JsonSerializer ser = getSer(writer); if (ser != null && ser instanceof SchemaAware) { - ((SchemaAware)ser).acceptJsonFormatVisitor(visitor, serType); + ((SchemaAware)ser).acceptJsonFormatVisitor(visitor, writer.getSerializationType()); } else { visitor.anyFormat(); } return visitor.finalSchema(); } - protected Schema propertySchema(SchemaAware handler, Type propertyTypeHint) { + protected Schema propertySchema(SchemaAware handler, JavaType propertyTypeHint) { SchemaFactory visitor = new SchemaFactory(provider); handler.acceptJsonFormatVisitor(visitor, propertyTypeHint); return visitor.finalSchema(); @@ -77,11 +76,11 @@ public void optionalProperty(BeanPropertyWriter writer) { objectSchema.putOptionalProperty(writer.getName(), propertySchema(writer)); } - public void property(String name, SchemaAware handler, Type propertyTypeHint) { + public void property(String name, SchemaAware handler, JavaType propertyTypeHint) { objectSchema.putProperty(name, propertySchema(handler, propertyTypeHint)); } - public void optionalProperty(String name, SchemaAware handler, Type propertyTypeHint) { + public void optionalProperty(String name, SchemaAware handler, JavaType propertyTypeHint) { objectSchema.putOptionalProperty(name, propertySchema(handler, propertyTypeHint)); } diff --git a/src/main/java/com/fasterxml/jackson/databind/jsonschema/factories/SchemaFactory.java b/src/main/java/com/fasterxml/jackson/databind/jsonschema/factories/SchemaFactory.java index 94223846ce..f8c7bd42e6 100644 --- a/src/main/java/com/fasterxml/jackson/databind/jsonschema/factories/SchemaFactory.java +++ b/src/main/java/com/fasterxml/jackson/databind/jsonschema/factories/SchemaFactory.java @@ -1,7 +1,7 @@ package com.fasterxml.jackson.databind.jsonschema.factories; -import java.lang.reflect.Type; +import com.fasterxml.jackson.databind.JavaType; import com.fasterxml.jackson.databind.SerializerProvider; import com.fasterxml.jackson.databind.jsonschema.types.Schema; import com.fasterxml.jackson.databind.jsonschema.visitors.JsonAnyFormatVisitor; @@ -28,7 +28,7 @@ public JsonAnyFormatVisitor anyFormat() { return (JsonAnyFormatVisitor) delegate; } - public JsonArrayFormatVisitor arrayFormat(Type elementType) { + public JsonArrayFormatVisitor arrayFormat(JavaType elementType) { delegate = new ArraySchemaFactory(this); return (JsonArrayFormatVisitor) delegate; } @@ -67,7 +67,7 @@ public JsonNumberFormatVisitor numberFormat() { return (JsonNumberFormatVisitor) delegate; } - public JsonObjectFormatVisitor objectFormat(Type type) { + public JsonObjectFormatVisitor objectFormat(JavaType type) { // BasicClassIntrospector.instance. delegate = new ObjectSchemaFactory(this); return (JsonObjectFormatVisitor) delegate; diff --git a/src/main/java/com/fasterxml/jackson/databind/jsonschema/visitors/JsonFormatVisitor.java b/src/main/java/com/fasterxml/jackson/databind/jsonschema/visitors/JsonFormatVisitor.java index aae53a9405..9f5df01a5a 100644 --- a/src/main/java/com/fasterxml/jackson/databind/jsonschema/visitors/JsonFormatVisitor.java +++ b/src/main/java/com/fasterxml/jackson/databind/jsonschema/visitors/JsonFormatVisitor.java @@ -1,13 +1,13 @@ package com.fasterxml.jackson.databind.jsonschema.visitors; -import java.lang.reflect.Type; +import com.fasterxml.jackson.databind.JavaType; import com.fasterxml.jackson.databind.SerializerProvider; public interface JsonFormatVisitor { - public JsonObjectFormatVisitor objectFormat(Type type); - public JsonArrayFormatVisitor arrayFormat(Type elementType); + public JsonObjectFormatVisitor objectFormat(JavaType type); + public JsonArrayFormatVisitor arrayFormat(JavaType elementType); public JsonStringFormatVisitor stringFormat(); public JsonNumberFormatVisitor numberFormat(); public JsonIntegerFormatVisitor integerFormat(); diff --git a/src/main/java/com/fasterxml/jackson/databind/jsonschema/visitors/JsonObjectFormatVisitor.java b/src/main/java/com/fasterxml/jackson/databind/jsonschema/visitors/JsonObjectFormatVisitor.java index 0a2113b1aa..679da671e2 100644 --- a/src/main/java/com/fasterxml/jackson/databind/jsonschema/visitors/JsonObjectFormatVisitor.java +++ b/src/main/java/com/fasterxml/jackson/databind/jsonschema/visitors/JsonObjectFormatVisitor.java @@ -1,7 +1,7 @@ package com.fasterxml.jackson.databind.jsonschema.visitors; -import java.lang.reflect.Type; +import com.fasterxml.jackson.databind.JavaType; import com.fasterxml.jackson.databind.jsonschema.SchemaAware; import com.fasterxml.jackson.databind.ser.BeanPropertyWriter; @@ -11,10 +11,10 @@ public interface JsonObjectFormatVisitor extends JsonFormatVisitor { public void optionalProperty(BeanPropertyWriter writer); - public void property(String name, SchemaAware handler, Type propertyTypeHint); + public void property(String name, SchemaAware handler, JavaType propertyTypeHint); public void optionalProperty(String name, SchemaAware handler, - Type propertyTypeHint); + JavaType propertyTypeHint); public void property(String name); diff --git a/src/main/java/com/fasterxml/jackson/databind/ser/DefaultSerializerProvider.java b/src/main/java/com/fasterxml/jackson/databind/ser/DefaultSerializerProvider.java index 8a471bea33..1026d6bdb5 100644 --- a/src/main/java/com/fasterxml/jackson/databind/ser/DefaultSerializerProvider.java +++ b/src/main/java/com/fasterxml/jackson/databind/ser/DefaultSerializerProvider.java @@ -236,7 +236,7 @@ public void serializeValue(JsonGenerator jgen, Object value, JavaType rootType, * * @param type The type for which to generate schema */ - public void acceptJsonFormatVisitor(Class type, JsonFormatVisitor visitor) + public void acceptJsonFormatVisitor(JavaType type, JsonFormatVisitor visitor) throws JsonMappingException { if (type == null) { diff --git a/src/main/java/com/fasterxml/jackson/databind/ser/impl/FailingSerializer.java b/src/main/java/com/fasterxml/jackson/databind/ser/impl/FailingSerializer.java index f2041f7542..e023f3091c 100644 --- a/src/main/java/com/fasterxml/jackson/databind/ser/impl/FailingSerializer.java +++ b/src/main/java/com/fasterxml/jackson/databind/ser/impl/FailingSerializer.java @@ -1,10 +1,10 @@ package com.fasterxml.jackson.databind.ser.impl; import java.io.IOException; -import java.lang.reflect.Type; import com.fasterxml.jackson.core.*; +import com.fasterxml.jackson.databind.JavaType; import com.fasterxml.jackson.databind.SerializerProvider; import com.fasterxml.jackson.databind.jsonschema.visitors.JsonFormatVisitor; import com.fasterxml.jackson.databind.ser.std.StdSerializer; @@ -34,7 +34,7 @@ public void serialize(Object value, JsonGenerator jgen, SerializerProvider provi } @Override - public void acceptJsonFormatVisitor(JsonFormatVisitor visitor, Type typeHint) + public void acceptJsonFormatVisitor(JsonFormatVisitor visitor, JavaType typeHint) { ; } diff --git a/src/main/java/com/fasterxml/jackson/databind/ser/impl/StringArraySerializer.java b/src/main/java/com/fasterxml/jackson/databind/ser/impl/StringArraySerializer.java index 5050c94ff8..eb2bc77457 100644 --- a/src/main/java/com/fasterxml/jackson/databind/ser/impl/StringArraySerializer.java +++ b/src/main/java/com/fasterxml/jackson/databind/ser/impl/StringArraySerializer.java @@ -1,7 +1,6 @@ package com.fasterxml.jackson.databind.ser.impl; import java.io.IOException; -import java.lang.reflect.Type; import com.fasterxml.jackson.core.JsonGenerationException; import com.fasterxml.jackson.core.JsonGenerator; @@ -171,7 +170,7 @@ private void serializeContentsSlow(String[] value, JsonGenerator jgen, Serialize } @Override - public void acceptJsonFormatVisitor(JsonFormatVisitor visitor, Type typeHint) + public void acceptJsonFormatVisitor(JsonFormatVisitor visitor, JavaType typeHint) { visitor.arrayFormat(null).itemsFormat(SchemaType.STRING); } diff --git a/src/main/java/com/fasterxml/jackson/databind/ser/impl/UnknownSerializer.java b/src/main/java/com/fasterxml/jackson/databind/ser/impl/UnknownSerializer.java index 02fc5dc024..800ccc41f7 100644 --- a/src/main/java/com/fasterxml/jackson/databind/ser/impl/UnknownSerializer.java +++ b/src/main/java/com/fasterxml/jackson/databind/ser/impl/UnknownSerializer.java @@ -1,7 +1,6 @@ package com.fasterxml.jackson.databind.ser.impl; import java.io.IOException; -import java.lang.reflect.Type; import com.fasterxml.jackson.core.*; @@ -43,7 +42,7 @@ public final void serializeWithType(Object value, JsonGenerator jgen, Serializer } @Override - public void acceptJsonFormatVisitor(JsonFormatVisitor visitor, Type typeHint) { + public void acceptJsonFormatVisitor(JsonFormatVisitor visitor, JavaType typeHint) { visitor.anyFormat(); } diff --git a/src/main/java/com/fasterxml/jackson/databind/ser/std/AsArraySerializerBase.java b/src/main/java/com/fasterxml/jackson/databind/ser/std/AsArraySerializerBase.java index 1de06418ac..d8f1bcab6d 100644 --- a/src/main/java/com/fasterxml/jackson/databind/ser/std/AsArraySerializerBase.java +++ b/src/main/java/com/fasterxml/jackson/databind/ser/std/AsArraySerializerBase.java @@ -168,7 +168,7 @@ protected abstract void serializeContents(T value, JsonGenerator jgen, Serialize throws IOException, JsonGenerationException; @Override - public void acceptJsonFormatVisitor(JsonFormatVisitor visitor, Type typeHint) + public void acceptJsonFormatVisitor(JsonFormatVisitor visitor, JavaType typeHint) { /* 15-Jan-2010, tatu: This should probably be rewritten, given that * more information about content type is actually being explicitly @@ -177,11 +177,10 @@ public void acceptJsonFormatVisitor(JsonFormatVisitor visitor, Type typeHint) */ //ObjectNode o = createSchemaNode("array", true); JsonArrayFormatVisitor arrayVisitor = - visitor.arrayFormat(typeHint == null ? _elementType.getRawClass() : typeHint); + visitor.arrayFormat(typeHint); JavaType contentType = null; if (typeHint != null) { - JavaType javaType = visitor.getProvider().constructType(typeHint); - contentType = javaType.getContentType(); + contentType = typeHint.getContentType(); if (contentType == null) { // could still be parametrized (Iterators) if (typeHint instanceof ParameterizedType) { Type[] typeArgs = ((ParameterizedType) typeHint).getActualTypeArguments(); diff --git a/src/main/java/com/fasterxml/jackson/databind/ser/std/BeanSerializerBase.java b/src/main/java/com/fasterxml/jackson/databind/ser/std/BeanSerializerBase.java index eac8280b74..ee1e13cd87 100644 --- a/src/main/java/com/fasterxml/jackson/databind/ser/std/BeanSerializerBase.java +++ b/src/main/java/com/fasterxml/jackson/databind/ser/std/BeanSerializerBase.java @@ -1,7 +1,6 @@ package com.fasterxml.jackson.databind.ser.std; import java.io.IOException; -import java.lang.reflect.Type; import java.util.*; import com.fasterxml.jackson.annotation.JsonFormat; @@ -627,9 +626,9 @@ protected BeanPropertyFilter findFilter(SerializerProvider provider) return filter; } - public void acceptJsonFormatVisitor(JsonFormatVisitor visitor, Type typeHint) + public void acceptJsonFormatVisitor(JsonFormatVisitor visitor, JavaType typeHint) { - JsonObjectFormatVisitor objectVisitor = visitor.objectFormat(typeHint == null ? _handledType : typeHint); + JsonObjectFormatVisitor objectVisitor = visitor.objectFormat(typeHint); // [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); @@ -659,7 +658,6 @@ public void acceptJsonFormatVisitor(JsonFormatVisitor visitor, Type typeHint) filter.depositSchemaProperty(prop, objectVisitor, visitor.getProvider()); continue; } - JavaType propType = prop.getSerializationType(); BeanSerializerBase.depositSchemaProperty(prop, objectVisitor); } } diff --git a/src/main/java/com/fasterxml/jackson/databind/ser/std/BooleanSerializer.java b/src/main/java/com/fasterxml/jackson/databind/ser/std/BooleanSerializer.java index 6bd3be5288..3c11db1f99 100644 --- a/src/main/java/com/fasterxml/jackson/databind/ser/std/BooleanSerializer.java +++ b/src/main/java/com/fasterxml/jackson/databind/ser/std/BooleanSerializer.java @@ -1,11 +1,11 @@ package com.fasterxml.jackson.databind.ser.std; import java.io.IOException; -import java.lang.reflect.Type; import com.fasterxml.jackson.core.JsonGenerationException; import com.fasterxml.jackson.core.JsonGenerator; +import com.fasterxml.jackson.databind.JavaType; import com.fasterxml.jackson.databind.JsonNode; import com.fasterxml.jackson.databind.SerializerProvider; import com.fasterxml.jackson.databind.annotation.JacksonStdImpl; @@ -42,7 +42,7 @@ public void serialize(Boolean value, JsonGenerator jgen, SerializerProvider prov } @Override - public void acceptJsonFormatVisitor(JsonFormatVisitor visitor, Type typeHint) + public void acceptJsonFormatVisitor(JsonFormatVisitor visitor, JavaType typeHint) { visitor.booleanFormat(); } diff --git a/src/main/java/com/fasterxml/jackson/databind/ser/std/DateTimeSerializerBase.java b/src/main/java/com/fasterxml/jackson/databind/ser/std/DateTimeSerializerBase.java index 79b5dacdf3..31f5910c67 100644 --- a/src/main/java/com/fasterxml/jackson/databind/ser/std/DateTimeSerializerBase.java +++ b/src/main/java/com/fasterxml/jackson/databind/ser/std/DateTimeSerializerBase.java @@ -1,7 +1,6 @@ package com.fasterxml.jackson.databind.ser.std; import java.io.IOException; -import java.lang.reflect.Type; import java.text.DateFormat; import java.text.SimpleDateFormat; import java.util.Locale; @@ -102,7 +101,7 @@ public boolean isEmpty(T value) { protected abstract long _timestamp(T value); - public void acceptJsonFormatVisitor(JsonFormatVisitor visitor, Type typeHint) + public void acceptJsonFormatVisitor(JsonFormatVisitor visitor, JavaType typeHint) { //todo: (ryan) add a format for the date in the schema? boolean asNumber = _useTimestamp; diff --git a/src/main/java/com/fasterxml/jackson/databind/ser/std/EnumMapSerializer.java b/src/main/java/com/fasterxml/jackson/databind/ser/std/EnumMapSerializer.java index b65a75da1a..2ddd38c479 100644 --- a/src/main/java/com/fasterxml/jackson/databind/ser/std/EnumMapSerializer.java +++ b/src/main/java/com/fasterxml/jackson/databind/ser/std/EnumMapSerializer.java @@ -19,6 +19,7 @@ import com.fasterxml.jackson.databind.node.ObjectNode; import com.fasterxml.jackson.databind.ser.ContainerSerializer; import com.fasterxml.jackson.databind.ser.ContextualSerializer; +import com.fasterxml.jackson.databind.type.TypeFactory; import com.fasterxml.jackson.databind.util.EnumValues; /** @@ -252,7 +253,7 @@ protected void serializeContentsUsing(EnumMap,?> value, JsonGe @SuppressWarnings("unchecked") @Override - public void acceptJsonFormatVisitor(JsonFormatVisitor visitor, Type typeHint) + public void acceptJsonFormatVisitor(JsonFormatVisitor visitor, JavaType typeHint) { JsonObjectFormatVisitor objectVisitor = visitor.objectFormat(typeHint); if (typeHint instanceof ParameterizedType) { @@ -268,7 +269,7 @@ public void acceptJsonFormatVisitor(JsonFormatVisitor visitor, Type typeHint) try { ser = visitor.getProvider().findValueSerializer(valueType.getRawClass(), _property); if (ser instanceof SchemaAware) { - objectVisitor.property(name, (SchemaAware) ser, typeArgs[1]); + objectVisitor.property(name, (SchemaAware) ser, TypeFactory.defaultInstance().constructType(typeArgs[1])); } continue; } catch (JsonMappingException e) { diff --git a/src/main/java/com/fasterxml/jackson/databind/ser/std/EnumSerializer.java b/src/main/java/com/fasterxml/jackson/databind/ser/std/EnumSerializer.java index 1da790eca4..59d09eba17 100644 --- a/src/main/java/com/fasterxml/jackson/databind/ser/std/EnumSerializer.java +++ b/src/main/java/com/fasterxml/jackson/databind/ser/std/EnumSerializer.java @@ -1,7 +1,6 @@ package com.fasterxml.jackson.databind.ser.std; import java.io.IOException; -import java.lang.reflect.Type; import java.util.HashSet; import java.util.Set; @@ -65,7 +64,7 @@ public final void serialize(Enum en, JsonGenerator jgen, SerializerProvider p } @Override - public void acceptJsonFormatVisitor(JsonFormatVisitor visitor, Type typeHint) + public void acceptJsonFormatVisitor(JsonFormatVisitor visitor, JavaType typeHint) { // [JACKSON-684]: serialize as index? if (visitor.getProvider().isEnabled(SerializationFeature.WRITE_ENUMS_USING_INDEX)) { @@ -73,8 +72,7 @@ public void acceptJsonFormatVisitor(JsonFormatVisitor visitor, Type typeHint) } else { JsonStringFormatVisitor stringVisitor = visitor.stringFormat(); if (typeHint != null) { - JavaType type = visitor.getProvider().constructType(typeHint); - if (type.isEnumType()) { + if (typeHint.isEnumType()) { Set enums = new HashSet(); for (SerializedString value : _values.values()) { enums.add(value.getValue()); diff --git a/src/main/java/com/fasterxml/jackson/databind/ser/std/JsonValueSerializer.java b/src/main/java/com/fasterxml/jackson/databind/ser/std/JsonValueSerializer.java index d2cf606508..797d3bb486 100644 --- a/src/main/java/com/fasterxml/jackson/databind/ser/std/JsonValueSerializer.java +++ b/src/main/java/com/fasterxml/jackson/databind/ser/std/JsonValueSerializer.java @@ -4,7 +4,6 @@ import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Method; import java.lang.reflect.Modifier; -import java.lang.reflect.Type; import com.fasterxml.jackson.core.*; @@ -231,7 +230,7 @@ public void serializeWithType(Object bean, JsonGenerator jgen, SerializerProvide } @Override - public void acceptJsonFormatVisitor(JsonFormatVisitor visitor, Type typeHint) + public void acceptJsonFormatVisitor(JsonFormatVisitor visitor, JavaType typeHint) { if (_valueSerializer instanceof SchemaAware) { ((SchemaAware) _valueSerializer).acceptJsonFormatVisitor(visitor, null); diff --git a/src/main/java/com/fasterxml/jackson/databind/ser/std/MapSerializer.java b/src/main/java/com/fasterxml/jackson/databind/ser/std/MapSerializer.java index 61f69ae2a8..d09da061c9 100644 --- a/src/main/java/com/fasterxml/jackson/databind/ser/std/MapSerializer.java +++ b/src/main/java/com/fasterxml/jackson/databind/ser/std/MapSerializer.java @@ -1,7 +1,6 @@ package com.fasterxml.jackson.databind.ser.std; import java.io.IOException; -import java.lang.reflect.Type; import java.util.*; import com.fasterxml.jackson.core.*; @@ -467,7 +466,7 @@ protected void serializeTypedFields(Map value, JsonGenerator jgen, Serializ } @Override - public void acceptJsonFormatVisitor(JsonFormatVisitor visitor, Type typeHint) + public void acceptJsonFormatVisitor(JsonFormatVisitor visitor, JavaType typeHint) { visitor.objectFormat(null); } diff --git a/src/main/java/com/fasterxml/jackson/databind/ser/std/NullSerializer.java b/src/main/java/com/fasterxml/jackson/databind/ser/std/NullSerializer.java index 200ab48730..b2f675e38b 100644 --- a/src/main/java/com/fasterxml/jackson/databind/ser/std/NullSerializer.java +++ b/src/main/java/com/fasterxml/jackson/databind/ser/std/NullSerializer.java @@ -1,6 +1,5 @@ package com.fasterxml.jackson.databind.ser.std; -import java.lang.reflect.Type; import java.io.IOException; import com.fasterxml.jackson.core.*; @@ -32,7 +31,7 @@ public void serialize(Object value, JsonGenerator jgen, SerializerProvider provi } @Override - public void acceptJsonFormatVisitor(JsonFormatVisitor visitor, Type typeHint) + public void acceptJsonFormatVisitor(JsonFormatVisitor visitor, JavaType typeHint) { visitor.nullFormat(); } diff --git a/src/main/java/com/fasterxml/jackson/databind/ser/std/NumberSerializers.java b/src/main/java/com/fasterxml/jackson/databind/ser/std/NumberSerializers.java index 4e6f506e20..db5c679daf 100644 --- a/src/main/java/com/fasterxml/jackson/databind/ser/std/NumberSerializers.java +++ b/src/main/java/com/fasterxml/jackson/databind/ser/std/NumberSerializers.java @@ -1,7 +1,6 @@ package com.fasterxml.jackson.databind.ser.std; import java.io.IOException; -import java.lang.reflect.Type; import java.math.BigDecimal; import java.math.BigInteger; import java.util.Map; @@ -72,7 +71,7 @@ public void serialize(Integer value, JsonGenerator jgen, SerializerProvider prov } @Override - public void acceptJsonFormatVisitor(JsonFormatVisitor visitor, Type typeHint) + public void acceptJsonFormatVisitor(JsonFormatVisitor visitor, JavaType typeHint) { visitor.integerFormat(); } @@ -99,7 +98,7 @@ public void serialize(Number value, JsonGenerator jgen, SerializerProvider provi } @Override - public void acceptJsonFormatVisitor(JsonFormatVisitor visitor, Type typeHint) + public void acceptJsonFormatVisitor(JsonFormatVisitor visitor, JavaType typeHint) { visitor.integerFormat(); } @@ -121,7 +120,7 @@ public void serialize(Long value, JsonGenerator jgen, SerializerProvider provide } @Override - public void acceptJsonFormatVisitor(JsonFormatVisitor visitor, Type typeHint) + public void acceptJsonFormatVisitor(JsonFormatVisitor visitor, JavaType typeHint) { visitor.numberFormat(); } @@ -143,7 +142,7 @@ public void serialize(Float value, JsonGenerator jgen, SerializerProvider provid } @Override - public void acceptJsonFormatVisitor(JsonFormatVisitor visitor, Type typeHint) + public void acceptJsonFormatVisitor(JsonFormatVisitor visitor, JavaType typeHint) { visitor.numberFormat(); } @@ -172,7 +171,7 @@ public void serialize(Double value, JsonGenerator jgen, SerializerProvider provi } @Override - public void acceptJsonFormatVisitor(JsonFormatVisitor visitor, Type typeHint) + public void acceptJsonFormatVisitor(JsonFormatVisitor visitor, JavaType typeHint) { visitor.numberFormat(); } @@ -220,7 +219,7 @@ public void serialize(Number value, JsonGenerator jgen, SerializerProvider provi } @Override - public void acceptJsonFormatVisitor(JsonFormatVisitor visitor, Type typeHint) + public void acceptJsonFormatVisitor(JsonFormatVisitor visitor, JavaType typeHint) { visitor.numberFormat(); } diff --git a/src/main/java/com/fasterxml/jackson/databind/ser/std/ObjectArraySerializer.java b/src/main/java/com/fasterxml/jackson/databind/ser/std/ObjectArraySerializer.java index dc213071aa..275a402aaa 100644 --- a/src/main/java/com/fasterxml/jackson/databind/ser/std/ObjectArraySerializer.java +++ b/src/main/java/com/fasterxml/jackson/databind/ser/std/ObjectArraySerializer.java @@ -2,7 +2,6 @@ import java.io.IOException; import java.lang.reflect.InvocationTargetException; -import java.lang.reflect.Type; import com.fasterxml.jackson.core.*; @@ -297,9 +296,9 @@ public void serializeTypedContents(Object[] value, JsonGenerator jgen, Serialize } @Override - public void acceptJsonFormatVisitor(JsonFormatVisitor visitor, Type typeHint) + public void acceptJsonFormatVisitor(JsonFormatVisitor visitor, JavaType typeHint) { - visitor.arrayFormat(typeHint == null ? _property.getType().getRawClass() : typeHint).itemsFormat(_elementType); + visitor.arrayFormat(typeHint).itemsFormat(_elementType); } protected final JsonSerializer _findAndAddDynamic(PropertySerializerMap map, diff --git a/src/main/java/com/fasterxml/jackson/databind/ser/std/RawSerializer.java b/src/main/java/com/fasterxml/jackson/databind/ser/std/RawSerializer.java index 2924f892c3..891a86964b 100644 --- a/src/main/java/com/fasterxml/jackson/databind/ser/std/RawSerializer.java +++ b/src/main/java/com/fasterxml/jackson/databind/ser/std/RawSerializer.java @@ -1,7 +1,6 @@ package com.fasterxml.jackson.databind.ser.std; import java.io.IOException; -import java.lang.reflect.Type; import com.fasterxml.jackson.core.*; @@ -45,7 +44,7 @@ public void serializeWithType(T value, JsonGenerator jgen, SerializerProvider pr } @Override - public void acceptJsonFormatVisitor(JsonFormatVisitor visitor, Type typeHint) + public void acceptJsonFormatVisitor(JsonFormatVisitor visitor, JavaType typeHint) { visitor.stringFormat(); } diff --git a/src/main/java/com/fasterxml/jackson/databind/ser/std/SerializableSerializer.java b/src/main/java/com/fasterxml/jackson/databind/ser/std/SerializableSerializer.java index aafe96be0f..da24334f37 100644 --- a/src/main/java/com/fasterxml/jackson/databind/ser/std/SerializableSerializer.java +++ b/src/main/java/com/fasterxml/jackson/databind/ser/std/SerializableSerializer.java @@ -1,12 +1,12 @@ package com.fasterxml.jackson.databind.ser.std; import java.io.IOException; -import java.lang.reflect.Type; import java.util.concurrent.atomic.AtomicReference; import com.fasterxml.jackson.core.*; +import com.fasterxml.jackson.databind.JavaType; import com.fasterxml.jackson.databind.JsonMappingException; import com.fasterxml.jackson.databind.JsonNode; import com.fasterxml.jackson.databind.JsonSerializable; @@ -55,21 +55,21 @@ public final void serializeWithType(JsonSerializable value, JsonGenerator jgen, } @Override - public void acceptJsonFormatVisitor(JsonFormatVisitor visitor, Type typeHint) + public void acceptJsonFormatVisitor(JsonFormatVisitor visitor, JavaType typeHint) { if (typeHint == null) { visitor.anyFormat(); } else { - Class rawClass = TypeFactory.rawClass(typeHint); + Class rawClass = typeHint.getRawClass(); if (rawClass.isAnnotationPresent(JsonSerializableSchema.class)) { JsonSerializableSchema schemaInfo = rawClass.getAnnotation(JsonSerializableSchema.class); if (!JsonSerializableSchema.NO_VALUE.equals(schemaInfo.schemaObjectPropertiesDefinition())) { - visitor.objectFormat(rawClass); + visitor.objectFormat(typeHint); //objectProperties = schemaInfo.schemaObjectPropertiesDefinition(); } else if (!JsonSerializableSchema.NO_VALUE.equals(schemaInfo.schemaItemDefinition())) { - visitor.arrayFormat(rawClass); + visitor.arrayFormat(typeHint); //itemDefinition = schemaInfo.schemaItemDefinition(); } else { visitor.anyFormat(); diff --git a/src/main/java/com/fasterxml/jackson/databind/ser/std/SqlDateSerializer.java b/src/main/java/com/fasterxml/jackson/databind/ser/std/SqlDateSerializer.java index 6dbdb1d406..2e3be58509 100644 --- a/src/main/java/com/fasterxml/jackson/databind/ser/std/SqlDateSerializer.java +++ b/src/main/java/com/fasterxml/jackson/databind/ser/std/SqlDateSerializer.java @@ -1,11 +1,11 @@ package com.fasterxml.jackson.databind.ser.std; import java.io.IOException; -import java.lang.reflect.Type; import com.fasterxml.jackson.core.JsonGenerationException; import com.fasterxml.jackson.core.JsonGenerator; +import com.fasterxml.jackson.databind.JavaType; import com.fasterxml.jackson.databind.JsonNode; import com.fasterxml.jackson.databind.SerializerProvider; import com.fasterxml.jackson.databind.annotation.JacksonStdImpl; @@ -31,7 +31,7 @@ public void serialize(java.sql.Date value, JsonGenerator jgen, SerializerProvide } @Override - public void acceptJsonFormatVisitor(JsonFormatVisitor visitor, Type typeHint) + public void acceptJsonFormatVisitor(JsonFormatVisitor visitor, JavaType typeHint) { visitor.stringFormat().format(JsonValueFormat.DATE_TIME); } diff --git a/src/main/java/com/fasterxml/jackson/databind/ser/std/SqlTimeSerializer.java b/src/main/java/com/fasterxml/jackson/databind/ser/std/SqlTimeSerializer.java index 7efd7c1867..25f6fb218e 100644 --- a/src/main/java/com/fasterxml/jackson/databind/ser/std/SqlTimeSerializer.java +++ b/src/main/java/com/fasterxml/jackson/databind/ser/std/SqlTimeSerializer.java @@ -1,11 +1,11 @@ package com.fasterxml.jackson.databind.ser.std; import java.io.IOException; -import java.lang.reflect.Type; import com.fasterxml.jackson.core.JsonGenerationException; import com.fasterxml.jackson.core.JsonGenerator; +import com.fasterxml.jackson.databind.JavaType; import com.fasterxml.jackson.databind.JsonNode; import com.fasterxml.jackson.databind.SerializerProvider; import com.fasterxml.jackson.databind.annotation.JacksonStdImpl; @@ -26,7 +26,7 @@ public void serialize(java.sql.Time value, JsonGenerator jgen, SerializerProvide } @Override - public void acceptJsonFormatVisitor(JsonFormatVisitor visitor, Type typeHint) + public void acceptJsonFormatVisitor(JsonFormatVisitor visitor, JavaType typeHint) { visitor.stringFormat().format(JsonValueFormat.DATE_TIME); } diff --git a/src/main/java/com/fasterxml/jackson/databind/ser/std/StaticListSerializerBase.java b/src/main/java/com/fasterxml/jackson/databind/ser/std/StaticListSerializerBase.java index 313340b508..798eaa454d 100644 --- a/src/main/java/com/fasterxml/jackson/databind/ser/std/StaticListSerializerBase.java +++ b/src/main/java/com/fasterxml/jackson/databind/ser/std/StaticListSerializerBase.java @@ -1,8 +1,8 @@ package com.fasterxml.jackson.databind.ser.std; -import java.lang.reflect.Type; import java.util.*; +import com.fasterxml.jackson.databind.JavaType; import com.fasterxml.jackson.databind.JsonNode; import com.fasterxml.jackson.databind.SerializerProvider; import com.fasterxml.jackson.databind.jsonschema.SchemaAware; @@ -27,7 +27,7 @@ public boolean isEmpty(T value) { } @Override - public void acceptJsonFormatVisitor(JsonFormatVisitor visitor, Type typeHint) + public void acceptJsonFormatVisitor(JsonFormatVisitor visitor, JavaType typeHint) { acceptContentVisitor(visitor.arrayFormat(typeHint)); } diff --git a/src/main/java/com/fasterxml/jackson/databind/ser/std/StdArraySerializers.java b/src/main/java/com/fasterxml/jackson/databind/ser/std/StdArraySerializers.java index d9d90e7486..cd80815a6c 100644 --- a/src/main/java/com/fasterxml/jackson/databind/ser/std/StdArraySerializers.java +++ b/src/main/java/com/fasterxml/jackson/databind/ser/std/StdArraySerializers.java @@ -1,7 +1,6 @@ package com.fasterxml.jackson.databind.ser.std; import java.io.IOException; -import java.lang.reflect.Type; import java.util.HashMap; import com.fasterxml.jackson.core.*; @@ -131,9 +130,9 @@ public void serializeContents(boolean[] value, JsonGenerator jgen, SerializerPro } @Override - public void acceptJsonFormatVisitor(JsonFormatVisitor visitor, Type typeHint) + public void acceptJsonFormatVisitor(JsonFormatVisitor visitor, JavaType typeHint) { - visitor.arrayFormat(typeHint == null ? _handledType : typeHint).itemsFormat(SchemaType.BOOLEAN); + visitor.arrayFormat(typeHint).itemsFormat(SchemaType.BOOLEAN); } } @@ -175,9 +174,9 @@ public void serializeWithType(byte[] value, JsonGenerator jgen, SerializerProvid } @Override - public void acceptJsonFormatVisitor(JsonFormatVisitor visitor, Type typeHint) + public void acceptJsonFormatVisitor(JsonFormatVisitor visitor, JavaType typeHint) { - visitor.arrayFormat(typeHint == null ? _handledType : typeHint).itemsFormat(SchemaType.STRING); + visitor.arrayFormat(typeHint).itemsFormat(SchemaType.STRING); } } @@ -238,9 +237,9 @@ public void serializeContents(short[] value, JsonGenerator jgen, SerializerProvi } @Override - public void acceptJsonFormatVisitor(JsonFormatVisitor visitor, Type typeHint) + public void acceptJsonFormatVisitor(JsonFormatVisitor visitor, JavaType typeHint) { - visitor.arrayFormat(typeHint == null ? _handledType : typeHint).itemsFormat(SchemaType.INTEGER); + visitor.arrayFormat(typeHint).itemsFormat(SchemaType.INTEGER); } } @@ -302,9 +301,9 @@ private final void _writeArrayContents(JsonGenerator jgen, char[] value) } @Override - public void acceptJsonFormatVisitor(JsonFormatVisitor visitor, Type typeHint) + public void acceptJsonFormatVisitor(JsonFormatVisitor visitor, JavaType typeHint) { - visitor.arrayFormat(typeHint == null ? _handledType : typeHint).itemsFormat(SchemaType.STRING); + visitor.arrayFormat(typeHint).itemsFormat(SchemaType.STRING); } } @@ -357,9 +356,9 @@ public void serializeContents(int[] value, JsonGenerator jgen, SerializerProvide } @Override - public void acceptJsonFormatVisitor(JsonFormatVisitor visitor, Type typeHint) + public void acceptJsonFormatVisitor(JsonFormatVisitor visitor, JavaType typeHint) { - visitor.arrayFormat(typeHint == null ? _handledType : typeHint).itemsFormat(SchemaType.INTEGER); + visitor.arrayFormat(typeHint).itemsFormat(SchemaType.INTEGER); } } @@ -421,9 +420,9 @@ public void serializeContents(long[] value, JsonGenerator jgen, SerializerProvid } @Override - public void acceptJsonFormatVisitor(JsonFormatVisitor visitor, Type typeHint) + public void acceptJsonFormatVisitor(JsonFormatVisitor visitor, JavaType typeHint) { - visitor.arrayFormat(typeHint == null ? _handledType : typeHint).itemsFormat(SchemaType.NUMBER); + visitor.arrayFormat(typeHint).itemsFormat(SchemaType.NUMBER); } } @@ -486,9 +485,9 @@ public void serializeContents(float[] value, JsonGenerator jgen, SerializerProvi } @Override - public void acceptJsonFormatVisitor(JsonFormatVisitor visitor, Type typeHint) + public void acceptJsonFormatVisitor(JsonFormatVisitor visitor, JavaType typeHint) { - visitor.arrayFormat(typeHint == null ? _handledType : typeHint).itemsFormat(SchemaType.NUMBER); + visitor.arrayFormat(typeHint).itemsFormat(SchemaType.NUMBER); } } @@ -541,9 +540,9 @@ public void serializeContents(double[] value, JsonGenerator jgen, SerializerProv } @Override - public void acceptJsonFormatVisitor(JsonFormatVisitor visitor, Type typeHint) + public void acceptJsonFormatVisitor(JsonFormatVisitor visitor, JavaType typeHint) { - visitor.arrayFormat(typeHint == null ? _handledType : typeHint).itemsFormat(SchemaType.NUMBER); + visitor.arrayFormat(typeHint).itemsFormat(SchemaType.NUMBER); } } } diff --git a/src/main/java/com/fasterxml/jackson/databind/ser/std/StdJdkSerializers.java b/src/main/java/com/fasterxml/jackson/databind/ser/std/StdJdkSerializers.java index 3859f41eac..e3a71a1f46 100644 --- a/src/main/java/com/fasterxml/jackson/databind/ser/std/StdJdkSerializers.java +++ b/src/main/java/com/fasterxml/jackson/databind/ser/std/StdJdkSerializers.java @@ -1,7 +1,6 @@ package com.fasterxml.jackson.databind.ser.std; import java.io.*; -import java.lang.reflect.Type; import java.util.*; import java.util.concurrent.atomic.*; @@ -78,7 +77,7 @@ public void serialize(AtomicBoolean value, JsonGenerator jgen, SerializerProvide } @Override - public void acceptJsonFormatVisitor(JsonFormatVisitor visitor, Type typeHint) + public void acceptJsonFormatVisitor(JsonFormatVisitor visitor, JavaType typeHint) { visitor.booleanFormat(); } @@ -97,7 +96,7 @@ public void serialize(AtomicInteger value, JsonGenerator jgen, SerializerProvide } @Override - public void acceptJsonFormatVisitor(JsonFormatVisitor visitor, Type typeHint) + public void acceptJsonFormatVisitor(JsonFormatVisitor visitor, JavaType typeHint) { visitor.integerFormat(); } @@ -116,7 +115,7 @@ public void serialize(AtomicLong value, JsonGenerator jgen, SerializerProvider p } @Override - public void acceptJsonFormatVisitor(JsonFormatVisitor visitor, Type typeHint) + public void acceptJsonFormatVisitor(JsonFormatVisitor visitor, JavaType typeHint) { visitor.integerFormat(); } @@ -135,7 +134,7 @@ public void serialize(AtomicReference value, JsonGenerator jgen, SerializerPr } @Override - public void acceptJsonFormatVisitor(JsonFormatVisitor visitor, Type typeHint) + public void acceptJsonFormatVisitor(JsonFormatVisitor visitor, JavaType typeHint) { visitor.anyFormat(); } @@ -164,7 +163,7 @@ public void serialize(File value, JsonGenerator jgen, SerializerProvider provide } @Override - public void acceptJsonFormatVisitor(JsonFormatVisitor visitor, Type typeHint) + public void acceptJsonFormatVisitor(JsonFormatVisitor visitor, JavaType typeHint) { visitor.stringFormat(); } @@ -187,7 +186,7 @@ public void serialize(Class value, JsonGenerator jgen, SerializerProvider pro } @Override - public void acceptJsonFormatVisitor(JsonFormatVisitor visitor, Type typeHint) + public void acceptJsonFormatVisitor(JsonFormatVisitor visitor, JavaType typeHint) { visitor.stringFormat(); } diff --git a/src/main/java/com/fasterxml/jackson/databind/ser/std/StdKeySerializer.java b/src/main/java/com/fasterxml/jackson/databind/ser/std/StdKeySerializer.java index aa1299cc39..89d09c7fc0 100644 --- a/src/main/java/com/fasterxml/jackson/databind/ser/std/StdKeySerializer.java +++ b/src/main/java/com/fasterxml/jackson/databind/ser/std/StdKeySerializer.java @@ -1,11 +1,11 @@ package com.fasterxml.jackson.databind.ser.std; import java.io.IOException; -import java.lang.reflect.Type; import java.util.Date; import com.fasterxml.jackson.core.*; +import com.fasterxml.jackson.databind.JavaType; import com.fasterxml.jackson.databind.SerializerProvider; import com.fasterxml.jackson.databind.jsonschema.visitors.JsonFormatVisitor; import com.fasterxml.jackson.databind.ser.std.StdSerializer; @@ -34,7 +34,7 @@ public void serialize(Object value, JsonGenerator jgen, SerializerProvider provi } @Override - public void acceptJsonFormatVisitor(JsonFormatVisitor visitor, Type typeHint) + public void acceptJsonFormatVisitor(JsonFormatVisitor visitor, JavaType typeHint) { visitor.stringFormat(); } diff --git a/src/main/java/com/fasterxml/jackson/databind/ser/std/StdScalarSerializer.java b/src/main/java/com/fasterxml/jackson/databind/ser/std/StdScalarSerializer.java index 8e8e195d93..5ba8789ca2 100644 --- a/src/main/java/com/fasterxml/jackson/databind/ser/std/StdScalarSerializer.java +++ b/src/main/java/com/fasterxml/jackson/databind/ser/std/StdScalarSerializer.java @@ -1,10 +1,10 @@ package com.fasterxml.jackson.databind.ser.std; import java.io.IOException; -import java.lang.reflect.Type; import com.fasterxml.jackson.core.*; +import com.fasterxml.jackson.databind.JavaType; import com.fasterxml.jackson.databind.JsonMappingException; import com.fasterxml.jackson.databind.JsonNode; import com.fasterxml.jackson.databind.SerializerProvider; @@ -45,7 +45,7 @@ public void serializeWithType(T value, JsonGenerator jgen, SerializerProvider pr } @Override - public void acceptJsonFormatVisitor(JsonFormatVisitor visitor, Type typeHint) + public void acceptJsonFormatVisitor(JsonFormatVisitor visitor, JavaType typeHint) { visitor.anyFormat(); } diff --git a/src/main/java/com/fasterxml/jackson/databind/ser/std/StdSerializer.java b/src/main/java/com/fasterxml/jackson/databind/ser/std/StdSerializer.java index 37602a0ab3..18aae8d2ea 100644 --- a/src/main/java/com/fasterxml/jackson/databind/ser/std/StdSerializer.java +++ b/src/main/java/com/fasterxml/jackson/databind/ser/std/StdSerializer.java @@ -2,7 +2,6 @@ import java.io.IOException; import java.lang.reflect.InvocationTargetException; -import java.lang.reflect.Type; import com.fasterxml.jackson.core.*; import com.fasterxml.jackson.databind.*; @@ -81,7 +80,7 @@ public abstract void serialize(T value, JsonGenerator jgen, SerializerProvider p * overriden by custom serializers. */ // @Override - public void acceptJsonFormatVisitor(JsonFormatVisitor visitor, Type typeHint) { + public void acceptJsonFormatVisitor(JsonFormatVisitor visitor, JavaType typeHint) { visitor.anyFormat(); } diff --git a/src/main/java/com/fasterxml/jackson/databind/ser/std/StringSerializer.java b/src/main/java/com/fasterxml/jackson/databind/ser/std/StringSerializer.java index 5635039e58..d03a05660c 100644 --- a/src/main/java/com/fasterxml/jackson/databind/ser/std/StringSerializer.java +++ b/src/main/java/com/fasterxml/jackson/databind/ser/std/StringSerializer.java @@ -1,10 +1,10 @@ package com.fasterxml.jackson.databind.ser.std; import java.io.IOException; -import java.lang.reflect.Type; import com.fasterxml.jackson.core.*; +import com.fasterxml.jackson.databind.JavaType; import com.fasterxml.jackson.databind.SerializerProvider; import com.fasterxml.jackson.databind.annotation.JacksonStdImpl; import com.fasterxml.jackson.databind.jsonschema.visitors.JsonFormatVisitor; @@ -37,7 +37,7 @@ public void serialize(String value, JsonGenerator jgen, SerializerProvider provi } @Override - public void acceptJsonFormatVisitor(JsonFormatVisitor visitor, Type typeHint) + public void acceptJsonFormatVisitor(JsonFormatVisitor visitor, JavaType typeHint) { visitor.stringFormat(); } diff --git a/src/main/java/com/fasterxml/jackson/databind/ser/std/ToStringSerializer.java b/src/main/java/com/fasterxml/jackson/databind/ser/std/ToStringSerializer.java index 83feb5770b..c664a57f52 100644 --- a/src/main/java/com/fasterxml/jackson/databind/ser/std/ToStringSerializer.java +++ b/src/main/java/com/fasterxml/jackson/databind/ser/std/ToStringSerializer.java @@ -1,10 +1,10 @@ package com.fasterxml.jackson.databind.ser.std; import java.io.IOException; -import java.lang.reflect.Type; import com.fasterxml.jackson.core.*; +import com.fasterxml.jackson.databind.JavaType; import com.fasterxml.jackson.databind.JsonMappingException; import com.fasterxml.jackson.databind.JsonNode; import com.fasterxml.jackson.databind.SerializerProvider; @@ -75,7 +75,7 @@ public void serializeWithType(Object value, JsonGenerator jgen, SerializerProvid } @Override - public void acceptJsonFormatVisitor(JsonFormatVisitor visitor, Type typeHint) + public void acceptJsonFormatVisitor(JsonFormatVisitor visitor, JavaType typeHint) { visitor.stringFormat(); } diff --git a/src/main/java/com/fasterxml/jackson/databind/ser/std/TokenBufferSerializer.java b/src/main/java/com/fasterxml/jackson/databind/ser/std/TokenBufferSerializer.java index 50dee4529b..55e34f4211 100644 --- a/src/main/java/com/fasterxml/jackson/databind/ser/std/TokenBufferSerializer.java +++ b/src/main/java/com/fasterxml/jackson/databind/ser/std/TokenBufferSerializer.java @@ -1,10 +1,10 @@ package com.fasterxml.jackson.databind.ser.std; import java.io.IOException; -import java.lang.reflect.Type; import com.fasterxml.jackson.core.*; +import com.fasterxml.jackson.databind.JavaType; import com.fasterxml.jackson.databind.JsonNode; import com.fasterxml.jackson.databind.SerializerProvider; import com.fasterxml.jackson.databind.annotation.JacksonStdImpl; @@ -54,7 +54,7 @@ public final void serializeWithType(TokenBuffer value, JsonGenerator jgen, Seria } @Override - public void acceptJsonFormatVisitor(JsonFormatVisitor visitor, Type typeHint) + public void acceptJsonFormatVisitor(JsonFormatVisitor visitor, JavaType typeHint) { /* 01-Jan-2010, tatu: Not 100% sure what we should say here: * type is basically not known. This seems closest diff --git a/src/test/java/com/fasterxml/jackson/databind/module/TestSimpleModule.java b/src/test/java/com/fasterxml/jackson/databind/module/TestSimpleModule.java index 2711d56f90..b15e208970 100644 --- a/src/test/java/com/fasterxml/jackson/databind/module/TestSimpleModule.java +++ b/src/test/java/com/fasterxml/jackson/databind/module/TestSimpleModule.java @@ -1,7 +1,6 @@ package com.fasterxml.jackson.databind.module; import java.io.IOException; -import java.lang.reflect.Type; import java.util.*; @@ -53,7 +52,7 @@ public void serialize(CustomBean value, JsonGenerator jgen, SerializerProvider p } @Override - public void acceptJsonFormatVisitor(JsonFormatVisitor visitor, Type typeHint) { + public void acceptJsonFormatVisitor(JsonFormatVisitor visitor, JavaType typeHint) { visitor.anyFormat(); } } @@ -87,7 +86,7 @@ public void serialize(SimpleEnum value, JsonGenerator jgen, SerializerProvider p } @Override - public void acceptJsonFormatVisitor(JsonFormatVisitor visitor, Type typeHint) { + public void acceptJsonFormatVisitor(JsonFormatVisitor visitor, JavaType typeHint) { visitor.anyFormat(); } } From c4db6f21552297afdc452b375f3603bb11db0018 Mon Sep 17 00:00:00 2001 From: jackphel Date: Thu, 2 Aug 2012 20:25:20 -0400 Subject: [PATCH 07/19] Revert "jsonFormatVisitor/acceptor now passes/accepts typeHint of JavaType, but some access is formatted incorrectly or, less likely, there is a bug in jackson. " This reverts commit 7fd884e4f7b0f02942fd425080e50f24fd6dfdfa. --- .../jackson/databind/ObjectMapper.java | 2 +- .../databind/ext/CoreXMLSerializers.java | 4 +- .../jackson/databind/ext/DOMSerializer.java | 4 +- .../databind/jsonschema/SchemaAware.java | 4 +- .../factories/ObjectSchemaFactory.java | 39 ++++++++++--------- .../jsonschema/factories/SchemaFactory.java | 6 +-- .../visitors/JsonFormatVisitor.java | 6 +-- .../visitors/JsonObjectFormatVisitor.java | 6 +-- .../ser/DefaultSerializerProvider.java | 2 +- .../databind/ser/impl/FailingSerializer.java | 4 +- .../ser/impl/StringArraySerializer.java | 3 +- .../databind/ser/impl/UnknownSerializer.java | 3 +- .../ser/std/AsArraySerializerBase.java | 7 ++-- .../databind/ser/std/BeanSerializerBase.java | 6 ++- .../databind/ser/std/BooleanSerializer.java | 4 +- .../ser/std/DateTimeSerializerBase.java | 3 +- .../databind/ser/std/EnumMapSerializer.java | 5 +-- .../databind/ser/std/EnumSerializer.java | 6 ++- .../databind/ser/std/JsonValueSerializer.java | 3 +- .../databind/ser/std/MapSerializer.java | 3 +- .../databind/ser/std/NullSerializer.java | 3 +- .../databind/ser/std/NumberSerializers.java | 13 ++++--- .../ser/std/ObjectArraySerializer.java | 5 ++- .../databind/ser/std/RawSerializer.java | 3 +- .../ser/std/SerializableSerializer.java | 10 ++--- .../databind/ser/std/SqlDateSerializer.java | 4 +- .../databind/ser/std/SqlTimeSerializer.java | 4 +- .../ser/std/StaticListSerializerBase.java | 4 +- .../databind/ser/std/StdArraySerializers.java | 33 ++++++++-------- .../databind/ser/std/StdJdkSerializers.java | 13 ++++--- .../databind/ser/std/StdKeySerializer.java | 4 +- .../databind/ser/std/StdScalarSerializer.java | 4 +- .../databind/ser/std/StdSerializer.java | 3 +- .../databind/ser/std/StringSerializer.java | 4 +- .../databind/ser/std/ToStringSerializer.java | 4 +- .../ser/std/TokenBufferSerializer.java | 4 +- .../databind/module/TestSimpleModule.java | 5 ++- 37 files changed, 129 insertions(+), 111 deletions(-) diff --git a/src/main/java/com/fasterxml/jackson/databind/ObjectMapper.java b/src/main/java/com/fasterxml/jackson/databind/ObjectMapper.java index 6c7563a6d4..e14468b189 100644 --- a/src/main/java/com/fasterxml/jackson/databind/ObjectMapper.java +++ b/src/main/java/com/fasterxml/jackson/databind/ObjectMapper.java @@ -2402,7 +2402,7 @@ protected Object _convert(Object fromValue, JavaType toValueType) public Schema generateJsonSchema(Class t) throws JsonMappingException { DefaultSerializerProvider provider = _serializerProvider(getSerializationConfig()); SchemaFactory visitor = new SchemaFactory(provider); - provider.acceptJsonFormatVisitor(constructType(t), visitor); + provider.acceptJsonFormatVisitor(t, visitor); return visitor.finalSchema(); } diff --git a/src/main/java/com/fasterxml/jackson/databind/ext/CoreXMLSerializers.java b/src/main/java/com/fasterxml/jackson/databind/ext/CoreXMLSerializers.java index de718ffa2f..3f3dbc65e7 100644 --- a/src/main/java/com/fasterxml/jackson/databind/ext/CoreXMLSerializers.java +++ b/src/main/java/com/fasterxml/jackson/databind/ext/CoreXMLSerializers.java @@ -1,6 +1,7 @@ package com.fasterxml.jackson.databind.ext; import java.io.IOException; +import java.lang.reflect.Type; import java.util.Collection; import java.util.HashMap; import java.util.Map; @@ -11,7 +12,6 @@ import com.fasterxml.jackson.core.*; -import com.fasterxml.jackson.databind.JavaType; import com.fasterxml.jackson.databind.JsonMappingException; import com.fasterxml.jackson.databind.JsonNode; import com.fasterxml.jackson.databind.JsonSerializer; @@ -63,7 +63,7 @@ public void serialize(XMLGregorianCalendar value, JsonGenerator jgen, Serializer CalendarSerializer.instance.serialize(value.toGregorianCalendar(), jgen, provider); } - public void acceptJsonFormatVisitor(JsonFormatVisitor visitor, JavaType typeHint) { + public void acceptJsonFormatVisitor(JsonFormatVisitor visitor, Type typeHint) { CalendarSerializer.instance.acceptJsonFormatVisitor(visitor, null); } } diff --git a/src/main/java/com/fasterxml/jackson/databind/ext/DOMSerializer.java b/src/main/java/com/fasterxml/jackson/databind/ext/DOMSerializer.java index f22f628ec1..215b288f09 100644 --- a/src/main/java/com/fasterxml/jackson/databind/ext/DOMSerializer.java +++ b/src/main/java/com/fasterxml/jackson/databind/ext/DOMSerializer.java @@ -1,6 +1,7 @@ package com.fasterxml.jackson.databind.ext; import java.io.IOException; +import java.lang.reflect.Type; import org.w3c.dom.Node; import org.w3c.dom.bootstrap.DOMImplementationRegistry; @@ -9,7 +10,6 @@ import com.fasterxml.jackson.core.*; -import com.fasterxml.jackson.databind.JavaType; import com.fasterxml.jackson.databind.SerializerProvider; import com.fasterxml.jackson.databind.jsonschema.visitors.JsonFormatVisitor; import com.fasterxml.jackson.databind.ser.std.StdSerializer; @@ -41,7 +41,7 @@ public void serialize(Node value, JsonGenerator jgen, SerializerProvider provide } @Override - public void acceptJsonFormatVisitor(JsonFormatVisitor visitor, JavaType typeHint) + public void acceptJsonFormatVisitor(JsonFormatVisitor visitor, Type typeHint) { visitor.anyFormat(); } diff --git a/src/main/java/com/fasterxml/jackson/databind/jsonschema/SchemaAware.java b/src/main/java/com/fasterxml/jackson/databind/jsonschema/SchemaAware.java index e613086e4f..d3fdc461fa 100644 --- a/src/main/java/com/fasterxml/jackson/databind/jsonschema/SchemaAware.java +++ b/src/main/java/com/fasterxml/jackson/databind/jsonschema/SchemaAware.java @@ -1,7 +1,7 @@ package com.fasterxml.jackson.databind.jsonschema; +import java.lang.reflect.Type; -import com.fasterxml.jackson.databind.JavaType; import com.fasterxml.jackson.databind.jsonschema.visitors.JsonFormatVisitor; /** @@ -15,5 +15,5 @@ public interface SchemaAware * * @return Json-schema for this serializer. */ - public void acceptJsonFormatVisitor(JsonFormatVisitor visitor, JavaType typeHint); + public void acceptJsonFormatVisitor(JsonFormatVisitor visitor, Type typeHint); } diff --git a/src/main/java/com/fasterxml/jackson/databind/jsonschema/factories/ObjectSchemaFactory.java b/src/main/java/com/fasterxml/jackson/databind/jsonschema/factories/ObjectSchemaFactory.java index 93a9c207d3..171f68d73d 100644 --- a/src/main/java/com/fasterxml/jackson/databind/jsonschema/factories/ObjectSchemaFactory.java +++ b/src/main/java/com/fasterxml/jackson/databind/jsonschema/factories/ObjectSchemaFactory.java @@ -1,7 +1,7 @@ package com.fasterxml.jackson.databind.jsonschema.factories; +import java.lang.reflect.Type; -import com.fasterxml.jackson.databind.JavaType; import com.fasterxml.jackson.databind.JsonMappingException; import com.fasterxml.jackson.databind.JsonSerializer; import com.fasterxml.jackson.databind.jsonschema.SchemaAware; @@ -10,7 +10,6 @@ import com.fasterxml.jackson.databind.jsonschema.types.SchemaType; import com.fasterxml.jackson.databind.jsonschema.visitors.JsonObjectFormatVisitor; import com.fasterxml.jackson.databind.ser.BeanPropertyWriter; -import com.fasterxml.jackson.databind.type.TypeFactory; public class ObjectSchemaFactory extends SchemaFactory implements JsonObjectFormatVisitor, SchemaFactoryDelegate { @@ -24,14 +23,16 @@ public ObjectSchemaFactory(SchemaFactory parent) { } public Schema getSchema() { + // TODO Auto-generated method stub return objectSchema; } - private JsonSerializer getSer(BeanPropertyWriter writer) { + private JsonSerializer getSer(BeanPropertyWriter writer, Class serType) { JsonSerializer ser = writer.getSerializer(); if (ser == null) { // nope - - JavaType serType = writer.getSerializationType(); + if (serType == null) { + serType = writer.getPropertyType(); + } try { return getProvider().findValueSerializer(serType, writer); } catch (JsonMappingException e) { @@ -41,28 +42,28 @@ private JsonSerializer getSer(BeanPropertyWriter writer) { return ser; } -// private Class writerType(BeanPropertyWriter writer) { -// -// //TODO:Will these ever return different types? -// -// JavaType propType = writer.getSerializationType(); -// TypeFactory.defaultInstance(). -// Type hint = (propType == null) ? writer.getGenericPropertyType() : propType.getRawClass(); -// return writer.getPropertyType(); -// } + private Class writerType(BeanPropertyWriter writer) { + + //TODO:Will these ever return different types? + + //JavaType propType = writer.getSerializationType(); + //Type hint = (propType == null) ? writer.getGenericPropertyType() : propType.getRawClass(); + return writer.getPropertyType(); + } protected Schema propertySchema(BeanPropertyWriter writer) { SchemaFactory visitor = new SchemaFactory(provider); - JsonSerializer ser = getSer(writer); + Class serType = writerType(writer); + JsonSerializer ser = getSer(writer, serType); if (ser != null && ser instanceof SchemaAware) { - ((SchemaAware)ser).acceptJsonFormatVisitor(visitor, writer.getSerializationType()); + ((SchemaAware)ser).acceptJsonFormatVisitor(visitor, serType); } else { visitor.anyFormat(); } return visitor.finalSchema(); } - protected Schema propertySchema(SchemaAware handler, JavaType propertyTypeHint) { + protected Schema propertySchema(SchemaAware handler, Type propertyTypeHint) { SchemaFactory visitor = new SchemaFactory(provider); handler.acceptJsonFormatVisitor(visitor, propertyTypeHint); return visitor.finalSchema(); @@ -76,11 +77,11 @@ public void optionalProperty(BeanPropertyWriter writer) { objectSchema.putOptionalProperty(writer.getName(), propertySchema(writer)); } - public void property(String name, SchemaAware handler, JavaType propertyTypeHint) { + public void property(String name, SchemaAware handler, Type propertyTypeHint) { objectSchema.putProperty(name, propertySchema(handler, propertyTypeHint)); } - public void optionalProperty(String name, SchemaAware handler, JavaType propertyTypeHint) { + public void optionalProperty(String name, SchemaAware handler, Type propertyTypeHint) { objectSchema.putOptionalProperty(name, propertySchema(handler, propertyTypeHint)); } diff --git a/src/main/java/com/fasterxml/jackson/databind/jsonschema/factories/SchemaFactory.java b/src/main/java/com/fasterxml/jackson/databind/jsonschema/factories/SchemaFactory.java index f8c7bd42e6..94223846ce 100644 --- a/src/main/java/com/fasterxml/jackson/databind/jsonschema/factories/SchemaFactory.java +++ b/src/main/java/com/fasterxml/jackson/databind/jsonschema/factories/SchemaFactory.java @@ -1,7 +1,7 @@ package com.fasterxml.jackson.databind.jsonschema.factories; +import java.lang.reflect.Type; -import com.fasterxml.jackson.databind.JavaType; import com.fasterxml.jackson.databind.SerializerProvider; import com.fasterxml.jackson.databind.jsonschema.types.Schema; import com.fasterxml.jackson.databind.jsonschema.visitors.JsonAnyFormatVisitor; @@ -28,7 +28,7 @@ public JsonAnyFormatVisitor anyFormat() { return (JsonAnyFormatVisitor) delegate; } - public JsonArrayFormatVisitor arrayFormat(JavaType elementType) { + public JsonArrayFormatVisitor arrayFormat(Type elementType) { delegate = new ArraySchemaFactory(this); return (JsonArrayFormatVisitor) delegate; } @@ -67,7 +67,7 @@ public JsonNumberFormatVisitor numberFormat() { return (JsonNumberFormatVisitor) delegate; } - public JsonObjectFormatVisitor objectFormat(JavaType type) { + public JsonObjectFormatVisitor objectFormat(Type type) { // BasicClassIntrospector.instance. delegate = new ObjectSchemaFactory(this); return (JsonObjectFormatVisitor) delegate; diff --git a/src/main/java/com/fasterxml/jackson/databind/jsonschema/visitors/JsonFormatVisitor.java b/src/main/java/com/fasterxml/jackson/databind/jsonschema/visitors/JsonFormatVisitor.java index 9f5df01a5a..aae53a9405 100644 --- a/src/main/java/com/fasterxml/jackson/databind/jsonschema/visitors/JsonFormatVisitor.java +++ b/src/main/java/com/fasterxml/jackson/databind/jsonschema/visitors/JsonFormatVisitor.java @@ -1,13 +1,13 @@ package com.fasterxml.jackson.databind.jsonschema.visitors; +import java.lang.reflect.Type; -import com.fasterxml.jackson.databind.JavaType; import com.fasterxml.jackson.databind.SerializerProvider; public interface JsonFormatVisitor { - public JsonObjectFormatVisitor objectFormat(JavaType type); - public JsonArrayFormatVisitor arrayFormat(JavaType elementType); + public JsonObjectFormatVisitor objectFormat(Type type); + public JsonArrayFormatVisitor arrayFormat(Type elementType); public JsonStringFormatVisitor stringFormat(); public JsonNumberFormatVisitor numberFormat(); public JsonIntegerFormatVisitor integerFormat(); diff --git a/src/main/java/com/fasterxml/jackson/databind/jsonschema/visitors/JsonObjectFormatVisitor.java b/src/main/java/com/fasterxml/jackson/databind/jsonschema/visitors/JsonObjectFormatVisitor.java index 679da671e2..0a2113b1aa 100644 --- a/src/main/java/com/fasterxml/jackson/databind/jsonschema/visitors/JsonObjectFormatVisitor.java +++ b/src/main/java/com/fasterxml/jackson/databind/jsonschema/visitors/JsonObjectFormatVisitor.java @@ -1,7 +1,7 @@ package com.fasterxml.jackson.databind.jsonschema.visitors; +import java.lang.reflect.Type; -import com.fasterxml.jackson.databind.JavaType; import com.fasterxml.jackson.databind.jsonschema.SchemaAware; import com.fasterxml.jackson.databind.ser.BeanPropertyWriter; @@ -11,10 +11,10 @@ public interface JsonObjectFormatVisitor extends JsonFormatVisitor { public void optionalProperty(BeanPropertyWriter writer); - public void property(String name, SchemaAware handler, JavaType propertyTypeHint); + public void property(String name, SchemaAware handler, Type propertyTypeHint); public void optionalProperty(String name, SchemaAware handler, - JavaType propertyTypeHint); + Type propertyTypeHint); public void property(String name); diff --git a/src/main/java/com/fasterxml/jackson/databind/ser/DefaultSerializerProvider.java b/src/main/java/com/fasterxml/jackson/databind/ser/DefaultSerializerProvider.java index 1026d6bdb5..8a471bea33 100644 --- a/src/main/java/com/fasterxml/jackson/databind/ser/DefaultSerializerProvider.java +++ b/src/main/java/com/fasterxml/jackson/databind/ser/DefaultSerializerProvider.java @@ -236,7 +236,7 @@ public void serializeValue(JsonGenerator jgen, Object value, JavaType rootType, * * @param type The type for which to generate schema */ - public void acceptJsonFormatVisitor(JavaType type, JsonFormatVisitor visitor) + public void acceptJsonFormatVisitor(Class type, JsonFormatVisitor visitor) throws JsonMappingException { if (type == null) { diff --git a/src/main/java/com/fasterxml/jackson/databind/ser/impl/FailingSerializer.java b/src/main/java/com/fasterxml/jackson/databind/ser/impl/FailingSerializer.java index e023f3091c..f2041f7542 100644 --- a/src/main/java/com/fasterxml/jackson/databind/ser/impl/FailingSerializer.java +++ b/src/main/java/com/fasterxml/jackson/databind/ser/impl/FailingSerializer.java @@ -1,10 +1,10 @@ package com.fasterxml.jackson.databind.ser.impl; import java.io.IOException; +import java.lang.reflect.Type; import com.fasterxml.jackson.core.*; -import com.fasterxml.jackson.databind.JavaType; import com.fasterxml.jackson.databind.SerializerProvider; import com.fasterxml.jackson.databind.jsonschema.visitors.JsonFormatVisitor; import com.fasterxml.jackson.databind.ser.std.StdSerializer; @@ -34,7 +34,7 @@ public void serialize(Object value, JsonGenerator jgen, SerializerProvider provi } @Override - public void acceptJsonFormatVisitor(JsonFormatVisitor visitor, JavaType typeHint) + public void acceptJsonFormatVisitor(JsonFormatVisitor visitor, Type typeHint) { ; } diff --git a/src/main/java/com/fasterxml/jackson/databind/ser/impl/StringArraySerializer.java b/src/main/java/com/fasterxml/jackson/databind/ser/impl/StringArraySerializer.java index eb2bc77457..5050c94ff8 100644 --- a/src/main/java/com/fasterxml/jackson/databind/ser/impl/StringArraySerializer.java +++ b/src/main/java/com/fasterxml/jackson/databind/ser/impl/StringArraySerializer.java @@ -1,6 +1,7 @@ package com.fasterxml.jackson.databind.ser.impl; import java.io.IOException; +import java.lang.reflect.Type; import com.fasterxml.jackson.core.JsonGenerationException; import com.fasterxml.jackson.core.JsonGenerator; @@ -170,7 +171,7 @@ private void serializeContentsSlow(String[] value, JsonGenerator jgen, Serialize } @Override - public void acceptJsonFormatVisitor(JsonFormatVisitor visitor, JavaType typeHint) + public void acceptJsonFormatVisitor(JsonFormatVisitor visitor, Type typeHint) { visitor.arrayFormat(null).itemsFormat(SchemaType.STRING); } diff --git a/src/main/java/com/fasterxml/jackson/databind/ser/impl/UnknownSerializer.java b/src/main/java/com/fasterxml/jackson/databind/ser/impl/UnknownSerializer.java index 800ccc41f7..02fc5dc024 100644 --- a/src/main/java/com/fasterxml/jackson/databind/ser/impl/UnknownSerializer.java +++ b/src/main/java/com/fasterxml/jackson/databind/ser/impl/UnknownSerializer.java @@ -1,6 +1,7 @@ package com.fasterxml.jackson.databind.ser.impl; import java.io.IOException; +import java.lang.reflect.Type; import com.fasterxml.jackson.core.*; @@ -42,7 +43,7 @@ public final void serializeWithType(Object value, JsonGenerator jgen, Serializer } @Override - public void acceptJsonFormatVisitor(JsonFormatVisitor visitor, JavaType typeHint) { + public void acceptJsonFormatVisitor(JsonFormatVisitor visitor, Type typeHint) { visitor.anyFormat(); } diff --git a/src/main/java/com/fasterxml/jackson/databind/ser/std/AsArraySerializerBase.java b/src/main/java/com/fasterxml/jackson/databind/ser/std/AsArraySerializerBase.java index d8f1bcab6d..1de06418ac 100644 --- a/src/main/java/com/fasterxml/jackson/databind/ser/std/AsArraySerializerBase.java +++ b/src/main/java/com/fasterxml/jackson/databind/ser/std/AsArraySerializerBase.java @@ -168,7 +168,7 @@ protected abstract void serializeContents(T value, JsonGenerator jgen, Serialize throws IOException, JsonGenerationException; @Override - public void acceptJsonFormatVisitor(JsonFormatVisitor visitor, JavaType typeHint) + public void acceptJsonFormatVisitor(JsonFormatVisitor visitor, Type typeHint) { /* 15-Jan-2010, tatu: This should probably be rewritten, given that * more information about content type is actually being explicitly @@ -177,10 +177,11 @@ public void acceptJsonFormatVisitor(JsonFormatVisitor visitor, JavaType typeHint */ //ObjectNode o = createSchemaNode("array", true); JsonArrayFormatVisitor arrayVisitor = - visitor.arrayFormat(typeHint); + visitor.arrayFormat(typeHint == null ? _elementType.getRawClass() : typeHint); JavaType contentType = null; if (typeHint != null) { - contentType = typeHint.getContentType(); + JavaType javaType = visitor.getProvider().constructType(typeHint); + contentType = javaType.getContentType(); if (contentType == null) { // could still be parametrized (Iterators) if (typeHint instanceof ParameterizedType) { Type[] typeArgs = ((ParameterizedType) typeHint).getActualTypeArguments(); diff --git a/src/main/java/com/fasterxml/jackson/databind/ser/std/BeanSerializerBase.java b/src/main/java/com/fasterxml/jackson/databind/ser/std/BeanSerializerBase.java index ee1e13cd87..eac8280b74 100644 --- a/src/main/java/com/fasterxml/jackson/databind/ser/std/BeanSerializerBase.java +++ b/src/main/java/com/fasterxml/jackson/databind/ser/std/BeanSerializerBase.java @@ -1,6 +1,7 @@ package com.fasterxml.jackson.databind.ser.std; import java.io.IOException; +import java.lang.reflect.Type; import java.util.*; import com.fasterxml.jackson.annotation.JsonFormat; @@ -626,9 +627,9 @@ protected BeanPropertyFilter findFilter(SerializerProvider provider) return filter; } - public void acceptJsonFormatVisitor(JsonFormatVisitor visitor, JavaType typeHint) + public void acceptJsonFormatVisitor(JsonFormatVisitor visitor, Type typeHint) { - JsonObjectFormatVisitor objectVisitor = visitor.objectFormat(typeHint); + JsonObjectFormatVisitor objectVisitor = visitor.objectFormat(typeHint == null ? _handledType : typeHint); // [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); @@ -658,6 +659,7 @@ public void acceptJsonFormatVisitor(JsonFormatVisitor visitor, JavaType typeHint filter.depositSchemaProperty(prop, objectVisitor, visitor.getProvider()); continue; } + JavaType propType = prop.getSerializationType(); BeanSerializerBase.depositSchemaProperty(prop, objectVisitor); } } diff --git a/src/main/java/com/fasterxml/jackson/databind/ser/std/BooleanSerializer.java b/src/main/java/com/fasterxml/jackson/databind/ser/std/BooleanSerializer.java index 3c11db1f99..6bd3be5288 100644 --- a/src/main/java/com/fasterxml/jackson/databind/ser/std/BooleanSerializer.java +++ b/src/main/java/com/fasterxml/jackson/databind/ser/std/BooleanSerializer.java @@ -1,11 +1,11 @@ package com.fasterxml.jackson.databind.ser.std; import java.io.IOException; +import java.lang.reflect.Type; import com.fasterxml.jackson.core.JsonGenerationException; import com.fasterxml.jackson.core.JsonGenerator; -import com.fasterxml.jackson.databind.JavaType; import com.fasterxml.jackson.databind.JsonNode; import com.fasterxml.jackson.databind.SerializerProvider; import com.fasterxml.jackson.databind.annotation.JacksonStdImpl; @@ -42,7 +42,7 @@ public void serialize(Boolean value, JsonGenerator jgen, SerializerProvider prov } @Override - public void acceptJsonFormatVisitor(JsonFormatVisitor visitor, JavaType typeHint) + public void acceptJsonFormatVisitor(JsonFormatVisitor visitor, Type typeHint) { visitor.booleanFormat(); } diff --git a/src/main/java/com/fasterxml/jackson/databind/ser/std/DateTimeSerializerBase.java b/src/main/java/com/fasterxml/jackson/databind/ser/std/DateTimeSerializerBase.java index 31f5910c67..79b5dacdf3 100644 --- a/src/main/java/com/fasterxml/jackson/databind/ser/std/DateTimeSerializerBase.java +++ b/src/main/java/com/fasterxml/jackson/databind/ser/std/DateTimeSerializerBase.java @@ -1,6 +1,7 @@ package com.fasterxml.jackson.databind.ser.std; import java.io.IOException; +import java.lang.reflect.Type; import java.text.DateFormat; import java.text.SimpleDateFormat; import java.util.Locale; @@ -101,7 +102,7 @@ public boolean isEmpty(T value) { protected abstract long _timestamp(T value); - public void acceptJsonFormatVisitor(JsonFormatVisitor visitor, JavaType typeHint) + public void acceptJsonFormatVisitor(JsonFormatVisitor visitor, Type typeHint) { //todo: (ryan) add a format for the date in the schema? boolean asNumber = _useTimestamp; diff --git a/src/main/java/com/fasterxml/jackson/databind/ser/std/EnumMapSerializer.java b/src/main/java/com/fasterxml/jackson/databind/ser/std/EnumMapSerializer.java index 2ddd38c479..b65a75da1a 100644 --- a/src/main/java/com/fasterxml/jackson/databind/ser/std/EnumMapSerializer.java +++ b/src/main/java/com/fasterxml/jackson/databind/ser/std/EnumMapSerializer.java @@ -19,7 +19,6 @@ import com.fasterxml.jackson.databind.node.ObjectNode; import com.fasterxml.jackson.databind.ser.ContainerSerializer; import com.fasterxml.jackson.databind.ser.ContextualSerializer; -import com.fasterxml.jackson.databind.type.TypeFactory; import com.fasterxml.jackson.databind.util.EnumValues; /** @@ -253,7 +252,7 @@ protected void serializeContentsUsing(EnumMap,?> value, JsonGe @SuppressWarnings("unchecked") @Override - public void acceptJsonFormatVisitor(JsonFormatVisitor visitor, JavaType typeHint) + public void acceptJsonFormatVisitor(JsonFormatVisitor visitor, Type typeHint) { JsonObjectFormatVisitor objectVisitor = visitor.objectFormat(typeHint); if (typeHint instanceof ParameterizedType) { @@ -269,7 +268,7 @@ public void acceptJsonFormatVisitor(JsonFormatVisitor visitor, JavaType typeHint try { ser = visitor.getProvider().findValueSerializer(valueType.getRawClass(), _property); if (ser instanceof SchemaAware) { - objectVisitor.property(name, (SchemaAware) ser, TypeFactory.defaultInstance().constructType(typeArgs[1])); + objectVisitor.property(name, (SchemaAware) ser, typeArgs[1]); } continue; } catch (JsonMappingException e) { diff --git a/src/main/java/com/fasterxml/jackson/databind/ser/std/EnumSerializer.java b/src/main/java/com/fasterxml/jackson/databind/ser/std/EnumSerializer.java index 59d09eba17..1da790eca4 100644 --- a/src/main/java/com/fasterxml/jackson/databind/ser/std/EnumSerializer.java +++ b/src/main/java/com/fasterxml/jackson/databind/ser/std/EnumSerializer.java @@ -1,6 +1,7 @@ package com.fasterxml.jackson.databind.ser.std; import java.io.IOException; +import java.lang.reflect.Type; import java.util.HashSet; import java.util.Set; @@ -64,7 +65,7 @@ public final void serialize(Enum en, JsonGenerator jgen, SerializerProvider p } @Override - public void acceptJsonFormatVisitor(JsonFormatVisitor visitor, JavaType typeHint) + public void acceptJsonFormatVisitor(JsonFormatVisitor visitor, Type typeHint) { // [JACKSON-684]: serialize as index? if (visitor.getProvider().isEnabled(SerializationFeature.WRITE_ENUMS_USING_INDEX)) { @@ -72,7 +73,8 @@ public void acceptJsonFormatVisitor(JsonFormatVisitor visitor, JavaType typeHint } else { JsonStringFormatVisitor stringVisitor = visitor.stringFormat(); if (typeHint != null) { - if (typeHint.isEnumType()) { + JavaType type = visitor.getProvider().constructType(typeHint); + if (type.isEnumType()) { Set enums = new HashSet(); for (SerializedString value : _values.values()) { enums.add(value.getValue()); diff --git a/src/main/java/com/fasterxml/jackson/databind/ser/std/JsonValueSerializer.java b/src/main/java/com/fasterxml/jackson/databind/ser/std/JsonValueSerializer.java index 797d3bb486..d2cf606508 100644 --- a/src/main/java/com/fasterxml/jackson/databind/ser/std/JsonValueSerializer.java +++ b/src/main/java/com/fasterxml/jackson/databind/ser/std/JsonValueSerializer.java @@ -4,6 +4,7 @@ import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Method; import java.lang.reflect.Modifier; +import java.lang.reflect.Type; import com.fasterxml.jackson.core.*; @@ -230,7 +231,7 @@ public void serializeWithType(Object bean, JsonGenerator jgen, SerializerProvide } @Override - public void acceptJsonFormatVisitor(JsonFormatVisitor visitor, JavaType typeHint) + public void acceptJsonFormatVisitor(JsonFormatVisitor visitor, Type typeHint) { if (_valueSerializer instanceof SchemaAware) { ((SchemaAware) _valueSerializer).acceptJsonFormatVisitor(visitor, null); diff --git a/src/main/java/com/fasterxml/jackson/databind/ser/std/MapSerializer.java b/src/main/java/com/fasterxml/jackson/databind/ser/std/MapSerializer.java index d09da061c9..61f69ae2a8 100644 --- a/src/main/java/com/fasterxml/jackson/databind/ser/std/MapSerializer.java +++ b/src/main/java/com/fasterxml/jackson/databind/ser/std/MapSerializer.java @@ -1,6 +1,7 @@ package com.fasterxml.jackson.databind.ser.std; import java.io.IOException; +import java.lang.reflect.Type; import java.util.*; import com.fasterxml.jackson.core.*; @@ -466,7 +467,7 @@ protected void serializeTypedFields(Map value, JsonGenerator jgen, Serializ } @Override - public void acceptJsonFormatVisitor(JsonFormatVisitor visitor, JavaType typeHint) + public void acceptJsonFormatVisitor(JsonFormatVisitor visitor, Type typeHint) { visitor.objectFormat(null); } diff --git a/src/main/java/com/fasterxml/jackson/databind/ser/std/NullSerializer.java b/src/main/java/com/fasterxml/jackson/databind/ser/std/NullSerializer.java index b2f675e38b..200ab48730 100644 --- a/src/main/java/com/fasterxml/jackson/databind/ser/std/NullSerializer.java +++ b/src/main/java/com/fasterxml/jackson/databind/ser/std/NullSerializer.java @@ -1,5 +1,6 @@ package com.fasterxml.jackson.databind.ser.std; +import java.lang.reflect.Type; import java.io.IOException; import com.fasterxml.jackson.core.*; @@ -31,7 +32,7 @@ public void serialize(Object value, JsonGenerator jgen, SerializerProvider provi } @Override - public void acceptJsonFormatVisitor(JsonFormatVisitor visitor, JavaType typeHint) + public void acceptJsonFormatVisitor(JsonFormatVisitor visitor, Type typeHint) { visitor.nullFormat(); } diff --git a/src/main/java/com/fasterxml/jackson/databind/ser/std/NumberSerializers.java b/src/main/java/com/fasterxml/jackson/databind/ser/std/NumberSerializers.java index db5c679daf..4e6f506e20 100644 --- a/src/main/java/com/fasterxml/jackson/databind/ser/std/NumberSerializers.java +++ b/src/main/java/com/fasterxml/jackson/databind/ser/std/NumberSerializers.java @@ -1,6 +1,7 @@ package com.fasterxml.jackson.databind.ser.std; import java.io.IOException; +import java.lang.reflect.Type; import java.math.BigDecimal; import java.math.BigInteger; import java.util.Map; @@ -71,7 +72,7 @@ public void serialize(Integer value, JsonGenerator jgen, SerializerProvider prov } @Override - public void acceptJsonFormatVisitor(JsonFormatVisitor visitor, JavaType typeHint) + public void acceptJsonFormatVisitor(JsonFormatVisitor visitor, Type typeHint) { visitor.integerFormat(); } @@ -98,7 +99,7 @@ public void serialize(Number value, JsonGenerator jgen, SerializerProvider provi } @Override - public void acceptJsonFormatVisitor(JsonFormatVisitor visitor, JavaType typeHint) + public void acceptJsonFormatVisitor(JsonFormatVisitor visitor, Type typeHint) { visitor.integerFormat(); } @@ -120,7 +121,7 @@ public void serialize(Long value, JsonGenerator jgen, SerializerProvider provide } @Override - public void acceptJsonFormatVisitor(JsonFormatVisitor visitor, JavaType typeHint) + public void acceptJsonFormatVisitor(JsonFormatVisitor visitor, Type typeHint) { visitor.numberFormat(); } @@ -142,7 +143,7 @@ public void serialize(Float value, JsonGenerator jgen, SerializerProvider provid } @Override - public void acceptJsonFormatVisitor(JsonFormatVisitor visitor, JavaType typeHint) + public void acceptJsonFormatVisitor(JsonFormatVisitor visitor, Type typeHint) { visitor.numberFormat(); } @@ -171,7 +172,7 @@ public void serialize(Double value, JsonGenerator jgen, SerializerProvider provi } @Override - public void acceptJsonFormatVisitor(JsonFormatVisitor visitor, JavaType typeHint) + public void acceptJsonFormatVisitor(JsonFormatVisitor visitor, Type typeHint) { visitor.numberFormat(); } @@ -219,7 +220,7 @@ public void serialize(Number value, JsonGenerator jgen, SerializerProvider provi } @Override - public void acceptJsonFormatVisitor(JsonFormatVisitor visitor, JavaType typeHint) + public void acceptJsonFormatVisitor(JsonFormatVisitor visitor, Type typeHint) { visitor.numberFormat(); } diff --git a/src/main/java/com/fasterxml/jackson/databind/ser/std/ObjectArraySerializer.java b/src/main/java/com/fasterxml/jackson/databind/ser/std/ObjectArraySerializer.java index 275a402aaa..dc213071aa 100644 --- a/src/main/java/com/fasterxml/jackson/databind/ser/std/ObjectArraySerializer.java +++ b/src/main/java/com/fasterxml/jackson/databind/ser/std/ObjectArraySerializer.java @@ -2,6 +2,7 @@ import java.io.IOException; import java.lang.reflect.InvocationTargetException; +import java.lang.reflect.Type; import com.fasterxml.jackson.core.*; @@ -296,9 +297,9 @@ public void serializeTypedContents(Object[] value, JsonGenerator jgen, Serialize } @Override - public void acceptJsonFormatVisitor(JsonFormatVisitor visitor, JavaType typeHint) + public void acceptJsonFormatVisitor(JsonFormatVisitor visitor, Type typeHint) { - visitor.arrayFormat(typeHint).itemsFormat(_elementType); + visitor.arrayFormat(typeHint == null ? _property.getType().getRawClass() : typeHint).itemsFormat(_elementType); } protected final JsonSerializer _findAndAddDynamic(PropertySerializerMap map, diff --git a/src/main/java/com/fasterxml/jackson/databind/ser/std/RawSerializer.java b/src/main/java/com/fasterxml/jackson/databind/ser/std/RawSerializer.java index 891a86964b..2924f892c3 100644 --- a/src/main/java/com/fasterxml/jackson/databind/ser/std/RawSerializer.java +++ b/src/main/java/com/fasterxml/jackson/databind/ser/std/RawSerializer.java @@ -1,6 +1,7 @@ package com.fasterxml.jackson.databind.ser.std; import java.io.IOException; +import java.lang.reflect.Type; import com.fasterxml.jackson.core.*; @@ -44,7 +45,7 @@ public void serializeWithType(T value, JsonGenerator jgen, SerializerProvider pr } @Override - public void acceptJsonFormatVisitor(JsonFormatVisitor visitor, JavaType typeHint) + public void acceptJsonFormatVisitor(JsonFormatVisitor visitor, Type typeHint) { visitor.stringFormat(); } diff --git a/src/main/java/com/fasterxml/jackson/databind/ser/std/SerializableSerializer.java b/src/main/java/com/fasterxml/jackson/databind/ser/std/SerializableSerializer.java index da24334f37..aafe96be0f 100644 --- a/src/main/java/com/fasterxml/jackson/databind/ser/std/SerializableSerializer.java +++ b/src/main/java/com/fasterxml/jackson/databind/ser/std/SerializableSerializer.java @@ -1,12 +1,12 @@ package com.fasterxml.jackson.databind.ser.std; import java.io.IOException; +import java.lang.reflect.Type; import java.util.concurrent.atomic.AtomicReference; import com.fasterxml.jackson.core.*; -import com.fasterxml.jackson.databind.JavaType; import com.fasterxml.jackson.databind.JsonMappingException; import com.fasterxml.jackson.databind.JsonNode; import com.fasterxml.jackson.databind.JsonSerializable; @@ -55,21 +55,21 @@ public final void serializeWithType(JsonSerializable value, JsonGenerator jgen, } @Override - public void acceptJsonFormatVisitor(JsonFormatVisitor visitor, JavaType typeHint) + public void acceptJsonFormatVisitor(JsonFormatVisitor visitor, Type typeHint) { if (typeHint == null) { visitor.anyFormat(); } else { - Class rawClass = typeHint.getRawClass(); + Class rawClass = TypeFactory.rawClass(typeHint); if (rawClass.isAnnotationPresent(JsonSerializableSchema.class)) { JsonSerializableSchema schemaInfo = rawClass.getAnnotation(JsonSerializableSchema.class); if (!JsonSerializableSchema.NO_VALUE.equals(schemaInfo.schemaObjectPropertiesDefinition())) { - visitor.objectFormat(typeHint); + visitor.objectFormat(rawClass); //objectProperties = schemaInfo.schemaObjectPropertiesDefinition(); } else if (!JsonSerializableSchema.NO_VALUE.equals(schemaInfo.schemaItemDefinition())) { - visitor.arrayFormat(typeHint); + visitor.arrayFormat(rawClass); //itemDefinition = schemaInfo.schemaItemDefinition(); } else { visitor.anyFormat(); diff --git a/src/main/java/com/fasterxml/jackson/databind/ser/std/SqlDateSerializer.java b/src/main/java/com/fasterxml/jackson/databind/ser/std/SqlDateSerializer.java index 2e3be58509..6dbdb1d406 100644 --- a/src/main/java/com/fasterxml/jackson/databind/ser/std/SqlDateSerializer.java +++ b/src/main/java/com/fasterxml/jackson/databind/ser/std/SqlDateSerializer.java @@ -1,11 +1,11 @@ package com.fasterxml.jackson.databind.ser.std; import java.io.IOException; +import java.lang.reflect.Type; import com.fasterxml.jackson.core.JsonGenerationException; import com.fasterxml.jackson.core.JsonGenerator; -import com.fasterxml.jackson.databind.JavaType; import com.fasterxml.jackson.databind.JsonNode; import com.fasterxml.jackson.databind.SerializerProvider; import com.fasterxml.jackson.databind.annotation.JacksonStdImpl; @@ -31,7 +31,7 @@ public void serialize(java.sql.Date value, JsonGenerator jgen, SerializerProvide } @Override - public void acceptJsonFormatVisitor(JsonFormatVisitor visitor, JavaType typeHint) + public void acceptJsonFormatVisitor(JsonFormatVisitor visitor, Type typeHint) { visitor.stringFormat().format(JsonValueFormat.DATE_TIME); } diff --git a/src/main/java/com/fasterxml/jackson/databind/ser/std/SqlTimeSerializer.java b/src/main/java/com/fasterxml/jackson/databind/ser/std/SqlTimeSerializer.java index 25f6fb218e..7efd7c1867 100644 --- a/src/main/java/com/fasterxml/jackson/databind/ser/std/SqlTimeSerializer.java +++ b/src/main/java/com/fasterxml/jackson/databind/ser/std/SqlTimeSerializer.java @@ -1,11 +1,11 @@ package com.fasterxml.jackson.databind.ser.std; import java.io.IOException; +import java.lang.reflect.Type; import com.fasterxml.jackson.core.JsonGenerationException; import com.fasterxml.jackson.core.JsonGenerator; -import com.fasterxml.jackson.databind.JavaType; import com.fasterxml.jackson.databind.JsonNode; import com.fasterxml.jackson.databind.SerializerProvider; import com.fasterxml.jackson.databind.annotation.JacksonStdImpl; @@ -26,7 +26,7 @@ public void serialize(java.sql.Time value, JsonGenerator jgen, SerializerProvide } @Override - public void acceptJsonFormatVisitor(JsonFormatVisitor visitor, JavaType typeHint) + public void acceptJsonFormatVisitor(JsonFormatVisitor visitor, Type typeHint) { visitor.stringFormat().format(JsonValueFormat.DATE_TIME); } diff --git a/src/main/java/com/fasterxml/jackson/databind/ser/std/StaticListSerializerBase.java b/src/main/java/com/fasterxml/jackson/databind/ser/std/StaticListSerializerBase.java index 798eaa454d..313340b508 100644 --- a/src/main/java/com/fasterxml/jackson/databind/ser/std/StaticListSerializerBase.java +++ b/src/main/java/com/fasterxml/jackson/databind/ser/std/StaticListSerializerBase.java @@ -1,8 +1,8 @@ package com.fasterxml.jackson.databind.ser.std; +import java.lang.reflect.Type; import java.util.*; -import com.fasterxml.jackson.databind.JavaType; import com.fasterxml.jackson.databind.JsonNode; import com.fasterxml.jackson.databind.SerializerProvider; import com.fasterxml.jackson.databind.jsonschema.SchemaAware; @@ -27,7 +27,7 @@ public boolean isEmpty(T value) { } @Override - public void acceptJsonFormatVisitor(JsonFormatVisitor visitor, JavaType typeHint) + public void acceptJsonFormatVisitor(JsonFormatVisitor visitor, Type typeHint) { acceptContentVisitor(visitor.arrayFormat(typeHint)); } diff --git a/src/main/java/com/fasterxml/jackson/databind/ser/std/StdArraySerializers.java b/src/main/java/com/fasterxml/jackson/databind/ser/std/StdArraySerializers.java index cd80815a6c..d9d90e7486 100644 --- a/src/main/java/com/fasterxml/jackson/databind/ser/std/StdArraySerializers.java +++ b/src/main/java/com/fasterxml/jackson/databind/ser/std/StdArraySerializers.java @@ -1,6 +1,7 @@ package com.fasterxml.jackson.databind.ser.std; import java.io.IOException; +import java.lang.reflect.Type; import java.util.HashMap; import com.fasterxml.jackson.core.*; @@ -130,9 +131,9 @@ public void serializeContents(boolean[] value, JsonGenerator jgen, SerializerPro } @Override - public void acceptJsonFormatVisitor(JsonFormatVisitor visitor, JavaType typeHint) + public void acceptJsonFormatVisitor(JsonFormatVisitor visitor, Type typeHint) { - visitor.arrayFormat(typeHint).itemsFormat(SchemaType.BOOLEAN); + visitor.arrayFormat(typeHint == null ? _handledType : typeHint).itemsFormat(SchemaType.BOOLEAN); } } @@ -174,9 +175,9 @@ public void serializeWithType(byte[] value, JsonGenerator jgen, SerializerProvid } @Override - public void acceptJsonFormatVisitor(JsonFormatVisitor visitor, JavaType typeHint) + public void acceptJsonFormatVisitor(JsonFormatVisitor visitor, Type typeHint) { - visitor.arrayFormat(typeHint).itemsFormat(SchemaType.STRING); + visitor.arrayFormat(typeHint == null ? _handledType : typeHint).itemsFormat(SchemaType.STRING); } } @@ -237,9 +238,9 @@ public void serializeContents(short[] value, JsonGenerator jgen, SerializerProvi } @Override - public void acceptJsonFormatVisitor(JsonFormatVisitor visitor, JavaType typeHint) + public void acceptJsonFormatVisitor(JsonFormatVisitor visitor, Type typeHint) { - visitor.arrayFormat(typeHint).itemsFormat(SchemaType.INTEGER); + visitor.arrayFormat(typeHint == null ? _handledType : typeHint).itemsFormat(SchemaType.INTEGER); } } @@ -301,9 +302,9 @@ private final void _writeArrayContents(JsonGenerator jgen, char[] value) } @Override - public void acceptJsonFormatVisitor(JsonFormatVisitor visitor, JavaType typeHint) + public void acceptJsonFormatVisitor(JsonFormatVisitor visitor, Type typeHint) { - visitor.arrayFormat(typeHint).itemsFormat(SchemaType.STRING); + visitor.arrayFormat(typeHint == null ? _handledType : typeHint).itemsFormat(SchemaType.STRING); } } @@ -356,9 +357,9 @@ public void serializeContents(int[] value, JsonGenerator jgen, SerializerProvide } @Override - public void acceptJsonFormatVisitor(JsonFormatVisitor visitor, JavaType typeHint) + public void acceptJsonFormatVisitor(JsonFormatVisitor visitor, Type typeHint) { - visitor.arrayFormat(typeHint).itemsFormat(SchemaType.INTEGER); + visitor.arrayFormat(typeHint == null ? _handledType : typeHint).itemsFormat(SchemaType.INTEGER); } } @@ -420,9 +421,9 @@ public void serializeContents(long[] value, JsonGenerator jgen, SerializerProvid } @Override - public void acceptJsonFormatVisitor(JsonFormatVisitor visitor, JavaType typeHint) + public void acceptJsonFormatVisitor(JsonFormatVisitor visitor, Type typeHint) { - visitor.arrayFormat(typeHint).itemsFormat(SchemaType.NUMBER); + visitor.arrayFormat(typeHint == null ? _handledType : typeHint).itemsFormat(SchemaType.NUMBER); } } @@ -485,9 +486,9 @@ public void serializeContents(float[] value, JsonGenerator jgen, SerializerProvi } @Override - public void acceptJsonFormatVisitor(JsonFormatVisitor visitor, JavaType typeHint) + public void acceptJsonFormatVisitor(JsonFormatVisitor visitor, Type typeHint) { - visitor.arrayFormat(typeHint).itemsFormat(SchemaType.NUMBER); + visitor.arrayFormat(typeHint == null ? _handledType : typeHint).itemsFormat(SchemaType.NUMBER); } } @@ -540,9 +541,9 @@ public void serializeContents(double[] value, JsonGenerator jgen, SerializerProv } @Override - public void acceptJsonFormatVisitor(JsonFormatVisitor visitor, JavaType typeHint) + public void acceptJsonFormatVisitor(JsonFormatVisitor visitor, Type typeHint) { - visitor.arrayFormat(typeHint).itemsFormat(SchemaType.NUMBER); + visitor.arrayFormat(typeHint == null ? _handledType : typeHint).itemsFormat(SchemaType.NUMBER); } } } diff --git a/src/main/java/com/fasterxml/jackson/databind/ser/std/StdJdkSerializers.java b/src/main/java/com/fasterxml/jackson/databind/ser/std/StdJdkSerializers.java index e3a71a1f46..3859f41eac 100644 --- a/src/main/java/com/fasterxml/jackson/databind/ser/std/StdJdkSerializers.java +++ b/src/main/java/com/fasterxml/jackson/databind/ser/std/StdJdkSerializers.java @@ -1,6 +1,7 @@ package com.fasterxml.jackson.databind.ser.std; import java.io.*; +import java.lang.reflect.Type; import java.util.*; import java.util.concurrent.atomic.*; @@ -77,7 +78,7 @@ public void serialize(AtomicBoolean value, JsonGenerator jgen, SerializerProvide } @Override - public void acceptJsonFormatVisitor(JsonFormatVisitor visitor, JavaType typeHint) + public void acceptJsonFormatVisitor(JsonFormatVisitor visitor, Type typeHint) { visitor.booleanFormat(); } @@ -96,7 +97,7 @@ public void serialize(AtomicInteger value, JsonGenerator jgen, SerializerProvide } @Override - public void acceptJsonFormatVisitor(JsonFormatVisitor visitor, JavaType typeHint) + public void acceptJsonFormatVisitor(JsonFormatVisitor visitor, Type typeHint) { visitor.integerFormat(); } @@ -115,7 +116,7 @@ public void serialize(AtomicLong value, JsonGenerator jgen, SerializerProvider p } @Override - public void acceptJsonFormatVisitor(JsonFormatVisitor visitor, JavaType typeHint) + public void acceptJsonFormatVisitor(JsonFormatVisitor visitor, Type typeHint) { visitor.integerFormat(); } @@ -134,7 +135,7 @@ public void serialize(AtomicReference value, JsonGenerator jgen, SerializerPr } @Override - public void acceptJsonFormatVisitor(JsonFormatVisitor visitor, JavaType typeHint) + public void acceptJsonFormatVisitor(JsonFormatVisitor visitor, Type typeHint) { visitor.anyFormat(); } @@ -163,7 +164,7 @@ public void serialize(File value, JsonGenerator jgen, SerializerProvider provide } @Override - public void acceptJsonFormatVisitor(JsonFormatVisitor visitor, JavaType typeHint) + public void acceptJsonFormatVisitor(JsonFormatVisitor visitor, Type typeHint) { visitor.stringFormat(); } @@ -186,7 +187,7 @@ public void serialize(Class value, JsonGenerator jgen, SerializerProvider pro } @Override - public void acceptJsonFormatVisitor(JsonFormatVisitor visitor, JavaType typeHint) + public void acceptJsonFormatVisitor(JsonFormatVisitor visitor, Type typeHint) { visitor.stringFormat(); } diff --git a/src/main/java/com/fasterxml/jackson/databind/ser/std/StdKeySerializer.java b/src/main/java/com/fasterxml/jackson/databind/ser/std/StdKeySerializer.java index 89d09c7fc0..aa1299cc39 100644 --- a/src/main/java/com/fasterxml/jackson/databind/ser/std/StdKeySerializer.java +++ b/src/main/java/com/fasterxml/jackson/databind/ser/std/StdKeySerializer.java @@ -1,11 +1,11 @@ package com.fasterxml.jackson.databind.ser.std; import java.io.IOException; +import java.lang.reflect.Type; import java.util.Date; import com.fasterxml.jackson.core.*; -import com.fasterxml.jackson.databind.JavaType; import com.fasterxml.jackson.databind.SerializerProvider; import com.fasterxml.jackson.databind.jsonschema.visitors.JsonFormatVisitor; import com.fasterxml.jackson.databind.ser.std.StdSerializer; @@ -34,7 +34,7 @@ public void serialize(Object value, JsonGenerator jgen, SerializerProvider provi } @Override - public void acceptJsonFormatVisitor(JsonFormatVisitor visitor, JavaType typeHint) + public void acceptJsonFormatVisitor(JsonFormatVisitor visitor, Type typeHint) { visitor.stringFormat(); } diff --git a/src/main/java/com/fasterxml/jackson/databind/ser/std/StdScalarSerializer.java b/src/main/java/com/fasterxml/jackson/databind/ser/std/StdScalarSerializer.java index 5ba8789ca2..8e8e195d93 100644 --- a/src/main/java/com/fasterxml/jackson/databind/ser/std/StdScalarSerializer.java +++ b/src/main/java/com/fasterxml/jackson/databind/ser/std/StdScalarSerializer.java @@ -1,10 +1,10 @@ package com.fasterxml.jackson.databind.ser.std; import java.io.IOException; +import java.lang.reflect.Type; import com.fasterxml.jackson.core.*; -import com.fasterxml.jackson.databind.JavaType; import com.fasterxml.jackson.databind.JsonMappingException; import com.fasterxml.jackson.databind.JsonNode; import com.fasterxml.jackson.databind.SerializerProvider; @@ -45,7 +45,7 @@ public void serializeWithType(T value, JsonGenerator jgen, SerializerProvider pr } @Override - public void acceptJsonFormatVisitor(JsonFormatVisitor visitor, JavaType typeHint) + public void acceptJsonFormatVisitor(JsonFormatVisitor visitor, Type typeHint) { visitor.anyFormat(); } diff --git a/src/main/java/com/fasterxml/jackson/databind/ser/std/StdSerializer.java b/src/main/java/com/fasterxml/jackson/databind/ser/std/StdSerializer.java index 18aae8d2ea..37602a0ab3 100644 --- a/src/main/java/com/fasterxml/jackson/databind/ser/std/StdSerializer.java +++ b/src/main/java/com/fasterxml/jackson/databind/ser/std/StdSerializer.java @@ -2,6 +2,7 @@ import java.io.IOException; import java.lang.reflect.InvocationTargetException; +import java.lang.reflect.Type; import com.fasterxml.jackson.core.*; import com.fasterxml.jackson.databind.*; @@ -80,7 +81,7 @@ public abstract void serialize(T value, JsonGenerator jgen, SerializerProvider p * overriden by custom serializers. */ // @Override - public void acceptJsonFormatVisitor(JsonFormatVisitor visitor, JavaType typeHint) { + public void acceptJsonFormatVisitor(JsonFormatVisitor visitor, Type typeHint) { visitor.anyFormat(); } diff --git a/src/main/java/com/fasterxml/jackson/databind/ser/std/StringSerializer.java b/src/main/java/com/fasterxml/jackson/databind/ser/std/StringSerializer.java index d03a05660c..5635039e58 100644 --- a/src/main/java/com/fasterxml/jackson/databind/ser/std/StringSerializer.java +++ b/src/main/java/com/fasterxml/jackson/databind/ser/std/StringSerializer.java @@ -1,10 +1,10 @@ package com.fasterxml.jackson.databind.ser.std; import java.io.IOException; +import java.lang.reflect.Type; import com.fasterxml.jackson.core.*; -import com.fasterxml.jackson.databind.JavaType; import com.fasterxml.jackson.databind.SerializerProvider; import com.fasterxml.jackson.databind.annotation.JacksonStdImpl; import com.fasterxml.jackson.databind.jsonschema.visitors.JsonFormatVisitor; @@ -37,7 +37,7 @@ public void serialize(String value, JsonGenerator jgen, SerializerProvider provi } @Override - public void acceptJsonFormatVisitor(JsonFormatVisitor visitor, JavaType typeHint) + public void acceptJsonFormatVisitor(JsonFormatVisitor visitor, Type typeHint) { visitor.stringFormat(); } diff --git a/src/main/java/com/fasterxml/jackson/databind/ser/std/ToStringSerializer.java b/src/main/java/com/fasterxml/jackson/databind/ser/std/ToStringSerializer.java index c664a57f52..83feb5770b 100644 --- a/src/main/java/com/fasterxml/jackson/databind/ser/std/ToStringSerializer.java +++ b/src/main/java/com/fasterxml/jackson/databind/ser/std/ToStringSerializer.java @@ -1,10 +1,10 @@ package com.fasterxml.jackson.databind.ser.std; import java.io.IOException; +import java.lang.reflect.Type; import com.fasterxml.jackson.core.*; -import com.fasterxml.jackson.databind.JavaType; import com.fasterxml.jackson.databind.JsonMappingException; import com.fasterxml.jackson.databind.JsonNode; import com.fasterxml.jackson.databind.SerializerProvider; @@ -75,7 +75,7 @@ public void serializeWithType(Object value, JsonGenerator jgen, SerializerProvid } @Override - public void acceptJsonFormatVisitor(JsonFormatVisitor visitor, JavaType typeHint) + public void acceptJsonFormatVisitor(JsonFormatVisitor visitor, Type typeHint) { visitor.stringFormat(); } diff --git a/src/main/java/com/fasterxml/jackson/databind/ser/std/TokenBufferSerializer.java b/src/main/java/com/fasterxml/jackson/databind/ser/std/TokenBufferSerializer.java index 55e34f4211..50dee4529b 100644 --- a/src/main/java/com/fasterxml/jackson/databind/ser/std/TokenBufferSerializer.java +++ b/src/main/java/com/fasterxml/jackson/databind/ser/std/TokenBufferSerializer.java @@ -1,10 +1,10 @@ package com.fasterxml.jackson.databind.ser.std; import java.io.IOException; +import java.lang.reflect.Type; import com.fasterxml.jackson.core.*; -import com.fasterxml.jackson.databind.JavaType; import com.fasterxml.jackson.databind.JsonNode; import com.fasterxml.jackson.databind.SerializerProvider; import com.fasterxml.jackson.databind.annotation.JacksonStdImpl; @@ -54,7 +54,7 @@ public final void serializeWithType(TokenBuffer value, JsonGenerator jgen, Seria } @Override - public void acceptJsonFormatVisitor(JsonFormatVisitor visitor, JavaType typeHint) + public void acceptJsonFormatVisitor(JsonFormatVisitor visitor, Type typeHint) { /* 01-Jan-2010, tatu: Not 100% sure what we should say here: * type is basically not known. This seems closest diff --git a/src/test/java/com/fasterxml/jackson/databind/module/TestSimpleModule.java b/src/test/java/com/fasterxml/jackson/databind/module/TestSimpleModule.java index b15e208970..2711d56f90 100644 --- a/src/test/java/com/fasterxml/jackson/databind/module/TestSimpleModule.java +++ b/src/test/java/com/fasterxml/jackson/databind/module/TestSimpleModule.java @@ -1,6 +1,7 @@ package com.fasterxml.jackson.databind.module; import java.io.IOException; +import java.lang.reflect.Type; import java.util.*; @@ -52,7 +53,7 @@ public void serialize(CustomBean value, JsonGenerator jgen, SerializerProvider p } @Override - public void acceptJsonFormatVisitor(JsonFormatVisitor visitor, JavaType typeHint) { + public void acceptJsonFormatVisitor(JsonFormatVisitor visitor, Type typeHint) { visitor.anyFormat(); } } @@ -86,7 +87,7 @@ public void serialize(SimpleEnum value, JsonGenerator jgen, SerializerProvider p } @Override - public void acceptJsonFormatVisitor(JsonFormatVisitor visitor, JavaType typeHint) { + public void acceptJsonFormatVisitor(JsonFormatVisitor visitor, Type typeHint) { visitor.anyFormat(); } } From cee882b97077da5e74c1f5daed90930404fb593d Mon Sep 17 00:00:00 2001 From: jackphel Date: Thu, 2 Aug 2012 20:56:03 -0400 Subject: [PATCH 08/19] working with JavaType --- .../databind/ext/CoreXMLSerializers.java | 4 +-- .../jackson/databind/ext/DOMSerializer.java | 4 +-- .../databind/jsonschema/SchemaAware.java | 4 +-- .../factories/ArraySchemaFactory.java | 2 +- .../factories/ObjectSchemaFactory.java | 10 +++--- .../jsonschema/factories/SchemaFactory.java | 7 ++-- .../visitors/JsonFormatVisitor.java | 7 ++-- .../visitors/JsonObjectFormatVisitor.java | 6 ++-- .../ser/DefaultSerializerProvider.java | 2 +- .../databind/ser/impl/FailingSerializer.java | 4 +-- .../ser/impl/StringArraySerializer.java | 3 +- .../databind/ser/impl/UnknownSerializer.java | 3 +- .../ser/std/AsArraySerializerBase.java | 10 ++---- .../databind/ser/std/BeanSerializerBase.java | 5 ++- .../databind/ser/std/BooleanSerializer.java | 4 +-- .../ser/std/DateTimeSerializerBase.java | 3 +- .../databind/ser/std/EnumMapSerializer.java | 4 +-- .../databind/ser/std/EnumSerializer.java | 6 ++-- .../databind/ser/std/JsonValueSerializer.java | 3 +- .../databind/ser/std/MapSerializer.java | 3 +- .../databind/ser/std/NullSerializer.java | 3 +- .../databind/ser/std/NumberSerializers.java | 13 ++++---- .../ser/std/ObjectArraySerializer.java | 5 ++- .../databind/ser/std/RawSerializer.java | 3 +- .../ser/std/SerializableSerializer.java | 10 +++--- .../databind/ser/std/SqlDateSerializer.java | 4 +-- .../databind/ser/std/SqlTimeSerializer.java | 4 +-- .../ser/std/StaticListSerializerBase.java | 4 +-- .../databind/ser/std/StdArraySerializers.java | 33 +++++++++---------- .../databind/ser/std/StdJdkSerializers.java | 13 ++++---- .../databind/ser/std/StdKeySerializer.java | 4 +-- .../databind/ser/std/StdScalarSerializer.java | 4 +-- .../databind/ser/std/StdSerializer.java | 3 +- .../databind/ser/std/StringSerializer.java | 4 +-- .../databind/ser/std/ToStringSerializer.java | 4 +-- .../ser/std/TokenBufferSerializer.java | 4 +-- .../databind/module/TestSimpleModule.java | 5 ++- 37 files changed, 96 insertions(+), 118 deletions(-) diff --git a/src/main/java/com/fasterxml/jackson/databind/ext/CoreXMLSerializers.java b/src/main/java/com/fasterxml/jackson/databind/ext/CoreXMLSerializers.java index 3f3dbc65e7..de718ffa2f 100644 --- a/src/main/java/com/fasterxml/jackson/databind/ext/CoreXMLSerializers.java +++ b/src/main/java/com/fasterxml/jackson/databind/ext/CoreXMLSerializers.java @@ -1,7 +1,6 @@ package com.fasterxml.jackson.databind.ext; import java.io.IOException; -import java.lang.reflect.Type; import java.util.Collection; import java.util.HashMap; import java.util.Map; @@ -12,6 +11,7 @@ import com.fasterxml.jackson.core.*; +import com.fasterxml.jackson.databind.JavaType; import com.fasterxml.jackson.databind.JsonMappingException; import com.fasterxml.jackson.databind.JsonNode; import com.fasterxml.jackson.databind.JsonSerializer; @@ -63,7 +63,7 @@ public void serialize(XMLGregorianCalendar value, JsonGenerator jgen, Serializer CalendarSerializer.instance.serialize(value.toGregorianCalendar(), jgen, provider); } - public void acceptJsonFormatVisitor(JsonFormatVisitor visitor, Type typeHint) { + public void acceptJsonFormatVisitor(JsonFormatVisitor visitor, JavaType typeHint) { CalendarSerializer.instance.acceptJsonFormatVisitor(visitor, null); } } diff --git a/src/main/java/com/fasterxml/jackson/databind/ext/DOMSerializer.java b/src/main/java/com/fasterxml/jackson/databind/ext/DOMSerializer.java index 215b288f09..f22f628ec1 100644 --- a/src/main/java/com/fasterxml/jackson/databind/ext/DOMSerializer.java +++ b/src/main/java/com/fasterxml/jackson/databind/ext/DOMSerializer.java @@ -1,7 +1,6 @@ package com.fasterxml.jackson.databind.ext; import java.io.IOException; -import java.lang.reflect.Type; import org.w3c.dom.Node; import org.w3c.dom.bootstrap.DOMImplementationRegistry; @@ -10,6 +9,7 @@ import com.fasterxml.jackson.core.*; +import com.fasterxml.jackson.databind.JavaType; import com.fasterxml.jackson.databind.SerializerProvider; import com.fasterxml.jackson.databind.jsonschema.visitors.JsonFormatVisitor; import com.fasterxml.jackson.databind.ser.std.StdSerializer; @@ -41,7 +41,7 @@ public void serialize(Node value, JsonGenerator jgen, SerializerProvider provide } @Override - public void acceptJsonFormatVisitor(JsonFormatVisitor visitor, Type typeHint) + public void acceptJsonFormatVisitor(JsonFormatVisitor visitor, JavaType typeHint) { visitor.anyFormat(); } diff --git a/src/main/java/com/fasterxml/jackson/databind/jsonschema/SchemaAware.java b/src/main/java/com/fasterxml/jackson/databind/jsonschema/SchemaAware.java index d3fdc461fa..e613086e4f 100644 --- a/src/main/java/com/fasterxml/jackson/databind/jsonschema/SchemaAware.java +++ b/src/main/java/com/fasterxml/jackson/databind/jsonschema/SchemaAware.java @@ -1,7 +1,7 @@ package com.fasterxml.jackson.databind.jsonschema; -import java.lang.reflect.Type; +import com.fasterxml.jackson.databind.JavaType; import com.fasterxml.jackson.databind.jsonschema.visitors.JsonFormatVisitor; /** @@ -15,5 +15,5 @@ public interface SchemaAware * * @return Json-schema for this serializer. */ - public void acceptJsonFormatVisitor(JsonFormatVisitor visitor, Type typeHint); + public void acceptJsonFormatVisitor(JsonFormatVisitor visitor, JavaType typeHint); } diff --git a/src/main/java/com/fasterxml/jackson/databind/jsonschema/factories/ArraySchemaFactory.java b/src/main/java/com/fasterxml/jackson/databind/jsonschema/factories/ArraySchemaFactory.java index 63607cb369..340f6f9ced 100644 --- a/src/main/java/com/fasterxml/jackson/databind/jsonschema/factories/ArraySchemaFactory.java +++ b/src/main/java/com/fasterxml/jackson/databind/jsonschema/factories/ArraySchemaFactory.java @@ -35,7 +35,7 @@ public void itemsFormat(JavaType contentType) { ser = getProvider().findValueSerializer(contentType, _property); if (ser instanceof SchemaAware) { SchemaFactory visitor = new SchemaFactory(provider); - ((SchemaAware) ser).acceptJsonFormatVisitor(visitor, null); + ((SchemaAware) ser).acceptJsonFormatVisitor(visitor, contentType); arraySchema.setItemsSchema(visitor.finalSchema()); } } catch (JsonMappingException e) { diff --git a/src/main/java/com/fasterxml/jackson/databind/jsonschema/factories/ObjectSchemaFactory.java b/src/main/java/com/fasterxml/jackson/databind/jsonschema/factories/ObjectSchemaFactory.java index 171f68d73d..59f76e1ef1 100644 --- a/src/main/java/com/fasterxml/jackson/databind/jsonschema/factories/ObjectSchemaFactory.java +++ b/src/main/java/com/fasterxml/jackson/databind/jsonschema/factories/ObjectSchemaFactory.java @@ -1,7 +1,7 @@ package com.fasterxml.jackson.databind.jsonschema.factories; -import java.lang.reflect.Type; +import com.fasterxml.jackson.databind.JavaType; import com.fasterxml.jackson.databind.JsonMappingException; import com.fasterxml.jackson.databind.JsonSerializer; import com.fasterxml.jackson.databind.jsonschema.SchemaAware; @@ -56,14 +56,14 @@ protected Schema propertySchema(BeanPropertyWriter writer) { Class serType = writerType(writer); JsonSerializer ser = getSer(writer, serType); if (ser != null && ser instanceof SchemaAware) { - ((SchemaAware)ser).acceptJsonFormatVisitor(visitor, serType); + ((SchemaAware)ser).acceptJsonFormatVisitor(visitor, writer.getType()); } else { visitor.anyFormat(); } return visitor.finalSchema(); } - protected Schema propertySchema(SchemaAware handler, Type propertyTypeHint) { + protected Schema propertySchema(SchemaAware handler, JavaType propertyTypeHint) { SchemaFactory visitor = new SchemaFactory(provider); handler.acceptJsonFormatVisitor(visitor, propertyTypeHint); return visitor.finalSchema(); @@ -77,11 +77,11 @@ public void optionalProperty(BeanPropertyWriter writer) { objectSchema.putOptionalProperty(writer.getName(), propertySchema(writer)); } - public void property(String name, SchemaAware handler, Type propertyTypeHint) { + public void property(String name, SchemaAware handler, JavaType propertyTypeHint) { objectSchema.putProperty(name, propertySchema(handler, propertyTypeHint)); } - public void optionalProperty(String name, SchemaAware handler, Type propertyTypeHint) { + public void optionalProperty(String name, SchemaAware handler, JavaType propertyTypeHint) { objectSchema.putOptionalProperty(name, propertySchema(handler, propertyTypeHint)); } diff --git a/src/main/java/com/fasterxml/jackson/databind/jsonschema/factories/SchemaFactory.java b/src/main/java/com/fasterxml/jackson/databind/jsonschema/factories/SchemaFactory.java index 94223846ce..1305f72c2f 100644 --- a/src/main/java/com/fasterxml/jackson/databind/jsonschema/factories/SchemaFactory.java +++ b/src/main/java/com/fasterxml/jackson/databind/jsonschema/factories/SchemaFactory.java @@ -1,7 +1,6 @@ package com.fasterxml.jackson.databind.jsonschema.factories; -import java.lang.reflect.Type; - +import com.fasterxml.jackson.databind.JavaType; import com.fasterxml.jackson.databind.SerializerProvider; import com.fasterxml.jackson.databind.jsonschema.types.Schema; import com.fasterxml.jackson.databind.jsonschema.visitors.JsonAnyFormatVisitor; @@ -28,7 +27,7 @@ public JsonAnyFormatVisitor anyFormat() { return (JsonAnyFormatVisitor) delegate; } - public JsonArrayFormatVisitor arrayFormat(Type elementType) { + public JsonArrayFormatVisitor arrayFormat(JavaType elementType) { delegate = new ArraySchemaFactory(this); return (JsonArrayFormatVisitor) delegate; } @@ -67,7 +66,7 @@ public JsonNumberFormatVisitor numberFormat() { return (JsonNumberFormatVisitor) delegate; } - public JsonObjectFormatVisitor objectFormat(Type type) { + public JsonObjectFormatVisitor objectFormat(JavaType type) { // BasicClassIntrospector.instance. delegate = new ObjectSchemaFactory(this); return (JsonObjectFormatVisitor) delegate; diff --git a/src/main/java/com/fasterxml/jackson/databind/jsonschema/visitors/JsonFormatVisitor.java b/src/main/java/com/fasterxml/jackson/databind/jsonschema/visitors/JsonFormatVisitor.java index aae53a9405..66181e385e 100644 --- a/src/main/java/com/fasterxml/jackson/databind/jsonschema/visitors/JsonFormatVisitor.java +++ b/src/main/java/com/fasterxml/jackson/databind/jsonschema/visitors/JsonFormatVisitor.java @@ -1,13 +1,12 @@ package com.fasterxml.jackson.databind.jsonschema.visitors; -import java.lang.reflect.Type; - +import com.fasterxml.jackson.databind.JavaType; import com.fasterxml.jackson.databind.SerializerProvider; public interface JsonFormatVisitor { - public JsonObjectFormatVisitor objectFormat(Type type); - public JsonArrayFormatVisitor arrayFormat(Type elementType); + public JsonObjectFormatVisitor objectFormat(JavaType type); + public JsonArrayFormatVisitor arrayFormat(JavaType elementType); public JsonStringFormatVisitor stringFormat(); public JsonNumberFormatVisitor numberFormat(); public JsonIntegerFormatVisitor integerFormat(); diff --git a/src/main/java/com/fasterxml/jackson/databind/jsonschema/visitors/JsonObjectFormatVisitor.java b/src/main/java/com/fasterxml/jackson/databind/jsonschema/visitors/JsonObjectFormatVisitor.java index 0a2113b1aa..679da671e2 100644 --- a/src/main/java/com/fasterxml/jackson/databind/jsonschema/visitors/JsonObjectFormatVisitor.java +++ b/src/main/java/com/fasterxml/jackson/databind/jsonschema/visitors/JsonObjectFormatVisitor.java @@ -1,7 +1,7 @@ package com.fasterxml.jackson.databind.jsonschema.visitors; -import java.lang.reflect.Type; +import com.fasterxml.jackson.databind.JavaType; import com.fasterxml.jackson.databind.jsonschema.SchemaAware; import com.fasterxml.jackson.databind.ser.BeanPropertyWriter; @@ -11,10 +11,10 @@ public interface JsonObjectFormatVisitor extends JsonFormatVisitor { public void optionalProperty(BeanPropertyWriter writer); - public void property(String name, SchemaAware handler, Type propertyTypeHint); + public void property(String name, SchemaAware handler, JavaType propertyTypeHint); public void optionalProperty(String name, SchemaAware handler, - Type propertyTypeHint); + JavaType propertyTypeHint); public void property(String name); diff --git a/src/main/java/com/fasterxml/jackson/databind/ser/DefaultSerializerProvider.java b/src/main/java/com/fasterxml/jackson/databind/ser/DefaultSerializerProvider.java index 8a471bea33..88f7e9debb 100644 --- a/src/main/java/com/fasterxml/jackson/databind/ser/DefaultSerializerProvider.java +++ b/src/main/java/com/fasterxml/jackson/databind/ser/DefaultSerializerProvider.java @@ -247,7 +247,7 @@ public void acceptJsonFormatVisitor(Class type, JsonFormatVisitor visitor) */ JsonSerializer ser = findValueSerializer(type, null); if (ser instanceof SchemaAware) { - ((SchemaAware) ser).acceptJsonFormatVisitor(visitor, type); + ((SchemaAware) ser).acceptJsonFormatVisitor(visitor, constructType(type)); } else { visitor.anyFormat(); } diff --git a/src/main/java/com/fasterxml/jackson/databind/ser/impl/FailingSerializer.java b/src/main/java/com/fasterxml/jackson/databind/ser/impl/FailingSerializer.java index f2041f7542..e023f3091c 100644 --- a/src/main/java/com/fasterxml/jackson/databind/ser/impl/FailingSerializer.java +++ b/src/main/java/com/fasterxml/jackson/databind/ser/impl/FailingSerializer.java @@ -1,10 +1,10 @@ package com.fasterxml.jackson.databind.ser.impl; import java.io.IOException; -import java.lang.reflect.Type; import com.fasterxml.jackson.core.*; +import com.fasterxml.jackson.databind.JavaType; import com.fasterxml.jackson.databind.SerializerProvider; import com.fasterxml.jackson.databind.jsonschema.visitors.JsonFormatVisitor; import com.fasterxml.jackson.databind.ser.std.StdSerializer; @@ -34,7 +34,7 @@ public void serialize(Object value, JsonGenerator jgen, SerializerProvider provi } @Override - public void acceptJsonFormatVisitor(JsonFormatVisitor visitor, Type typeHint) + public void acceptJsonFormatVisitor(JsonFormatVisitor visitor, JavaType typeHint) { ; } diff --git a/src/main/java/com/fasterxml/jackson/databind/ser/impl/StringArraySerializer.java b/src/main/java/com/fasterxml/jackson/databind/ser/impl/StringArraySerializer.java index 5050c94ff8..eb2bc77457 100644 --- a/src/main/java/com/fasterxml/jackson/databind/ser/impl/StringArraySerializer.java +++ b/src/main/java/com/fasterxml/jackson/databind/ser/impl/StringArraySerializer.java @@ -1,7 +1,6 @@ package com.fasterxml.jackson.databind.ser.impl; import java.io.IOException; -import java.lang.reflect.Type; import com.fasterxml.jackson.core.JsonGenerationException; import com.fasterxml.jackson.core.JsonGenerator; @@ -171,7 +170,7 @@ private void serializeContentsSlow(String[] value, JsonGenerator jgen, Serialize } @Override - public void acceptJsonFormatVisitor(JsonFormatVisitor visitor, Type typeHint) + public void acceptJsonFormatVisitor(JsonFormatVisitor visitor, JavaType typeHint) { visitor.arrayFormat(null).itemsFormat(SchemaType.STRING); } diff --git a/src/main/java/com/fasterxml/jackson/databind/ser/impl/UnknownSerializer.java b/src/main/java/com/fasterxml/jackson/databind/ser/impl/UnknownSerializer.java index 02fc5dc024..800ccc41f7 100644 --- a/src/main/java/com/fasterxml/jackson/databind/ser/impl/UnknownSerializer.java +++ b/src/main/java/com/fasterxml/jackson/databind/ser/impl/UnknownSerializer.java @@ -1,7 +1,6 @@ package com.fasterxml.jackson.databind.ser.impl; import java.io.IOException; -import java.lang.reflect.Type; import com.fasterxml.jackson.core.*; @@ -43,7 +42,7 @@ public final void serializeWithType(Object value, JsonGenerator jgen, Serializer } @Override - public void acceptJsonFormatVisitor(JsonFormatVisitor visitor, Type typeHint) { + public void acceptJsonFormatVisitor(JsonFormatVisitor visitor, JavaType typeHint) { visitor.anyFormat(); } diff --git a/src/main/java/com/fasterxml/jackson/databind/ser/std/AsArraySerializerBase.java b/src/main/java/com/fasterxml/jackson/databind/ser/std/AsArraySerializerBase.java index 1de06418ac..71b4ff67c8 100644 --- a/src/main/java/com/fasterxml/jackson/databind/ser/std/AsArraySerializerBase.java +++ b/src/main/java/com/fasterxml/jackson/databind/ser/std/AsArraySerializerBase.java @@ -7,12 +7,9 @@ import com.fasterxml.jackson.core.*; import com.fasterxml.jackson.databind.*; -import com.fasterxml.jackson.databind.jsonschema.JsonSchema; -import com.fasterxml.jackson.databind.jsonschema.SchemaAware; import com.fasterxml.jackson.databind.jsonschema.visitors.JsonArrayFormatVisitor; import com.fasterxml.jackson.databind.jsonschema.visitors.JsonFormatVisitor; import com.fasterxml.jackson.databind.jsontype.TypeSerializer; -import com.fasterxml.jackson.databind.node.ObjectNode; import com.fasterxml.jackson.databind.ser.ContainerSerializer; import com.fasterxml.jackson.databind.ser.ContextualSerializer; import com.fasterxml.jackson.databind.ser.impl.PropertySerializerMap; @@ -168,7 +165,7 @@ protected abstract void serializeContents(T value, JsonGenerator jgen, Serialize throws IOException, JsonGenerationException; @Override - public void acceptJsonFormatVisitor(JsonFormatVisitor visitor, Type typeHint) + public void acceptJsonFormatVisitor(JsonFormatVisitor visitor, JavaType typeHint) { /* 15-Jan-2010, tatu: This should probably be rewritten, given that * more information about content type is actually being explicitly @@ -177,11 +174,10 @@ public void acceptJsonFormatVisitor(JsonFormatVisitor visitor, Type typeHint) */ //ObjectNode o = createSchemaNode("array", true); JsonArrayFormatVisitor arrayVisitor = - visitor.arrayFormat(typeHint == null ? _elementType.getRawClass() : typeHint); + visitor.arrayFormat(typeHint); JavaType contentType = null; if (typeHint != null) { - JavaType javaType = visitor.getProvider().constructType(typeHint); - contentType = javaType.getContentType(); + contentType = typeHint.getContentType(); if (contentType == null) { // could still be parametrized (Iterators) if (typeHint instanceof ParameterizedType) { Type[] typeArgs = ((ParameterizedType) typeHint).getActualTypeArguments(); diff --git a/src/main/java/com/fasterxml/jackson/databind/ser/std/BeanSerializerBase.java b/src/main/java/com/fasterxml/jackson/databind/ser/std/BeanSerializerBase.java index eac8280b74..db9ba34aeb 100644 --- a/src/main/java/com/fasterxml/jackson/databind/ser/std/BeanSerializerBase.java +++ b/src/main/java/com/fasterxml/jackson/databind/ser/std/BeanSerializerBase.java @@ -1,7 +1,6 @@ package com.fasterxml.jackson.databind.ser.std; import java.io.IOException; -import java.lang.reflect.Type; import java.util.*; import com.fasterxml.jackson.annotation.JsonFormat; @@ -627,9 +626,9 @@ protected BeanPropertyFilter findFilter(SerializerProvider provider) return filter; } - public void acceptJsonFormatVisitor(JsonFormatVisitor visitor, Type typeHint) + public void acceptJsonFormatVisitor(JsonFormatVisitor visitor, JavaType typeHint) { - JsonObjectFormatVisitor objectVisitor = visitor.objectFormat(typeHint == null ? _handledType : typeHint); + JsonObjectFormatVisitor objectVisitor = visitor.objectFormat(typeHint); // [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); diff --git a/src/main/java/com/fasterxml/jackson/databind/ser/std/BooleanSerializer.java b/src/main/java/com/fasterxml/jackson/databind/ser/std/BooleanSerializer.java index 6bd3be5288..3c11db1f99 100644 --- a/src/main/java/com/fasterxml/jackson/databind/ser/std/BooleanSerializer.java +++ b/src/main/java/com/fasterxml/jackson/databind/ser/std/BooleanSerializer.java @@ -1,11 +1,11 @@ package com.fasterxml.jackson.databind.ser.std; import java.io.IOException; -import java.lang.reflect.Type; import com.fasterxml.jackson.core.JsonGenerationException; import com.fasterxml.jackson.core.JsonGenerator; +import com.fasterxml.jackson.databind.JavaType; import com.fasterxml.jackson.databind.JsonNode; import com.fasterxml.jackson.databind.SerializerProvider; import com.fasterxml.jackson.databind.annotation.JacksonStdImpl; @@ -42,7 +42,7 @@ public void serialize(Boolean value, JsonGenerator jgen, SerializerProvider prov } @Override - public void acceptJsonFormatVisitor(JsonFormatVisitor visitor, Type typeHint) + public void acceptJsonFormatVisitor(JsonFormatVisitor visitor, JavaType typeHint) { visitor.booleanFormat(); } diff --git a/src/main/java/com/fasterxml/jackson/databind/ser/std/DateTimeSerializerBase.java b/src/main/java/com/fasterxml/jackson/databind/ser/std/DateTimeSerializerBase.java index 79b5dacdf3..31f5910c67 100644 --- a/src/main/java/com/fasterxml/jackson/databind/ser/std/DateTimeSerializerBase.java +++ b/src/main/java/com/fasterxml/jackson/databind/ser/std/DateTimeSerializerBase.java @@ -1,7 +1,6 @@ package com.fasterxml.jackson.databind.ser.std; import java.io.IOException; -import java.lang.reflect.Type; import java.text.DateFormat; import java.text.SimpleDateFormat; import java.util.Locale; @@ -102,7 +101,7 @@ public boolean isEmpty(T value) { protected abstract long _timestamp(T value); - public void acceptJsonFormatVisitor(JsonFormatVisitor visitor, Type typeHint) + public void acceptJsonFormatVisitor(JsonFormatVisitor visitor, JavaType typeHint) { //todo: (ryan) add a format for the date in the schema? boolean asNumber = _useTimestamp; diff --git a/src/main/java/com/fasterxml/jackson/databind/ser/std/EnumMapSerializer.java b/src/main/java/com/fasterxml/jackson/databind/ser/std/EnumMapSerializer.java index b65a75da1a..d5c36555c8 100644 --- a/src/main/java/com/fasterxml/jackson/databind/ser/std/EnumMapSerializer.java +++ b/src/main/java/com/fasterxml/jackson/databind/ser/std/EnumMapSerializer.java @@ -252,7 +252,7 @@ protected void serializeContentsUsing(EnumMap,?> value, JsonGe @SuppressWarnings("unchecked") @Override - public void acceptJsonFormatVisitor(JsonFormatVisitor visitor, Type typeHint) + public void acceptJsonFormatVisitor(JsonFormatVisitor visitor, JavaType typeHint) { JsonObjectFormatVisitor objectVisitor = visitor.objectFormat(typeHint); if (typeHint instanceof ParameterizedType) { @@ -268,7 +268,7 @@ public void acceptJsonFormatVisitor(JsonFormatVisitor visitor, Type typeHint) try { ser = visitor.getProvider().findValueSerializer(valueType.getRawClass(), _property); if (ser instanceof SchemaAware) { - objectVisitor.property(name, (SchemaAware) ser, typeArgs[1]); + objectVisitor.property(name, (SchemaAware) ser, valueType); } continue; } catch (JsonMappingException e) { diff --git a/src/main/java/com/fasterxml/jackson/databind/ser/std/EnumSerializer.java b/src/main/java/com/fasterxml/jackson/databind/ser/std/EnumSerializer.java index 1da790eca4..59d09eba17 100644 --- a/src/main/java/com/fasterxml/jackson/databind/ser/std/EnumSerializer.java +++ b/src/main/java/com/fasterxml/jackson/databind/ser/std/EnumSerializer.java @@ -1,7 +1,6 @@ package com.fasterxml.jackson.databind.ser.std; import java.io.IOException; -import java.lang.reflect.Type; import java.util.HashSet; import java.util.Set; @@ -65,7 +64,7 @@ public final void serialize(Enum en, JsonGenerator jgen, SerializerProvider p } @Override - public void acceptJsonFormatVisitor(JsonFormatVisitor visitor, Type typeHint) + public void acceptJsonFormatVisitor(JsonFormatVisitor visitor, JavaType typeHint) { // [JACKSON-684]: serialize as index? if (visitor.getProvider().isEnabled(SerializationFeature.WRITE_ENUMS_USING_INDEX)) { @@ -73,8 +72,7 @@ public void acceptJsonFormatVisitor(JsonFormatVisitor visitor, Type typeHint) } else { JsonStringFormatVisitor stringVisitor = visitor.stringFormat(); if (typeHint != null) { - JavaType type = visitor.getProvider().constructType(typeHint); - if (type.isEnumType()) { + if (typeHint.isEnumType()) { Set enums = new HashSet(); for (SerializedString value : _values.values()) { enums.add(value.getValue()); diff --git a/src/main/java/com/fasterxml/jackson/databind/ser/std/JsonValueSerializer.java b/src/main/java/com/fasterxml/jackson/databind/ser/std/JsonValueSerializer.java index d2cf606508..797d3bb486 100644 --- a/src/main/java/com/fasterxml/jackson/databind/ser/std/JsonValueSerializer.java +++ b/src/main/java/com/fasterxml/jackson/databind/ser/std/JsonValueSerializer.java @@ -4,7 +4,6 @@ import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Method; import java.lang.reflect.Modifier; -import java.lang.reflect.Type; import com.fasterxml.jackson.core.*; @@ -231,7 +230,7 @@ public void serializeWithType(Object bean, JsonGenerator jgen, SerializerProvide } @Override - public void acceptJsonFormatVisitor(JsonFormatVisitor visitor, Type typeHint) + public void acceptJsonFormatVisitor(JsonFormatVisitor visitor, JavaType typeHint) { if (_valueSerializer instanceof SchemaAware) { ((SchemaAware) _valueSerializer).acceptJsonFormatVisitor(visitor, null); diff --git a/src/main/java/com/fasterxml/jackson/databind/ser/std/MapSerializer.java b/src/main/java/com/fasterxml/jackson/databind/ser/std/MapSerializer.java index 61f69ae2a8..d09da061c9 100644 --- a/src/main/java/com/fasterxml/jackson/databind/ser/std/MapSerializer.java +++ b/src/main/java/com/fasterxml/jackson/databind/ser/std/MapSerializer.java @@ -1,7 +1,6 @@ package com.fasterxml.jackson.databind.ser.std; import java.io.IOException; -import java.lang.reflect.Type; import java.util.*; import com.fasterxml.jackson.core.*; @@ -467,7 +466,7 @@ protected void serializeTypedFields(Map value, JsonGenerator jgen, Serializ } @Override - public void acceptJsonFormatVisitor(JsonFormatVisitor visitor, Type typeHint) + public void acceptJsonFormatVisitor(JsonFormatVisitor visitor, JavaType typeHint) { visitor.objectFormat(null); } diff --git a/src/main/java/com/fasterxml/jackson/databind/ser/std/NullSerializer.java b/src/main/java/com/fasterxml/jackson/databind/ser/std/NullSerializer.java index 200ab48730..b2f675e38b 100644 --- a/src/main/java/com/fasterxml/jackson/databind/ser/std/NullSerializer.java +++ b/src/main/java/com/fasterxml/jackson/databind/ser/std/NullSerializer.java @@ -1,6 +1,5 @@ package com.fasterxml.jackson.databind.ser.std; -import java.lang.reflect.Type; import java.io.IOException; import com.fasterxml.jackson.core.*; @@ -32,7 +31,7 @@ public void serialize(Object value, JsonGenerator jgen, SerializerProvider provi } @Override - public void acceptJsonFormatVisitor(JsonFormatVisitor visitor, Type typeHint) + public void acceptJsonFormatVisitor(JsonFormatVisitor visitor, JavaType typeHint) { visitor.nullFormat(); } diff --git a/src/main/java/com/fasterxml/jackson/databind/ser/std/NumberSerializers.java b/src/main/java/com/fasterxml/jackson/databind/ser/std/NumberSerializers.java index 4e6f506e20..db5c679daf 100644 --- a/src/main/java/com/fasterxml/jackson/databind/ser/std/NumberSerializers.java +++ b/src/main/java/com/fasterxml/jackson/databind/ser/std/NumberSerializers.java @@ -1,7 +1,6 @@ package com.fasterxml.jackson.databind.ser.std; import java.io.IOException; -import java.lang.reflect.Type; import java.math.BigDecimal; import java.math.BigInteger; import java.util.Map; @@ -72,7 +71,7 @@ public void serialize(Integer value, JsonGenerator jgen, SerializerProvider prov } @Override - public void acceptJsonFormatVisitor(JsonFormatVisitor visitor, Type typeHint) + public void acceptJsonFormatVisitor(JsonFormatVisitor visitor, JavaType typeHint) { visitor.integerFormat(); } @@ -99,7 +98,7 @@ public void serialize(Number value, JsonGenerator jgen, SerializerProvider provi } @Override - public void acceptJsonFormatVisitor(JsonFormatVisitor visitor, Type typeHint) + public void acceptJsonFormatVisitor(JsonFormatVisitor visitor, JavaType typeHint) { visitor.integerFormat(); } @@ -121,7 +120,7 @@ public void serialize(Long value, JsonGenerator jgen, SerializerProvider provide } @Override - public void acceptJsonFormatVisitor(JsonFormatVisitor visitor, Type typeHint) + public void acceptJsonFormatVisitor(JsonFormatVisitor visitor, JavaType typeHint) { visitor.numberFormat(); } @@ -143,7 +142,7 @@ public void serialize(Float value, JsonGenerator jgen, SerializerProvider provid } @Override - public void acceptJsonFormatVisitor(JsonFormatVisitor visitor, Type typeHint) + public void acceptJsonFormatVisitor(JsonFormatVisitor visitor, JavaType typeHint) { visitor.numberFormat(); } @@ -172,7 +171,7 @@ public void serialize(Double value, JsonGenerator jgen, SerializerProvider provi } @Override - public void acceptJsonFormatVisitor(JsonFormatVisitor visitor, Type typeHint) + public void acceptJsonFormatVisitor(JsonFormatVisitor visitor, JavaType typeHint) { visitor.numberFormat(); } @@ -220,7 +219,7 @@ public void serialize(Number value, JsonGenerator jgen, SerializerProvider provi } @Override - public void acceptJsonFormatVisitor(JsonFormatVisitor visitor, Type typeHint) + public void acceptJsonFormatVisitor(JsonFormatVisitor visitor, JavaType typeHint) { visitor.numberFormat(); } diff --git a/src/main/java/com/fasterxml/jackson/databind/ser/std/ObjectArraySerializer.java b/src/main/java/com/fasterxml/jackson/databind/ser/std/ObjectArraySerializer.java index dc213071aa..275a402aaa 100644 --- a/src/main/java/com/fasterxml/jackson/databind/ser/std/ObjectArraySerializer.java +++ b/src/main/java/com/fasterxml/jackson/databind/ser/std/ObjectArraySerializer.java @@ -2,7 +2,6 @@ import java.io.IOException; import java.lang.reflect.InvocationTargetException; -import java.lang.reflect.Type; import com.fasterxml.jackson.core.*; @@ -297,9 +296,9 @@ public void serializeTypedContents(Object[] value, JsonGenerator jgen, Serialize } @Override - public void acceptJsonFormatVisitor(JsonFormatVisitor visitor, Type typeHint) + public void acceptJsonFormatVisitor(JsonFormatVisitor visitor, JavaType typeHint) { - visitor.arrayFormat(typeHint == null ? _property.getType().getRawClass() : typeHint).itemsFormat(_elementType); + visitor.arrayFormat(typeHint).itemsFormat(_elementType); } protected final JsonSerializer _findAndAddDynamic(PropertySerializerMap map, diff --git a/src/main/java/com/fasterxml/jackson/databind/ser/std/RawSerializer.java b/src/main/java/com/fasterxml/jackson/databind/ser/std/RawSerializer.java index 2924f892c3..891a86964b 100644 --- a/src/main/java/com/fasterxml/jackson/databind/ser/std/RawSerializer.java +++ b/src/main/java/com/fasterxml/jackson/databind/ser/std/RawSerializer.java @@ -1,7 +1,6 @@ package com.fasterxml.jackson.databind.ser.std; import java.io.IOException; -import java.lang.reflect.Type; import com.fasterxml.jackson.core.*; @@ -45,7 +44,7 @@ public void serializeWithType(T value, JsonGenerator jgen, SerializerProvider pr } @Override - public void acceptJsonFormatVisitor(JsonFormatVisitor visitor, Type typeHint) + public void acceptJsonFormatVisitor(JsonFormatVisitor visitor, JavaType typeHint) { visitor.stringFormat(); } diff --git a/src/main/java/com/fasterxml/jackson/databind/ser/std/SerializableSerializer.java b/src/main/java/com/fasterxml/jackson/databind/ser/std/SerializableSerializer.java index aafe96be0f..da24334f37 100644 --- a/src/main/java/com/fasterxml/jackson/databind/ser/std/SerializableSerializer.java +++ b/src/main/java/com/fasterxml/jackson/databind/ser/std/SerializableSerializer.java @@ -1,12 +1,12 @@ package com.fasterxml.jackson.databind.ser.std; import java.io.IOException; -import java.lang.reflect.Type; import java.util.concurrent.atomic.AtomicReference; import com.fasterxml.jackson.core.*; +import com.fasterxml.jackson.databind.JavaType; import com.fasterxml.jackson.databind.JsonMappingException; import com.fasterxml.jackson.databind.JsonNode; import com.fasterxml.jackson.databind.JsonSerializable; @@ -55,21 +55,21 @@ public final void serializeWithType(JsonSerializable value, JsonGenerator jgen, } @Override - public void acceptJsonFormatVisitor(JsonFormatVisitor visitor, Type typeHint) + public void acceptJsonFormatVisitor(JsonFormatVisitor visitor, JavaType typeHint) { if (typeHint == null) { visitor.anyFormat(); } else { - Class rawClass = TypeFactory.rawClass(typeHint); + Class rawClass = typeHint.getRawClass(); if (rawClass.isAnnotationPresent(JsonSerializableSchema.class)) { JsonSerializableSchema schemaInfo = rawClass.getAnnotation(JsonSerializableSchema.class); if (!JsonSerializableSchema.NO_VALUE.equals(schemaInfo.schemaObjectPropertiesDefinition())) { - visitor.objectFormat(rawClass); + visitor.objectFormat(typeHint); //objectProperties = schemaInfo.schemaObjectPropertiesDefinition(); } else if (!JsonSerializableSchema.NO_VALUE.equals(schemaInfo.schemaItemDefinition())) { - visitor.arrayFormat(rawClass); + visitor.arrayFormat(typeHint); //itemDefinition = schemaInfo.schemaItemDefinition(); } else { visitor.anyFormat(); diff --git a/src/main/java/com/fasterxml/jackson/databind/ser/std/SqlDateSerializer.java b/src/main/java/com/fasterxml/jackson/databind/ser/std/SqlDateSerializer.java index 6dbdb1d406..2e3be58509 100644 --- a/src/main/java/com/fasterxml/jackson/databind/ser/std/SqlDateSerializer.java +++ b/src/main/java/com/fasterxml/jackson/databind/ser/std/SqlDateSerializer.java @@ -1,11 +1,11 @@ package com.fasterxml.jackson.databind.ser.std; import java.io.IOException; -import java.lang.reflect.Type; import com.fasterxml.jackson.core.JsonGenerationException; import com.fasterxml.jackson.core.JsonGenerator; +import com.fasterxml.jackson.databind.JavaType; import com.fasterxml.jackson.databind.JsonNode; import com.fasterxml.jackson.databind.SerializerProvider; import com.fasterxml.jackson.databind.annotation.JacksonStdImpl; @@ -31,7 +31,7 @@ public void serialize(java.sql.Date value, JsonGenerator jgen, SerializerProvide } @Override - public void acceptJsonFormatVisitor(JsonFormatVisitor visitor, Type typeHint) + public void acceptJsonFormatVisitor(JsonFormatVisitor visitor, JavaType typeHint) { visitor.stringFormat().format(JsonValueFormat.DATE_TIME); } diff --git a/src/main/java/com/fasterxml/jackson/databind/ser/std/SqlTimeSerializer.java b/src/main/java/com/fasterxml/jackson/databind/ser/std/SqlTimeSerializer.java index 7efd7c1867..25f6fb218e 100644 --- a/src/main/java/com/fasterxml/jackson/databind/ser/std/SqlTimeSerializer.java +++ b/src/main/java/com/fasterxml/jackson/databind/ser/std/SqlTimeSerializer.java @@ -1,11 +1,11 @@ package com.fasterxml.jackson.databind.ser.std; import java.io.IOException; -import java.lang.reflect.Type; import com.fasterxml.jackson.core.JsonGenerationException; import com.fasterxml.jackson.core.JsonGenerator; +import com.fasterxml.jackson.databind.JavaType; import com.fasterxml.jackson.databind.JsonNode; import com.fasterxml.jackson.databind.SerializerProvider; import com.fasterxml.jackson.databind.annotation.JacksonStdImpl; @@ -26,7 +26,7 @@ public void serialize(java.sql.Time value, JsonGenerator jgen, SerializerProvide } @Override - public void acceptJsonFormatVisitor(JsonFormatVisitor visitor, Type typeHint) + public void acceptJsonFormatVisitor(JsonFormatVisitor visitor, JavaType typeHint) { visitor.stringFormat().format(JsonValueFormat.DATE_TIME); } diff --git a/src/main/java/com/fasterxml/jackson/databind/ser/std/StaticListSerializerBase.java b/src/main/java/com/fasterxml/jackson/databind/ser/std/StaticListSerializerBase.java index 313340b508..798eaa454d 100644 --- a/src/main/java/com/fasterxml/jackson/databind/ser/std/StaticListSerializerBase.java +++ b/src/main/java/com/fasterxml/jackson/databind/ser/std/StaticListSerializerBase.java @@ -1,8 +1,8 @@ package com.fasterxml.jackson.databind.ser.std; -import java.lang.reflect.Type; import java.util.*; +import com.fasterxml.jackson.databind.JavaType; import com.fasterxml.jackson.databind.JsonNode; import com.fasterxml.jackson.databind.SerializerProvider; import com.fasterxml.jackson.databind.jsonschema.SchemaAware; @@ -27,7 +27,7 @@ public boolean isEmpty(T value) { } @Override - public void acceptJsonFormatVisitor(JsonFormatVisitor visitor, Type typeHint) + public void acceptJsonFormatVisitor(JsonFormatVisitor visitor, JavaType typeHint) { acceptContentVisitor(visitor.arrayFormat(typeHint)); } diff --git a/src/main/java/com/fasterxml/jackson/databind/ser/std/StdArraySerializers.java b/src/main/java/com/fasterxml/jackson/databind/ser/std/StdArraySerializers.java index d9d90e7486..cd80815a6c 100644 --- a/src/main/java/com/fasterxml/jackson/databind/ser/std/StdArraySerializers.java +++ b/src/main/java/com/fasterxml/jackson/databind/ser/std/StdArraySerializers.java @@ -1,7 +1,6 @@ package com.fasterxml.jackson.databind.ser.std; import java.io.IOException; -import java.lang.reflect.Type; import java.util.HashMap; import com.fasterxml.jackson.core.*; @@ -131,9 +130,9 @@ public void serializeContents(boolean[] value, JsonGenerator jgen, SerializerPro } @Override - public void acceptJsonFormatVisitor(JsonFormatVisitor visitor, Type typeHint) + public void acceptJsonFormatVisitor(JsonFormatVisitor visitor, JavaType typeHint) { - visitor.arrayFormat(typeHint == null ? _handledType : typeHint).itemsFormat(SchemaType.BOOLEAN); + visitor.arrayFormat(typeHint).itemsFormat(SchemaType.BOOLEAN); } } @@ -175,9 +174,9 @@ public void serializeWithType(byte[] value, JsonGenerator jgen, SerializerProvid } @Override - public void acceptJsonFormatVisitor(JsonFormatVisitor visitor, Type typeHint) + public void acceptJsonFormatVisitor(JsonFormatVisitor visitor, JavaType typeHint) { - visitor.arrayFormat(typeHint == null ? _handledType : typeHint).itemsFormat(SchemaType.STRING); + visitor.arrayFormat(typeHint).itemsFormat(SchemaType.STRING); } } @@ -238,9 +237,9 @@ public void serializeContents(short[] value, JsonGenerator jgen, SerializerProvi } @Override - public void acceptJsonFormatVisitor(JsonFormatVisitor visitor, Type typeHint) + public void acceptJsonFormatVisitor(JsonFormatVisitor visitor, JavaType typeHint) { - visitor.arrayFormat(typeHint == null ? _handledType : typeHint).itemsFormat(SchemaType.INTEGER); + visitor.arrayFormat(typeHint).itemsFormat(SchemaType.INTEGER); } } @@ -302,9 +301,9 @@ private final void _writeArrayContents(JsonGenerator jgen, char[] value) } @Override - public void acceptJsonFormatVisitor(JsonFormatVisitor visitor, Type typeHint) + public void acceptJsonFormatVisitor(JsonFormatVisitor visitor, JavaType typeHint) { - visitor.arrayFormat(typeHint == null ? _handledType : typeHint).itemsFormat(SchemaType.STRING); + visitor.arrayFormat(typeHint).itemsFormat(SchemaType.STRING); } } @@ -357,9 +356,9 @@ public void serializeContents(int[] value, JsonGenerator jgen, SerializerProvide } @Override - public void acceptJsonFormatVisitor(JsonFormatVisitor visitor, Type typeHint) + public void acceptJsonFormatVisitor(JsonFormatVisitor visitor, JavaType typeHint) { - visitor.arrayFormat(typeHint == null ? _handledType : typeHint).itemsFormat(SchemaType.INTEGER); + visitor.arrayFormat(typeHint).itemsFormat(SchemaType.INTEGER); } } @@ -421,9 +420,9 @@ public void serializeContents(long[] value, JsonGenerator jgen, SerializerProvid } @Override - public void acceptJsonFormatVisitor(JsonFormatVisitor visitor, Type typeHint) + public void acceptJsonFormatVisitor(JsonFormatVisitor visitor, JavaType typeHint) { - visitor.arrayFormat(typeHint == null ? _handledType : typeHint).itemsFormat(SchemaType.NUMBER); + visitor.arrayFormat(typeHint).itemsFormat(SchemaType.NUMBER); } } @@ -486,9 +485,9 @@ public void serializeContents(float[] value, JsonGenerator jgen, SerializerProvi } @Override - public void acceptJsonFormatVisitor(JsonFormatVisitor visitor, Type typeHint) + public void acceptJsonFormatVisitor(JsonFormatVisitor visitor, JavaType typeHint) { - visitor.arrayFormat(typeHint == null ? _handledType : typeHint).itemsFormat(SchemaType.NUMBER); + visitor.arrayFormat(typeHint).itemsFormat(SchemaType.NUMBER); } } @@ -541,9 +540,9 @@ public void serializeContents(double[] value, JsonGenerator jgen, SerializerProv } @Override - public void acceptJsonFormatVisitor(JsonFormatVisitor visitor, Type typeHint) + public void acceptJsonFormatVisitor(JsonFormatVisitor visitor, JavaType typeHint) { - visitor.arrayFormat(typeHint == null ? _handledType : typeHint).itemsFormat(SchemaType.NUMBER); + visitor.arrayFormat(typeHint).itemsFormat(SchemaType.NUMBER); } } } diff --git a/src/main/java/com/fasterxml/jackson/databind/ser/std/StdJdkSerializers.java b/src/main/java/com/fasterxml/jackson/databind/ser/std/StdJdkSerializers.java index 3859f41eac..e3a71a1f46 100644 --- a/src/main/java/com/fasterxml/jackson/databind/ser/std/StdJdkSerializers.java +++ b/src/main/java/com/fasterxml/jackson/databind/ser/std/StdJdkSerializers.java @@ -1,7 +1,6 @@ package com.fasterxml.jackson.databind.ser.std; import java.io.*; -import java.lang.reflect.Type; import java.util.*; import java.util.concurrent.atomic.*; @@ -78,7 +77,7 @@ public void serialize(AtomicBoolean value, JsonGenerator jgen, SerializerProvide } @Override - public void acceptJsonFormatVisitor(JsonFormatVisitor visitor, Type typeHint) + public void acceptJsonFormatVisitor(JsonFormatVisitor visitor, JavaType typeHint) { visitor.booleanFormat(); } @@ -97,7 +96,7 @@ public void serialize(AtomicInteger value, JsonGenerator jgen, SerializerProvide } @Override - public void acceptJsonFormatVisitor(JsonFormatVisitor visitor, Type typeHint) + public void acceptJsonFormatVisitor(JsonFormatVisitor visitor, JavaType typeHint) { visitor.integerFormat(); } @@ -116,7 +115,7 @@ public void serialize(AtomicLong value, JsonGenerator jgen, SerializerProvider p } @Override - public void acceptJsonFormatVisitor(JsonFormatVisitor visitor, Type typeHint) + public void acceptJsonFormatVisitor(JsonFormatVisitor visitor, JavaType typeHint) { visitor.integerFormat(); } @@ -135,7 +134,7 @@ public void serialize(AtomicReference value, JsonGenerator jgen, SerializerPr } @Override - public void acceptJsonFormatVisitor(JsonFormatVisitor visitor, Type typeHint) + public void acceptJsonFormatVisitor(JsonFormatVisitor visitor, JavaType typeHint) { visitor.anyFormat(); } @@ -164,7 +163,7 @@ public void serialize(File value, JsonGenerator jgen, SerializerProvider provide } @Override - public void acceptJsonFormatVisitor(JsonFormatVisitor visitor, Type typeHint) + public void acceptJsonFormatVisitor(JsonFormatVisitor visitor, JavaType typeHint) { visitor.stringFormat(); } @@ -187,7 +186,7 @@ public void serialize(Class value, JsonGenerator jgen, SerializerProvider pro } @Override - public void acceptJsonFormatVisitor(JsonFormatVisitor visitor, Type typeHint) + public void acceptJsonFormatVisitor(JsonFormatVisitor visitor, JavaType typeHint) { visitor.stringFormat(); } diff --git a/src/main/java/com/fasterxml/jackson/databind/ser/std/StdKeySerializer.java b/src/main/java/com/fasterxml/jackson/databind/ser/std/StdKeySerializer.java index aa1299cc39..89d09c7fc0 100644 --- a/src/main/java/com/fasterxml/jackson/databind/ser/std/StdKeySerializer.java +++ b/src/main/java/com/fasterxml/jackson/databind/ser/std/StdKeySerializer.java @@ -1,11 +1,11 @@ package com.fasterxml.jackson.databind.ser.std; import java.io.IOException; -import java.lang.reflect.Type; import java.util.Date; import com.fasterxml.jackson.core.*; +import com.fasterxml.jackson.databind.JavaType; import com.fasterxml.jackson.databind.SerializerProvider; import com.fasterxml.jackson.databind.jsonschema.visitors.JsonFormatVisitor; import com.fasterxml.jackson.databind.ser.std.StdSerializer; @@ -34,7 +34,7 @@ public void serialize(Object value, JsonGenerator jgen, SerializerProvider provi } @Override - public void acceptJsonFormatVisitor(JsonFormatVisitor visitor, Type typeHint) + public void acceptJsonFormatVisitor(JsonFormatVisitor visitor, JavaType typeHint) { visitor.stringFormat(); } diff --git a/src/main/java/com/fasterxml/jackson/databind/ser/std/StdScalarSerializer.java b/src/main/java/com/fasterxml/jackson/databind/ser/std/StdScalarSerializer.java index 8e8e195d93..5ba8789ca2 100644 --- a/src/main/java/com/fasterxml/jackson/databind/ser/std/StdScalarSerializer.java +++ b/src/main/java/com/fasterxml/jackson/databind/ser/std/StdScalarSerializer.java @@ -1,10 +1,10 @@ package com.fasterxml.jackson.databind.ser.std; import java.io.IOException; -import java.lang.reflect.Type; import com.fasterxml.jackson.core.*; +import com.fasterxml.jackson.databind.JavaType; import com.fasterxml.jackson.databind.JsonMappingException; import com.fasterxml.jackson.databind.JsonNode; import com.fasterxml.jackson.databind.SerializerProvider; @@ -45,7 +45,7 @@ public void serializeWithType(T value, JsonGenerator jgen, SerializerProvider pr } @Override - public void acceptJsonFormatVisitor(JsonFormatVisitor visitor, Type typeHint) + public void acceptJsonFormatVisitor(JsonFormatVisitor visitor, JavaType typeHint) { visitor.anyFormat(); } diff --git a/src/main/java/com/fasterxml/jackson/databind/ser/std/StdSerializer.java b/src/main/java/com/fasterxml/jackson/databind/ser/std/StdSerializer.java index 37602a0ab3..18aae8d2ea 100644 --- a/src/main/java/com/fasterxml/jackson/databind/ser/std/StdSerializer.java +++ b/src/main/java/com/fasterxml/jackson/databind/ser/std/StdSerializer.java @@ -2,7 +2,6 @@ import java.io.IOException; import java.lang.reflect.InvocationTargetException; -import java.lang.reflect.Type; import com.fasterxml.jackson.core.*; import com.fasterxml.jackson.databind.*; @@ -81,7 +80,7 @@ public abstract void serialize(T value, JsonGenerator jgen, SerializerProvider p * overriden by custom serializers. */ // @Override - public void acceptJsonFormatVisitor(JsonFormatVisitor visitor, Type typeHint) { + public void acceptJsonFormatVisitor(JsonFormatVisitor visitor, JavaType typeHint) { visitor.anyFormat(); } diff --git a/src/main/java/com/fasterxml/jackson/databind/ser/std/StringSerializer.java b/src/main/java/com/fasterxml/jackson/databind/ser/std/StringSerializer.java index 5635039e58..d03a05660c 100644 --- a/src/main/java/com/fasterxml/jackson/databind/ser/std/StringSerializer.java +++ b/src/main/java/com/fasterxml/jackson/databind/ser/std/StringSerializer.java @@ -1,10 +1,10 @@ package com.fasterxml.jackson.databind.ser.std; import java.io.IOException; -import java.lang.reflect.Type; import com.fasterxml.jackson.core.*; +import com.fasterxml.jackson.databind.JavaType; import com.fasterxml.jackson.databind.SerializerProvider; import com.fasterxml.jackson.databind.annotation.JacksonStdImpl; import com.fasterxml.jackson.databind.jsonschema.visitors.JsonFormatVisitor; @@ -37,7 +37,7 @@ public void serialize(String value, JsonGenerator jgen, SerializerProvider provi } @Override - public void acceptJsonFormatVisitor(JsonFormatVisitor visitor, Type typeHint) + public void acceptJsonFormatVisitor(JsonFormatVisitor visitor, JavaType typeHint) { visitor.stringFormat(); } diff --git a/src/main/java/com/fasterxml/jackson/databind/ser/std/ToStringSerializer.java b/src/main/java/com/fasterxml/jackson/databind/ser/std/ToStringSerializer.java index 83feb5770b..c664a57f52 100644 --- a/src/main/java/com/fasterxml/jackson/databind/ser/std/ToStringSerializer.java +++ b/src/main/java/com/fasterxml/jackson/databind/ser/std/ToStringSerializer.java @@ -1,10 +1,10 @@ package com.fasterxml.jackson.databind.ser.std; import java.io.IOException; -import java.lang.reflect.Type; import com.fasterxml.jackson.core.*; +import com.fasterxml.jackson.databind.JavaType; import com.fasterxml.jackson.databind.JsonMappingException; import com.fasterxml.jackson.databind.JsonNode; import com.fasterxml.jackson.databind.SerializerProvider; @@ -75,7 +75,7 @@ public void serializeWithType(Object value, JsonGenerator jgen, SerializerProvid } @Override - public void acceptJsonFormatVisitor(JsonFormatVisitor visitor, Type typeHint) + public void acceptJsonFormatVisitor(JsonFormatVisitor visitor, JavaType typeHint) { visitor.stringFormat(); } diff --git a/src/main/java/com/fasterxml/jackson/databind/ser/std/TokenBufferSerializer.java b/src/main/java/com/fasterxml/jackson/databind/ser/std/TokenBufferSerializer.java index 50dee4529b..55e34f4211 100644 --- a/src/main/java/com/fasterxml/jackson/databind/ser/std/TokenBufferSerializer.java +++ b/src/main/java/com/fasterxml/jackson/databind/ser/std/TokenBufferSerializer.java @@ -1,10 +1,10 @@ package com.fasterxml.jackson.databind.ser.std; import java.io.IOException; -import java.lang.reflect.Type; import com.fasterxml.jackson.core.*; +import com.fasterxml.jackson.databind.JavaType; import com.fasterxml.jackson.databind.JsonNode; import com.fasterxml.jackson.databind.SerializerProvider; import com.fasterxml.jackson.databind.annotation.JacksonStdImpl; @@ -54,7 +54,7 @@ public final void serializeWithType(TokenBuffer value, JsonGenerator jgen, Seria } @Override - public void acceptJsonFormatVisitor(JsonFormatVisitor visitor, Type typeHint) + public void acceptJsonFormatVisitor(JsonFormatVisitor visitor, JavaType typeHint) { /* 01-Jan-2010, tatu: Not 100% sure what we should say here: * type is basically not known. This seems closest diff --git a/src/test/java/com/fasterxml/jackson/databind/module/TestSimpleModule.java b/src/test/java/com/fasterxml/jackson/databind/module/TestSimpleModule.java index 2711d56f90..b15e208970 100644 --- a/src/test/java/com/fasterxml/jackson/databind/module/TestSimpleModule.java +++ b/src/test/java/com/fasterxml/jackson/databind/module/TestSimpleModule.java @@ -1,7 +1,6 @@ package com.fasterxml.jackson.databind.module; import java.io.IOException; -import java.lang.reflect.Type; import java.util.*; @@ -53,7 +52,7 @@ public void serialize(CustomBean value, JsonGenerator jgen, SerializerProvider p } @Override - public void acceptJsonFormatVisitor(JsonFormatVisitor visitor, Type typeHint) { + public void acceptJsonFormatVisitor(JsonFormatVisitor visitor, JavaType typeHint) { visitor.anyFormat(); } } @@ -87,7 +86,7 @@ public void serialize(SimpleEnum value, JsonGenerator jgen, SerializerProvider p } @Override - public void acceptJsonFormatVisitor(JsonFormatVisitor visitor, Type typeHint) { + public void acceptJsonFormatVisitor(JsonFormatVisitor visitor, JavaType typeHint) { visitor.anyFormat(); } } From 8fababd72c60e25b6a1751f78e04700418da95f3 Mon Sep 17 00:00:00 2001 From: jackphel Date: Fri, 3 Aug 2012 00:28:25 -0400 Subject: [PATCH 09/19] working schema serialization, except for JsonSerializableSchema is ignored --- .../databind/jsonschema/types/AnySchema.java | 10 ++- .../jsonschema/types/ArraySchema.java | 36 +++++++--- .../jsonschema/types/BooleanSchema.java | 10 ++- .../jsonschema/types/HyperSchema.java | 11 ++- .../databind/jsonschema/types/NullSchema.java | 10 ++- .../jsonschema/types/NumberSchema.java | 14 +++- .../jsonschema/types/ObjectSchema.java | 11 ++- .../databind/jsonschema/types/Schema.java | 25 +++++-- .../databind/jsonschema/types/SchemaType.java | 52 ++++++-------- .../jsonschema/types/StringSchema.java | 10 ++- .../jsonschema/types/UnionTypeSchema.java | 8 +++ .../databind/ser/std/BeanSerializerBase.java | 16 ++--- .../jsonschema/TestGenerateJsonSchema.java | 71 ++++++++++--------- 13 files changed, 185 insertions(+), 99 deletions(-) diff --git a/src/main/java/com/fasterxml/jackson/databind/jsonschema/types/AnySchema.java b/src/main/java/com/fasterxml/jackson/databind/jsonschema/types/AnySchema.java index 43570e418b..e786dc8dec 100644 --- a/src/main/java/com/fasterxml/jackson/databind/jsonschema/types/AnySchema.java +++ b/src/main/java/com/fasterxml/jackson/databind/jsonschema/types/AnySchema.java @@ -21,7 +21,7 @@ of enum values uses the same algorithm as defined in "uniqueItems" private Set enums; @JsonProperty(required = true) - public final SchemaType type = SchemaType.ANY; + private final SchemaType type = SchemaType.ANY; //instance initializer block { @@ -34,6 +34,14 @@ of enum values uses the same algorithm as defined in "uniqueItems" @Override public boolean isAnySchema() { return true; } + /* (non-Javadoc) + * @see com.fasterxml.jackson.databind.jsonschema.types.Schema#getType() + */ + @Override + public SchemaType getType() { + return type; + } + public void setEnums(Set enums) { this.enums = enums; } diff --git a/src/main/java/com/fasterxml/jackson/databind/jsonschema/types/ArraySchema.java b/src/main/java/com/fasterxml/jackson/databind/jsonschema/types/ArraySchema.java index c911604c99..f8ae0a172e 100644 --- a/src/main/java/com/fasterxml/jackson/databind/jsonschema/types/ArraySchema.java +++ b/src/main/java/com/fasterxml/jackson/databind/jsonschema/types/ArraySchema.java @@ -1,6 +1,8 @@ package com.fasterxml.jackson.databind.jsonschema.types; +import com.fasterxml.jackson.annotation.JsonIgnore; import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.annotation.JsonUnwrapped; import com.fasterxml.jackson.annotation.JsonValue; /* @@ -17,13 +19,13 @@ public class ArraySchema extends ContainerTypeSchema { private ArraySchema.Items items; /**This attribute defines the maximum number of values in an array*/ @JsonProperty - private int maxItems; + private Integer maxItems; /**This attribute defines the minimum number of values in an array*/ @JsonProperty - private int minItems; + private Integer minItems; @JsonProperty(required = true) - public final SchemaType type = SchemaType.ARRAY; + private final SchemaType type = SchemaType.ARRAY; /** * This attribute indicates that all items in an array instance MUST be unique (contains no two identical values). @@ -42,7 +44,7 @@ public class ArraySchema extends ContainerTypeSchema { object. */ @JsonProperty - private Boolean uniqueItems; + private Boolean uniqueItems = null; @Override public ArraySchema asArraySchema() { return this; } @@ -66,7 +68,7 @@ public ArraySchema.Items getItems() { * {@link ArraySchema#maxItems} * @return the maxItems */ - public int getMaxItems() { + public Integer getMaxItems() { return maxItems; } @@ -75,9 +77,18 @@ public int getMaxItems() { * {@link ArraySchema#minItems} * @return the minItems */ - public int getMinItems() { + public Integer getMinItems() { return minItems; } + + /* (non-Javadoc) + * @see com.fasterxml.jackson.databind.jsonschema.types.Schema#getType() + */ + @Override + public SchemaType getType() { + return type; + } + /** * {@link ArraySchema#uniqueItems} * @return the uniqueItems @@ -110,7 +121,7 @@ public void setItemsSchema(Schema schema) { * {@link ArraySchema#maxItems} * @param maxItems the maxItems to set */ - public void setMaxItems(int maxItems) { + public void setMaxItems(Integer maxItems) { this.maxItems = maxItems; } @@ -118,7 +129,7 @@ public void setMaxItems(int maxItems) { * {@link ArraySchema#minItems} * @param minItems the minItems to set */ - public void setMinItems(int minItems) { + public void setMinItems(Integer minItems) { this.minItems = minItems; } @@ -166,7 +177,11 @@ public static class ArrayItems extends ArraySchema.Items { empty schema which allows any value for items in the instance array. */ public static abstract class Items { + + @JsonIgnore public boolean isSingleItems() { return false; } + + @JsonIgnore public boolean isArrayItems() { return false; } public SingleItems asSingleItems() { return null; } @@ -188,7 +203,7 @@ public static class NoAdditionalItems { */ public static class SchemaAdditionalItems { - @JsonProperty(required = true) + @JsonUnwrapped private Schema schema; } @@ -198,7 +213,7 @@ public static class SchemaAdditionalItems { schema. */ public static class SingleItems extends ArraySchema.Items { - @JsonProperty + @JsonUnwrapped private Schema schema; public SingleItems(Schema schema) { @@ -233,4 +248,5 @@ public void setSchema(Schema schema) { @Override public SingleItems asSingleItems() { return this; } } + } \ No newline at end of file diff --git a/src/main/java/com/fasterxml/jackson/databind/jsonschema/types/BooleanSchema.java b/src/main/java/com/fasterxml/jackson/databind/jsonschema/types/BooleanSchema.java index 2aef4ee400..e7fdbbf55f 100644 --- a/src/main/java/com/fasterxml/jackson/databind/jsonschema/types/BooleanSchema.java +++ b/src/main/java/com/fasterxml/jackson/databind/jsonschema/types/BooleanSchema.java @@ -5,11 +5,19 @@ public class BooleanSchema extends ValueTypeSchema { @JsonProperty(required = true) - public final SchemaType type = SchemaType.BOOLEAN; + private final SchemaType type = SchemaType.BOOLEAN; @Override public boolean isBooleanSchema() { return true; } + /* (non-Javadoc) + * @see com.fasterxml.jackson.databind.jsonschema.types.Schema#getType() + */ + @Override + public SchemaType getType() { + return type; + } + @Override public BooleanSchema asBooleanSchema() { return this; } } \ No newline at end of file diff --git a/src/main/java/com/fasterxml/jackson/databind/jsonschema/types/HyperSchema.java b/src/main/java/com/fasterxml/jackson/databind/jsonschema/types/HyperSchema.java index 2974908732..053eaf3d22 100644 --- a/src/main/java/com/fasterxml/jackson/databind/jsonschema/types/HyperSchema.java +++ b/src/main/java/com/fasterxml/jackson/databind/jsonschema/types/HyperSchema.java @@ -1,4 +1,4 @@ -package com.fasterxml.jackson.databind.jsonschema.types; + package com.fasterxml.jackson.databind.jsonschema.types; import com.fasterxml.jackson.annotation.JsonProperty; @@ -330,4 +330,13 @@ structure of the submitted request (for a GET request, this schema private Schema schema; } + + /* (non-Javadoc) + * @see com.fasterxml.jackson.databind.jsonschema.types.Schema#getType() + */ + @Override + public SchemaType getType() { + // TODO Auto-generated method stub + return null; + } } \ No newline at end of file diff --git a/src/main/java/com/fasterxml/jackson/databind/jsonschema/types/NullSchema.java b/src/main/java/com/fasterxml/jackson/databind/jsonschema/types/NullSchema.java index 96edc3c8dd..dcf772ccd3 100644 --- a/src/main/java/com/fasterxml/jackson/databind/jsonschema/types/NullSchema.java +++ b/src/main/java/com/fasterxml/jackson/databind/jsonschema/types/NullSchema.java @@ -8,7 +8,15 @@ public class NullSchema extends SimpleTypeSchema { @JsonProperty(required = true) - public final SchemaType type = SchemaType.NULL; + private final SchemaType type = SchemaType.NULL; + + /* (non-Javadoc) + * @see com.fasterxml.jackson.databind.jsonschema.types.Schema#getType() + */ + @Override + public SchemaType getType() { + return type; + } @Override public boolean isNullSchema() { return true; } diff --git a/src/main/java/com/fasterxml/jackson/databind/jsonschema/types/NumberSchema.java b/src/main/java/com/fasterxml/jackson/databind/jsonschema/types/NumberSchema.java index 0c31542510..0a27f43506 100644 --- a/src/main/java/com/fasterxml/jackson/databind/jsonschema/types/NumberSchema.java +++ b/src/main/java/com/fasterxml/jackson/databind/jsonschema/types/NumberSchema.java @@ -22,14 +22,14 @@ public class NumberSchema extends ValueTypeSchema { /**This attribute defines the maximum value of the instance property*/ @JsonProperty - private Double maximum; + private Double maximum = null; /**This attribute defines the minimum value of the instance property*/ @JsonProperty - private Double minimum; + private Double minimum = null; @JsonProperty(required = true) - public final SchemaType type = SchemaType.NUMBER; + private final SchemaType type = SchemaType.NUMBER; @Override public NumberSchema asNumberSchema() { return this; } @@ -63,6 +63,14 @@ public Double getMinimum() { return minimum; } + /* (non-Javadoc) + * @see com.fasterxml.jackson.databind.jsonschema.types.Schema#getType() + */ + @Override + public SchemaType getType() { + return type; + } + @Override public boolean isNumberSchema() { return true; } /** diff --git a/src/main/java/com/fasterxml/jackson/databind/jsonschema/types/ObjectSchema.java b/src/main/java/com/fasterxml/jackson/databind/jsonschema/types/ObjectSchema.java index 1eb323b9f3..6e75650e42 100644 --- a/src/main/java/com/fasterxml/jackson/databind/jsonschema/types/ObjectSchema.java +++ b/src/main/java/com/fasterxml/jackson/databind/jsonschema/types/ObjectSchema.java @@ -57,7 +57,7 @@ public class ObjectSchema extends ContainerTypeSchema { private Map properties; @JsonProperty(required = true) - public final SchemaType type = SchemaType.OBJECT; + private final SchemaType type = SchemaType.OBJECT; // instance initializer block { @@ -116,13 +116,20 @@ public Map getProperties() { return properties; } + /* (non-Javadoc) + * @see com.fasterxml.jackson.databind.jsonschema.types.Schema#getType() + */ + @Override + public SchemaType getType() { + return type; + } + @Override public boolean isObjectSchema() { return true; } public void putOptionalProperty(String name, Schema schema) { - schema.setRequired(false); properties.put(name, schema); } diff --git a/src/main/java/com/fasterxml/jackson/databind/jsonschema/types/Schema.java b/src/main/java/com/fasterxml/jackson/databind/jsonschema/types/Schema.java index db50ec4ae9..12ceded5e2 100644 --- a/src/main/java/com/fasterxml/jackson/databind/jsonschema/types/Schema.java +++ b/src/main/java/com/fasterxml/jackson/databind/jsonschema/types/Schema.java @@ -2,8 +2,11 @@ import com.fasterxml.jackson.annotation.JsonGetter; import com.fasterxml.jackson.annotation.JsonIgnore; +import com.fasterxml.jackson.annotation.JsonInclude; +import com.fasterxml.jackson.annotation.JsonInclude.Include; import com.fasterxml.jackson.annotation.JsonProperty; import com.fasterxml.jackson.annotation.JsonSetter; +import com.fasterxml.jackson.databind.annotation.JsonSerialize; /** * Json Schema @@ -64,6 +67,7 @@ * * @author jphelan */ +@JsonInclude(Include.NON_EMPTY) public abstract class Schema { /** @@ -138,10 +142,7 @@ public abstract class Schema { * undefined. This is false by default, making the instance optional. */ @JsonProperty - private Boolean required = false;// default = false; - - @JsonProperty(required = true) - public final SchemaType type = null; + private Boolean required = null; public AnySchema asAnySchema() { return null; @@ -246,54 +247,64 @@ public Boolean getRequired() { return required; } - public SchemaType getType() { - return this.type; - } + public abstract SchemaType getType(); + @JsonIgnore public boolean isAnySchema() { return false; } + @JsonIgnore public boolean isArraySchema() { return false; } + @JsonIgnore public boolean isBooleanSchema() { return false; } + @JsonIgnore public boolean isContainerTypeSchema() { return false; } + @JsonIgnore public boolean isIntegerSchema() { return false; } + @JsonIgnore public boolean isNullSchema() { return false; } + @JsonIgnore public boolean isNumberSchema() { return false; } + @JsonIgnore public boolean isObjectSchema() { return false; } + @JsonIgnore public boolean isSimpleTypeSchema() { return false; } + @JsonIgnore public boolean isStringSchema() { return false; } + @JsonIgnore public boolean isUnionTypeSchema() { return false; } + @JsonIgnore public boolean isValueTypeSchema() { return false; } diff --git a/src/main/java/com/fasterxml/jackson/databind/jsonschema/types/SchemaType.java b/src/main/java/com/fasterxml/jackson/databind/jsonschema/types/SchemaType.java index 6d310499ba..481c726f5b 100644 --- a/src/main/java/com/fasterxml/jackson/databind/jsonschema/types/SchemaType.java +++ b/src/main/java/com/fasterxml/jackson/databind/jsonschema/types/SchemaType.java @@ -1,37 +1,27 @@ package com.fasterxml.jackson.databind.jsonschema.types; +import com.fasterxml.jackson.annotation.JsonCreator; +import com.fasterxml.jackson.annotation.JsonValue; + public enum SchemaType { - STRING { - @Override - public String toString() { return "string"; } - }, - NUMBER { - @Override - public String toString() { return "number"; } - }, - INTEGER { - @Override - public String toString() { return "integer"; } - }, - BOOLEAN { - @Override - public String toString() { return "boolean"; } - }, - OBJECT { - @Override - public String toString() { return "object"; } - }, - ARRAY { - @Override - public String toString() { return "array"; } - }, - NULL { - @Override - public String toString() { return "null"; } - }, - ANY { - @Override - public String toString() { return "any"; } + + STRING, + NUMBER, + INTEGER, + BOOLEAN, + OBJECT, + ARRAY, + NULL, + ANY; + + + @JsonValue + public String value() { + return this.name().toLowerCase(); } + @JsonCreator + public static SchemaType forValue(String s) { + return valueOf(s.toUpperCase()); + } } \ No newline at end of file diff --git a/src/main/java/com/fasterxml/jackson/databind/jsonschema/types/StringSchema.java b/src/main/java/com/fasterxml/jackson/databind/jsonschema/types/StringSchema.java index 3b872176ee..87bee09a49 100644 --- a/src/main/java/com/fasterxml/jackson/databind/jsonschema/types/StringSchema.java +++ b/src/main/java/com/fasterxml/jackson/databind/jsonschema/types/StringSchema.java @@ -20,7 +20,7 @@ public class StringSchema extends ValueTypeSchema { private String pattern; @JsonProperty(required = true) - public final SchemaType type = SchemaType.STRING; + private final SchemaType type = SchemaType.STRING; @Override public StringSchema asStringSchema() { @@ -53,6 +53,14 @@ public Integer getMinLength() { public String getPattern() { return pattern; } + + /* (non-Javadoc) + * @see com.fasterxml.jackson.databind.jsonschema.types.Schema#getType() + */ + @Override + public SchemaType getType() { + return type; + } @Override public boolean isStringSchema() { diff --git a/src/main/java/com/fasterxml/jackson/databind/jsonschema/types/UnionTypeSchema.java b/src/main/java/com/fasterxml/jackson/databind/jsonschema/types/UnionTypeSchema.java index 6a9c7a736e..4fb78ae55c 100644 --- a/src/main/java/com/fasterxml/jackson/databind/jsonschema/types/UnionTypeSchema.java +++ b/src/main/java/com/fasterxml/jackson/databind/jsonschema/types/UnionTypeSchema.java @@ -21,6 +21,14 @@ public ValueTypeSchema[] getElements() { return elements; } + /* (non-Javadoc) + * @see com.fasterxml.jackson.databind.jsonschema.types.Schema#getType() + */ + @Override + public SchemaType getType() { + return null; + } + @Override public boolean isUnionTypeSchema() { return true; diff --git a/src/main/java/com/fasterxml/jackson/databind/ser/std/BeanSerializerBase.java b/src/main/java/com/fasterxml/jackson/databind/ser/std/BeanSerializerBase.java index db9ba34aeb..debded7843 100644 --- a/src/main/java/com/fasterxml/jackson/databind/ser/std/BeanSerializerBase.java +++ b/src/main/java/com/fasterxml/jackson/databind/ser/std/BeanSerializerBase.java @@ -631,14 +631,14 @@ public void acceptJsonFormatVisitor(JsonFormatVisitor visitor, JavaType typeHint JsonObjectFormatVisitor objectVisitor = visitor.objectFormat(typeHint); // [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); -// if (ann != null) { -// String id = ann.id(); -// if (id != null && id.length() > 0) { -// //o.put("id", id); what is this? -// //objectVisitor.expect?? -// } -// } + JsonSerializableSchema ann = _handledType.getAnnotation(JsonSerializableSchema.class); + if (ann != null) { + String id = ann.id(); + if (id != null && id.length() > 0) { + //o.put("id", id); what is this? + //objectVisitor.expect?? + } + } BeanPropertyFilter filter; if (_propertyFilterId != null) { diff --git a/src/test/java/com/fasterxml/jackson/databind/jsonschema/TestGenerateJsonSchema.java b/src/test/java/com/fasterxml/jackson/databind/jsonschema/TestGenerateJsonSchema.java index 234f88b92b..e103fc6f70 100644 --- a/src/test/java/com/fasterxml/jackson/databind/jsonschema/TestGenerateJsonSchema.java +++ b/src/test/java/com/fasterxml/jackson/databind/jsonschema/TestGenerateJsonSchema.java @@ -1,16 +1,15 @@ package com.fasterxml.jackson.databind.jsonschema; import java.util.Collection; +import java.util.HashMap; import java.util.Map; import com.fasterxml.jackson.annotation.JsonFilter; import com.fasterxml.jackson.annotation.JsonProperty; -import com.fasterxml.jackson.databind.JsonNode; import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.databind.jsonschema.types.ObjectSchema; import com.fasterxml.jackson.databind.jsonschema.types.Schema; import com.fasterxml.jackson.databind.jsonschema.types.ArraySchema.Items; -import com.fasterxml.jackson.databind.node.ObjectNode; import com.fasterxml.jackson.databind.ser.DefaultSerializerProvider; import com.fasterxml.jackson.databind.ser.FilterProvider; import com.fasterxml.jackson.databind.ser.impl.SimpleBeanPropertyFilter; @@ -131,17 +130,17 @@ public void testGeneratingJsonSchema() Schema prop1 = properties.get("property1"); assertNotNull(prop1); assertTrue(prop1.isIntegerSchema()); - assertFalse(prop1.getRequired()); + assertNull(prop1.getRequired()); Schema prop2 = properties.get("property2"); assertNotNull(prop2); assertTrue(prop2.isStringSchema()); - assertFalse(prop2.getRequired()); + assertNull(prop2.getRequired()); Schema prop3 = properties.get("property3"); assertNotNull(prop3); assertTrue(prop3.isArraySchema()); - assertFalse(prop3.getRequired()); + assertNull(prop3.getRequired()); Items items = prop3.asArraySchema().getItems(); assertTrue(items.isSingleItems()); Schema itemType = items.asSingleItems().getSchema(); @@ -151,7 +150,7 @@ public void testGeneratingJsonSchema() Schema prop4 = properties.get("property4"); assertNotNull(prop4); assertTrue(prop4.isArraySchema()); - assertFalse(prop4.getRequired()); + assertNull(prop4.getRequired()); items = prop4.asArraySchema().getItems(); assertTrue(items.isSingleItems()); itemType = items.asSingleItems().getSchema(); @@ -161,17 +160,7 @@ public void testGeneratingJsonSchema() Schema prop5 = properties.get("property5"); assertNotNull(prop5); assertTrue(prop5.getRequired()); - - - -// assertEquals("array", property3Schema.get("type").asText()); -// assertEquals(false, property3Schema.path("required").booleanValue()); -// assertEquals("string", property3Schema.get("items").get("type").asText()); -// JsonNode property4Schema = propertiesSchema.get("property4"); -// assertNotNull(property4Schema); -// assertEquals("array", property4Schema.get("type").asText()); -// assertEquals(false, property4Schema.path("required").booleanValue()); -// assertEquals("number", property4Schema.get("items").get("type").asText()); + } @JsonFilter("filteredBean") @@ -197,9 +186,16 @@ public void testGeneratingJsonSchemaWithFilters() throws Exception { ObjectMapper mapper = new ObjectMapper(); mapper.setFilters(secretFilterProvider); Schema schema = mapper.generateJsonSchema(FilteredBean.class); -// JsonNode node = schema.getSchemaNode().get("properties"); -// assertTrue(node.has("obvious")); -// assertFalse(node.has("secret")); + assertNotNull(schema); + assertTrue(schema.isObjectSchema()); + ObjectSchema object = schema.asObjectSchema(); + assertNotNull(object); + Map properties = object.getProperties(); + assertNotNull(properties); + Schema obvious = properties.get("obvious"); + assertNotNull(obvious); + assertTrue(obvious.isStringSchema()); + assertNull(properties.get("secret")); } /** @@ -210,13 +206,13 @@ public void testSchemaSerialization() throws Exception { Schema jsonSchema = MAPPER.generateJsonSchema(SimpleBean.class); - Map result = writeAndMap(MAPPER, jsonSchema); - assertNotNull(result); - // no need to check out full structure, just basics... - assertEquals("object", result.get("type")); - // only add 'required' if it is true... - assertNull(result.get("required")); - assertNotNull(result.get("properties")); + Map result = writeAndMap(MAPPER, jsonSchema); + assertNotNull(result); + // no need to check out full structure, just basics... + assertEquals("object", result.get("type")); + // only add 'required' if it is true... + assertNull(result.get("required")); + assertNotNull(result.get("properties")); } public void testInvalidCall() @@ -237,18 +233,27 @@ public void testInvalidCall() public void testThatObjectsHaveNoItems() throws Exception { Schema jsonSchema = MAPPER.generateJsonSchema(TrivialBean.class); - String json = jsonSchema.toString().replaceAll("\"", "'"); + Map result = writeAndMap(MAPPER, jsonSchema); // can we count on ordering being stable? I think this is true with current ObjectNode impl // as perh [JACKSON-563]; 'required' is only included if true - assertEquals("{'type':'object','properties':{'name':{'type':'string'}}}", - json); + assertFalse(result.containsKey("items")); + } public void testSchemaId() throws Exception { Schema jsonSchema = MAPPER.generateJsonSchema(BeanWithId.class); - String json = jsonSchema.toString().replaceAll("\"", "'"); - assertEquals("{'type':'object','id':'myType','properties':{'value':{'type':'string'}}}", - json); + Map result = writeAndMap(MAPPER, jsonSchema); + + assertEquals(new HashMap() {{ + put("type", "object"); + put("id", "myType"); + put("properties", + new HashMap(){{ put("value", + new HashMap() {{ put("type", "string");}} + );}} + );}}, result); + //assertEquals("{'type':'object','id':'myType','properties':{'value':{'type':'string'}}}", + // json); } } From ed98c9e3c47b12f6f457f4af6fd2546e53f68284 Mon Sep 17 00:00:00 2001 From: jackphel Date: Fri, 3 Aug 2012 21:41:54 -0400 Subject: [PATCH 10/19] jsonschema serialization and deep equals implemented. --- .../jackson/databind/ObjectMapper.java | 11 +- ...Aware.java => JsonFormatVisitorAware.java} | 2 +- .../databind/jsonschema/JsonSchema.java | 89 --- .../jsonschema/JsonSerializableSchema.java | 62 -- .../factories/AnySchemaFactory.java | 4 +- .../factories/ArraySchemaFactory.java | 14 +- .../factories/NullSchemaFactory.java | 4 +- .../factories/ObjectSchemaFactory.java | 43 +- .../jsonschema/factories/SchemaFactory.java | 6 +- .../factories/SchemaFactoryDelegate.java | 4 +- .../factories/ValueTypeSchemaFactory.java | 4 +- .../databind/jsonschema/types/AnySchema.java | 31 +- .../jsonschema/types/ArraySchema.java | 204 +++++- .../jsonschema/types/BooleanSchema.java | 17 +- .../jsonschema/types/ContainerTypeSchema.java | 45 +- .../jsonschema/types/HyperSchema.java | 63 +- .../jsonschema/types/IntegerSchema.java | 44 +- .../databind/jsonschema/types/JsonSchema.java | 613 ++++++++++++++++++ .../jsonschema/types/JsonValueFormat.java | 31 +- .../databind/jsonschema/types/NullSchema.java | 22 +- .../jsonschema/types/NumberSchema.java | 33 +- .../jsonschema/types/ObjectSchema.java | 200 +++++- .../databind/jsonschema/types/Schema.java | 395 ----------- .../jsonschema/types/SimpleTypeSchema.java | 33 +- .../jsonschema/types/StringSchema.java | 36 +- .../jsonschema/types/UnionTypeSchema.java | 30 +- .../jsonschema/types/ValueTypeSchema.java | 27 +- .../visitors/JsonArrayFormatVisitor.java | 4 +- .../visitors/JsonObjectFormatVisitor.java | 6 +- .../ser/DefaultSerializerProvider.java | 6 +- .../ser/impl/SimpleBeanPropertyFilter.java | 4 - .../databind/ser/std/BeanSerializerBase.java | 15 +- .../databind/ser/std/EnumMapSerializer.java | 7 +- .../databind/ser/std/JsonValueSerializer.java | 9 +- .../ser/std/ObjectArraySerializer.java | 5 - .../ser/std/SerializableSerializer.java | 60 +- .../ser/std/StaticListSerializerBase.java | 2 +- .../databind/ser/std/StdSerializer.java | 8 +- .../jsonschema/TestGenerateJsonSchema.java | 53 +- .../jsonschema/TestReadJsonSchema.java | 11 +- 40 files changed, 1373 insertions(+), 884 deletions(-) rename src/main/java/com/fasterxml/jackson/databind/jsonschema/{SchemaAware.java => JsonFormatVisitorAware.java} (93%) delete mode 100644 src/main/java/com/fasterxml/jackson/databind/jsonschema/JsonSchema.java delete mode 100644 src/main/java/com/fasterxml/jackson/databind/jsonschema/JsonSerializableSchema.java create mode 100644 src/main/java/com/fasterxml/jackson/databind/jsonschema/types/JsonSchema.java delete mode 100644 src/main/java/com/fasterxml/jackson/databind/jsonschema/types/Schema.java diff --git a/src/main/java/com/fasterxml/jackson/databind/ObjectMapper.java b/src/main/java/com/fasterxml/jackson/databind/ObjectMapper.java index e14468b189..819a5b6f12 100644 --- a/src/main/java/com/fasterxml/jackson/databind/ObjectMapper.java +++ b/src/main/java/com/fasterxml/jackson/databind/ObjectMapper.java @@ -26,9 +26,8 @@ import com.fasterxml.jackson.databind.introspect.ClassIntrospector; import com.fasterxml.jackson.databind.introspect.JacksonAnnotationIntrospector; import com.fasterxml.jackson.databind.introspect.VisibilityChecker; -import com.fasterxml.jackson.databind.jsonschema.JsonSchema; import com.fasterxml.jackson.databind.jsonschema.factories.SchemaFactory; -import com.fasterxml.jackson.databind.jsonschema.types.Schema; +import com.fasterxml.jackson.databind.jsonschema.types.JsonSchema; import com.fasterxml.jackson.databind.jsontype.*; import com.fasterxml.jackson.databind.jsontype.impl.StdSubtypeResolver; import com.fasterxml.jackson.databind.jsontype.impl.StdTypeResolverBuilder; @@ -2150,7 +2149,7 @@ public ObjectWriter writer(FilterProvider filterProvider) { * pass specific schema object to {@link JsonGenerator} used for * writing content. * - * @param schema Schema to pass to generator + * @param schema JsonSchema to pass to generator */ public ObjectWriter writer(FormatSchema schema) { return new ObjectWriter(this, getSerializationConfig(), schema); @@ -2255,7 +2254,7 @@ public ObjectReader reader(JsonNodeFactory f) * pass specific schema object to {@link JsonParser} used for * reading content. * - * @param schema Schema to pass to parser + * @param schema JsonSchema to pass to parser */ public ObjectReader reader(FormatSchema schema) { return new ObjectReader(this, getDeserializationConfig(), null, null, @@ -2388,7 +2387,7 @@ protected Object _convert(Object fromValue, JavaType toValueType) /* /********************************************************** - /* Extended Public API: JSON Schema generation + /* Extended Public API: JSON JsonSchema generation /********************************************************** */ @@ -2399,7 +2398,7 @@ protected Object _convert(Object fromValue, JavaType toValueType) * @param t The class to generate schema for * @return Constructed JSON schema. */ - public Schema generateJsonSchema(Class t) throws JsonMappingException { + public JsonSchema generateJsonSchema(Class t) throws JsonMappingException { DefaultSerializerProvider provider = _serializerProvider(getSerializationConfig()); SchemaFactory visitor = new SchemaFactory(provider); provider.acceptJsonFormatVisitor(t, visitor); diff --git a/src/main/java/com/fasterxml/jackson/databind/jsonschema/SchemaAware.java b/src/main/java/com/fasterxml/jackson/databind/jsonschema/JsonFormatVisitorAware.java similarity index 93% rename from src/main/java/com/fasterxml/jackson/databind/jsonschema/SchemaAware.java rename to src/main/java/com/fasterxml/jackson/databind/jsonschema/JsonFormatVisitorAware.java index e613086e4f..4380820656 100644 --- a/src/main/java/com/fasterxml/jackson/databind/jsonschema/SchemaAware.java +++ b/src/main/java/com/fasterxml/jackson/databind/jsonschema/JsonFormatVisitorAware.java @@ -7,7 +7,7 @@ /** * Marker interface for schema-aware serializers. */ -public interface SchemaAware +public interface JsonFormatVisitorAware { /** * Get the representation of the schema to which this serializer will conform. diff --git a/src/main/java/com/fasterxml/jackson/databind/jsonschema/JsonSchema.java b/src/main/java/com/fasterxml/jackson/databind/jsonschema/JsonSchema.java deleted file mode 100644 index 781810dbf6..0000000000 --- a/src/main/java/com/fasterxml/jackson/databind/jsonschema/JsonSchema.java +++ /dev/null @@ -1,89 +0,0 @@ -package com.fasterxml.jackson.databind.jsonschema; - -import java.math.BigDecimal; -import java.util.Map; - -import com.fasterxml.jackson.annotation.JsonCreator; -import com.fasterxml.jackson.annotation.JsonValue; - -import com.fasterxml.jackson.databind.JsonNode; -import com.fasterxml.jackson.databind.node.JsonNodeFactory; -import com.fasterxml.jackson.databind.node.ObjectNode; - -/** - * Container for a logical JSON Schema instance. - * Internally schema data is stored as a JSON Tree - * (instance of {@link JsonNode} is the root - * of schema document) - * - * @author Ryan Heaton - * @see JSON Schema - */ -public class JsonSchema -{ - private final ObjectNode schema; - - /** - * Main constructor for schema instances. - *

- * This is the creator constructor used by Jackson itself when - * deserializing instances. It is so-called delegating creator, - * meaning that its argument will be bound by Jackson before - * constructor gets called. - */ - @JsonCreator - public JsonSchema(ObjectNode schema) - { - this.schema = schema; - } - - /** - * Method for accessing root JSON object of the contained schema. - *

- * Note: this method is specified with {@link JsonValue} annotation - * to represent serialization to use; same as if explicitly - * serializing returned object. - * - * @return Root node of the schema tree - */ - @JsonValue - public ObjectNode getSchemaNode() - { - return schema; - } - - @Override - public String toString() - { - return this.schema.toString(); - } - - @Override - public boolean equals(Object o) - { - if (o == this) return true; - if (o == null) return false; - if (!(o instanceof JsonSchema)) return false; - - JsonSchema other = (JsonSchema) o; - if (schema == null) { - return other.schema == null; - } - return schema.equals(other.schema); - } - - /** - * Get the default schema node. - * - * @return The default schema node. - */ - public static JsonNode getDefaultSchemaNode() - { - ObjectNode objectNode = JsonNodeFactory.instance.objectNode(); - objectNode.put("type", "any"); - // "required" is false by default, no need to include - //objectNode.put("required", false); - return objectNode; - } - -} diff --git a/src/main/java/com/fasterxml/jackson/databind/jsonschema/JsonSerializableSchema.java b/src/main/java/com/fasterxml/jackson/databind/jsonschema/JsonSerializableSchema.java deleted file mode 100644 index a2935693b5..0000000000 --- a/src/main/java/com/fasterxml/jackson/databind/jsonschema/JsonSerializableSchema.java +++ /dev/null @@ -1,62 +0,0 @@ -package com.fasterxml.jackson.databind.jsonschema; - -import java.lang.annotation.RetentionPolicy; -import java.lang.annotation.Retention; -import java.lang.annotation.ElementType; -import java.lang.annotation.Target; - -import com.fasterxml.jackson.annotation.JacksonAnnotation; - -/** - * Annotation that can be used to define JSON Schema definition for - * the annotated class. - *

- * Note that annotation is often not needed: for example, regular - * Jackson beans that Jackson can introspect can be used without - * annotations, to produce JSON schema definition. - * - * @author Ryan Heaton - * @author Tatu Saloranta - */ -@Target(ElementType.TYPE) -@Retention(RetentionPolicy.RUNTIME) -@JacksonAnnotation -public @interface JsonSerializableSchema -{ - /** - * Marker value used to indicate that property has "no value"; - * needed because annotations can not have null as default - * value. - */ - public final static String NO_VALUE = "##irrelevant"; - - /** - * Property that can be used to indicate id of the type when - * generating JSON Schema; empty String indicates that no id - * is defined. - */ - public String id() default ""; - - /** - * The schema type for this JsonSerializable instance. - * Possible values: "string", "number", "boolean", "object", "array", "null", "any" - * - * @return The schema type for this JsonSerializable instance. - */ - public String schemaType() default "any"; - - /** - * If the schema type is "object", JSON definition of properties of the object as - * a String. - * - * @return The node representing the schema properties, or "##irrelevant" if irrelevant. - */ - public String schemaObjectPropertiesDefinition() default NO_VALUE; - - /** - * If the schema type if "array", JSON definition of the schema for item types contained. - * - * @return The schema for the items in the array, or "##irrelevant" if irrelevant. - */ - public String schemaItemDefinition() default NO_VALUE; -} diff --git a/src/main/java/com/fasterxml/jackson/databind/jsonschema/factories/AnySchemaFactory.java b/src/main/java/com/fasterxml/jackson/databind/jsonschema/factories/AnySchemaFactory.java index 4758a05815..f948d90610 100644 --- a/src/main/java/com/fasterxml/jackson/databind/jsonschema/factories/AnySchemaFactory.java +++ b/src/main/java/com/fasterxml/jackson/databind/jsonschema/factories/AnySchemaFactory.java @@ -1,7 +1,7 @@ package com.fasterxml.jackson.databind.jsonschema.factories; import com.fasterxml.jackson.databind.jsonschema.types.AnySchema; -import com.fasterxml.jackson.databind.jsonschema.types.Schema; +import com.fasterxml.jackson.databind.jsonschema.types.JsonSchema; import com.fasterxml.jackson.databind.jsonschema.visitors.JsonAnyFormatVisitor; public class AnySchemaFactory extends SchemaFactory implements @@ -16,7 +16,7 @@ public AnySchemaFactory(SchemaFactory parent) { anySchema = new AnySchema(); } - public Schema getSchema() { + public JsonSchema getSchema() { return anySchema; } diff --git a/src/main/java/com/fasterxml/jackson/databind/jsonschema/factories/ArraySchemaFactory.java b/src/main/java/com/fasterxml/jackson/databind/jsonschema/factories/ArraySchemaFactory.java index 340f6f9ced..afd02fa5c0 100644 --- a/src/main/java/com/fasterxml/jackson/databind/jsonschema/factories/ArraySchemaFactory.java +++ b/src/main/java/com/fasterxml/jackson/databind/jsonschema/factories/ArraySchemaFactory.java @@ -4,9 +4,9 @@ import com.fasterxml.jackson.databind.JavaType; import com.fasterxml.jackson.databind.JsonMappingException; import com.fasterxml.jackson.databind.JsonSerializer; -import com.fasterxml.jackson.databind.jsonschema.SchemaAware; +import com.fasterxml.jackson.databind.jsonschema.JsonFormatVisitorAware; import com.fasterxml.jackson.databind.jsonschema.types.ArraySchema; -import com.fasterxml.jackson.databind.jsonschema.types.Schema; +import com.fasterxml.jackson.databind.jsonschema.types.JsonSchema; import com.fasterxml.jackson.databind.jsonschema.types.SchemaType; import com.fasterxml.jackson.databind.jsonschema.visitors.JsonArrayFormatVisitor; @@ -33,9 +33,9 @@ public void itemsFormat(JavaType contentType) { JsonSerializer ser; try { ser = getProvider().findValueSerializer(contentType, _property); - if (ser instanceof SchemaAware) { + if (ser instanceof JsonFormatVisitorAware) { SchemaFactory visitor = new SchemaFactory(provider); - ((SchemaAware) ser).acceptJsonFormatVisitor(visitor, contentType); + ((JsonFormatVisitorAware) ser).acceptJsonFormatVisitor(visitor, contentType); arraySchema.setItemsSchema(visitor.finalSchema()); } } catch (JsonMappingException e) { @@ -44,13 +44,13 @@ public void itemsFormat(JavaType contentType) { } } - public void itemsFormat(SchemaAware toVisit) {} + public void itemsFormat(JsonFormatVisitorAware toVisit) {} public void itemsFormat(SchemaType format) { - arraySchema.setItemsSchema(Schema.minimalForFormat(format)); + arraySchema.setItemsSchema(JsonSchema.minimalForFormat(format)); } - public Schema getSchema() { + public JsonSchema getSchema() { return arraySchema; } diff --git a/src/main/java/com/fasterxml/jackson/databind/jsonschema/factories/NullSchemaFactory.java b/src/main/java/com/fasterxml/jackson/databind/jsonschema/factories/NullSchemaFactory.java index 70ffc5b834..c71d2cadd3 100644 --- a/src/main/java/com/fasterxml/jackson/databind/jsonschema/factories/NullSchemaFactory.java +++ b/src/main/java/com/fasterxml/jackson/databind/jsonschema/factories/NullSchemaFactory.java @@ -1,7 +1,7 @@ package com.fasterxml.jackson.databind.jsonschema.factories; import com.fasterxml.jackson.databind.jsonschema.types.NullSchema; -import com.fasterxml.jackson.databind.jsonschema.types.Schema; +import com.fasterxml.jackson.databind.jsonschema.types.JsonSchema; import com.fasterxml.jackson.databind.jsonschema.visitors.JsonNullFormatVisitor; public class NullSchemaFactory extends SchemaFactory implements @@ -16,7 +16,7 @@ public NullSchemaFactory(SchemaFactory parent) { nullSchema = new NullSchema(); } - public Schema getSchema() { + public JsonSchema getSchema() { return nullSchema; } diff --git a/src/main/java/com/fasterxml/jackson/databind/jsonschema/factories/ObjectSchemaFactory.java b/src/main/java/com/fasterxml/jackson/databind/jsonschema/factories/ObjectSchemaFactory.java index 59f76e1ef1..78206b8fe1 100644 --- a/src/main/java/com/fasterxml/jackson/databind/jsonschema/factories/ObjectSchemaFactory.java +++ b/src/main/java/com/fasterxml/jackson/databind/jsonschema/factories/ObjectSchemaFactory.java @@ -4,9 +4,9 @@ import com.fasterxml.jackson.databind.JavaType; import com.fasterxml.jackson.databind.JsonMappingException; import com.fasterxml.jackson.databind.JsonSerializer; -import com.fasterxml.jackson.databind.jsonschema.SchemaAware; +import com.fasterxml.jackson.databind.jsonschema.JsonFormatVisitorAware; import com.fasterxml.jackson.databind.jsonschema.types.ObjectSchema; -import com.fasterxml.jackson.databind.jsonschema.types.Schema; +import com.fasterxml.jackson.databind.jsonschema.types.JsonSchema; import com.fasterxml.jackson.databind.jsonschema.types.SchemaType; import com.fasterxml.jackson.databind.jsonschema.visitors.JsonObjectFormatVisitor; import com.fasterxml.jackson.databind.ser.BeanPropertyWriter; @@ -22,17 +22,14 @@ public ObjectSchemaFactory(SchemaFactory parent) { objectSchema = new ObjectSchema(); } - public Schema getSchema() { - // TODO Auto-generated method stub + public JsonSchema getSchema() { return objectSchema; } - private JsonSerializer getSer(BeanPropertyWriter writer, Class serType) { + private JsonSerializer getSer(BeanPropertyWriter writer) { JsonSerializer ser = writer.getSerializer(); - if (ser == null) { // nope - if (serType == null) { - serType = writer.getPropertyType(); - } + if (ser == null) { + Class serType = writer.getPropertyType(); try { return getProvider().findValueSerializer(serType, writer); } catch (JsonMappingException e) { @@ -42,28 +39,18 @@ private JsonSerializer getSer(BeanPropertyWriter writer, Class serTyp return ser; } - private Class writerType(BeanPropertyWriter writer) { - - //TODO:Will these ever return different types? - - //JavaType propType = writer.getSerializationType(); - //Type hint = (propType == null) ? writer.getGenericPropertyType() : propType.getRawClass(); - return writer.getPropertyType(); - } - - protected Schema propertySchema(BeanPropertyWriter writer) { + protected JsonSchema propertySchema(BeanPropertyWriter writer) { SchemaFactory visitor = new SchemaFactory(provider); - Class serType = writerType(writer); - JsonSerializer ser = getSer(writer, serType); - if (ser != null && ser instanceof SchemaAware) { - ((SchemaAware)ser).acceptJsonFormatVisitor(visitor, writer.getType()); + JsonSerializer ser = getSer(writer); + if (ser != null && ser instanceof JsonFormatVisitorAware) { + ((JsonFormatVisitorAware)ser).acceptJsonFormatVisitor(visitor, writer.getType()); } else { visitor.anyFormat(); } return visitor.finalSchema(); } - protected Schema propertySchema(SchemaAware handler, JavaType propertyTypeHint) { + protected JsonSchema propertySchema(JsonFormatVisitorAware handler, JavaType propertyTypeHint) { SchemaFactory visitor = new SchemaFactory(provider); handler.acceptJsonFormatVisitor(visitor, propertyTypeHint); return visitor.finalSchema(); @@ -77,20 +64,20 @@ public void optionalProperty(BeanPropertyWriter writer) { objectSchema.putOptionalProperty(writer.getName(), propertySchema(writer)); } - public void property(String name, SchemaAware handler, JavaType propertyTypeHint) { + public void property(String name, JsonFormatVisitorAware handler, JavaType propertyTypeHint) { objectSchema.putProperty(name, propertySchema(handler, propertyTypeHint)); } - public void optionalProperty(String name, SchemaAware handler, JavaType propertyTypeHint) { + public void optionalProperty(String name, JsonFormatVisitorAware handler, JavaType propertyTypeHint) { objectSchema.putOptionalProperty(name, propertySchema(handler, propertyTypeHint)); } public void property(String name) { - objectSchema.putProperty(name, Schema.minimalForFormat(SchemaType.ANY)); + objectSchema.putProperty(name, JsonSchema.minimalForFormat(SchemaType.ANY)); } public void optionalProperty(String name) { - objectSchema.putOptionalProperty(name, Schema.minimalForFormat(SchemaType.ANY)); + objectSchema.putOptionalProperty(name, JsonSchema.minimalForFormat(SchemaType.ANY)); } } diff --git a/src/main/java/com/fasterxml/jackson/databind/jsonschema/factories/SchemaFactory.java b/src/main/java/com/fasterxml/jackson/databind/jsonschema/factories/SchemaFactory.java index 1305f72c2f..53407d101e 100644 --- a/src/main/java/com/fasterxml/jackson/databind/jsonschema/factories/SchemaFactory.java +++ b/src/main/java/com/fasterxml/jackson/databind/jsonschema/factories/SchemaFactory.java @@ -2,7 +2,7 @@ import com.fasterxml.jackson.databind.JavaType; import com.fasterxml.jackson.databind.SerializerProvider; -import com.fasterxml.jackson.databind.jsonschema.types.Schema; +import com.fasterxml.jackson.databind.jsonschema.types.JsonSchema; import com.fasterxml.jackson.databind.jsonschema.visitors.JsonAnyFormatVisitor; import com.fasterxml.jackson.databind.jsonschema.visitors.JsonArrayFormatVisitor; import com.fasterxml.jackson.databind.jsonschema.visitors.JsonBooleanFormatVisitor; @@ -37,8 +37,8 @@ public JsonBooleanFormatVisitor booleanFormat() { return (JsonBooleanFormatVisitor) delegate; } - public Schema finalSchema() { - assert delegate != null : "SchemaFactory must envoke a delegate method before it can return a Schema."; + public JsonSchema finalSchema() { + assert delegate != null : "SchemaFactory must envoke a delegate method before it can return a JsonSchema."; if (delegate == null) { return null; } else { diff --git a/src/main/java/com/fasterxml/jackson/databind/jsonschema/factories/SchemaFactoryDelegate.java b/src/main/java/com/fasterxml/jackson/databind/jsonschema/factories/SchemaFactoryDelegate.java index 6eb23b9080..21af14cdff 100644 --- a/src/main/java/com/fasterxml/jackson/databind/jsonschema/factories/SchemaFactoryDelegate.java +++ b/src/main/java/com/fasterxml/jackson/databind/jsonschema/factories/SchemaFactoryDelegate.java @@ -1,8 +1,8 @@ package com.fasterxml.jackson.databind.jsonschema.factories; -import com.fasterxml.jackson.databind.jsonschema.types.Schema; +import com.fasterxml.jackson.databind.jsonschema.types.JsonSchema; public interface SchemaFactoryDelegate { - public Schema getSchema(); + public JsonSchema getSchema(); } diff --git a/src/main/java/com/fasterxml/jackson/databind/jsonschema/factories/ValueTypeSchemaFactory.java b/src/main/java/com/fasterxml/jackson/databind/jsonschema/factories/ValueTypeSchemaFactory.java index d84790f768..2041accc55 100644 --- a/src/main/java/com/fasterxml/jackson/databind/jsonschema/factories/ValueTypeSchemaFactory.java +++ b/src/main/java/com/fasterxml/jackson/databind/jsonschema/factories/ValueTypeSchemaFactory.java @@ -4,7 +4,7 @@ import com.fasterxml.jackson.databind.SerializerProvider; import com.fasterxml.jackson.databind.jsonschema.types.JsonValueFormat; -import com.fasterxml.jackson.databind.jsonschema.types.Schema; +import com.fasterxml.jackson.databind.jsonschema.types.JsonSchema; import com.fasterxml.jackson.databind.jsonschema.types.ValueTypeSchema; import com.fasterxml.jackson.databind.jsonschema.visitors.JsonValueFormatVisitor; @@ -15,7 +15,7 @@ protected ValueTypeSchemaFactory(SerializerProvider provider) { super(provider); } - public Schema getSchema() { + public JsonSchema getSchema() { return getValueSchema(); } protected abstract ValueTypeSchema getValueSchema(); diff --git a/src/main/java/com/fasterxml/jackson/databind/jsonschema/types/AnySchema.java b/src/main/java/com/fasterxml/jackson/databind/jsonschema/types/AnySchema.java index e786dc8dec..7f197a8c4e 100644 --- a/src/main/java/com/fasterxml/jackson/databind/jsonschema/types/AnySchema.java +++ b/src/main/java/com/fasterxml/jackson/databind/jsonschema/types/AnySchema.java @@ -3,9 +3,14 @@ import java.util.HashSet; import java.util.Set; +import com.fasterxml.jackson.annotation.JsonIgnore; import com.fasterxml.jackson.annotation.JsonProperty; - +/** + * This class represents a {@link JsonSchema} of type any + * @author jphelan + * + */ public class AnySchema extends SimpleTypeSchema { /** @@ -20,7 +25,7 @@ of enum values uses the same algorithm as defined in "uniqueItems" @JsonProperty private Set enums; - @JsonProperty(required = true) + @JsonIgnore private final SchemaType type = SchemaType.ANY; //instance initializer block @@ -28,14 +33,34 @@ of enum values uses the same algorithm as defined in "uniqueItems" enums = new HashSet(); } + /* (non-Javadoc) + * @see com.fasterxml.jackson.databind.jsonschema.types.JsonSchema#asAnySchema() + */ @Override public AnySchema asAnySchema() { return this; } + /* (non-Javadoc) + * @see com.fasterxml.jackson.databind.jsonschema.types.JsonSchema#equals(java.lang.Object) + */ + @Override + public boolean equals(Object obj) { + if (obj instanceof AnySchema) { + AnySchema that = ((AnySchema)obj); + return super.equals(obj) && + enums == null ? that.enums == null : enums.equals(that.enums); + } else { + return false; + } + } + + /* (non-Javadoc) + * @see com.fasterxml.jackson.databind.jsonschema.types.JsonSchema#isAnySchema() + */ @Override public boolean isAnySchema() { return true; } /* (non-Javadoc) - * @see com.fasterxml.jackson.databind.jsonschema.types.Schema#getType() + * @see com.fasterxml.jackson.databind.jsonschema.types.JsonSchema#getType() */ @Override public SchemaType getType() { diff --git a/src/main/java/com/fasterxml/jackson/databind/jsonschema/types/ArraySchema.java b/src/main/java/com/fasterxml/jackson/databind/jsonschema/types/ArraySchema.java index f8ae0a172e..0c81f87a26 100644 --- a/src/main/java/com/fasterxml/jackson/databind/jsonschema/types/ArraySchema.java +++ b/src/main/java/com/fasterxml/jackson/databind/jsonschema/types/ArraySchema.java @@ -1,31 +1,45 @@ package com.fasterxml.jackson.databind.jsonschema.types; +import java.util.Map; + +import com.fasterxml.jackson.annotation.JsonCreator; import com.fasterxml.jackson.annotation.JsonIgnore; import com.fasterxml.jackson.annotation.JsonProperty; import com.fasterxml.jackson.annotation.JsonUnwrapped; import com.fasterxml.jackson.annotation.JsonValue; +import com.fasterxml.jackson.databind.jsonschema.factories.SchemaFactory; /* * This attribute defines the allowed items in an instance array, and - MUST be a schema or an array of schemas. The default value is an - empty schema which allows any value for items in the instance array. + MUST be a jsonSchema or an array of jsonSchemas. The default value is an + empty jsonSchema which allows any value for items in the instance array. */ public class ArraySchema extends ContainerTypeSchema { + + /** + * see {@link AdditionalItems} + */ @JsonProperty private ArraySchema.AdditionalItems additionalItems; + /** + * see {@link Items} + */ @JsonProperty private ArraySchema.Items items; + /**This attribute defines the maximum number of values in an array*/ @JsonProperty private Integer maxItems; + /**This attribute defines the minimum number of values in an array*/ @JsonProperty private Integer minItems; - @JsonProperty(required = true) + @JsonIgnore private final SchemaType type = SchemaType.ARRAY; + /** * This attribute indicates that all items in an array instance MUST be unique (contains no two identical values). @@ -46,9 +60,35 @@ public class ArraySchema extends ContainerTypeSchema { @JsonProperty private Boolean uniqueItems = null; + /* (non-Javadoc) + * @see com.fasterxml.jackson.databind.jsonschema.types.JsonSchema#asArraySchema() + */ @Override public ArraySchema asArraySchema() { return this; } + /* (non-Javadoc) + * @see com.fasterxml.jackson.databind.jsonschema.types.JsonSchema#equals(java.lang.Object) + */ + @Override + public boolean equals(Object obj) { + if (obj instanceof ArraySchema) { + ArraySchema that = (ArraySchema) obj; + return getAdditionalItems() == null ? that.getAdditionalItems() == null : + getAdditionalItems().equals(that.getAdditionalItems()) && + getItems() == null ? that.getItems() == null : + getItems().equals(that.getItems()) && + getMaxItems() == null ? that.getMaxItems() == null : + getMaxItems().equals(that.getMaxItems()) && + getMinItems() == null ? that.getMinItems() == null : + getMinItems().equals(that.getMinItems()) && + getUniqueItems() == null ? that.getUniqueItems() == null : + getUniqueItems().equals(that.getUniqueItems()) && + super.equals(obj); + } else { + return false; + } + } + /** * {@link ArraySchema#additionalItems} * @return the additionalItems @@ -82,7 +122,7 @@ public Integer getMinItems() { } /* (non-Javadoc) - * @see com.fasterxml.jackson.databind.jsonschema.types.Schema#getType() + * @see com.fasterxml.jackson.databind.jsonschema.types.JsonSchema#getType() */ @Override public SchemaType getType() { @@ -96,6 +136,10 @@ public SchemaType getType() { public Boolean getUniqueItems() { return uniqueItems; } + + /* (non-Javadoc) + * @see com.fasterxml.jackson.databind.jsonschema.types.JsonSchema#isArraySchema() + */ @Override public boolean isArraySchema() { return true; } @@ -114,8 +158,14 @@ public void setAdditionalItems(ArraySchema.AdditionalItems additionalItems) { public void setItems(ArraySchema.Items items) { this.items = items; } - public void setItemsSchema(Schema schema) { - items = new SingleItems(schema); + + /** + * Convenience method to set the json schema for the {@link ArraySchema#items} + * field + * @param jsonSchema + */ + public void setItemsSchema(JsonSchema jsonSchema) { + items = new SingleItems(jsonSchema); } /** * {@link ArraySchema#maxItems} @@ -145,36 +195,67 @@ public void setUniqueItems(Boolean uniqueItems) { * This provides a definition for additional items in an array instance when tuple definitions of the items is provided. */ - public static abstract class AdditionalItems {} + public static abstract class AdditionalItems { + + @JsonCreator + public static Items jsonCreator(Map props) { + // not implemented for jsonSchema + return null; + //KNOWN ISSUE: pending https://github.com/FasterXML/jackson-databind/issues/43 + } + } /** - * When this attribute value is an array of schemas and the instance + * When this attribute value is an array of jsonSchemas and the instance value is an array, each position in the instance array MUST conform - to the schema in the corresponding position for this array. This + to the jsonSchema in the corresponding position for this array. This called tuple typing. When tuple typing is used, additional items are allowed, disallowed, or constrained by the "additionalItems" */ public static class ArrayItems extends ArraySchema.Items { @JsonProperty - private Schema[] schemas; + private JsonSchema[] jsonSchemas; /* (non-Javadoc) - * @see com.fasterxml.jackson.databind.jsonschema.types.ArraySchema.Items#isArrayItems() + * @see com.fasterxml.jackson.databind.jsonschema.types.ArraySchema.Items#asArrayItems() */ @Override - public boolean isArrayItems() { return true; } + public ArrayItems asArrayItems() { return this; } /* (non-Javadoc) - * @see com.fasterxml.jackson.databind.jsonschema.types.ArraySchema.Items#asArrayItems() + * @see java.lang.Object#equals(java.lang.Object) */ @Override - public ArrayItems asArrayItems() { return this; } + public boolean equals(Object obj) { + if (obj instanceof Items) { + ArrayItems that = (ArrayItems) obj; + return getJsonSchemas() == null ? that.getJsonSchemas() == null : + getJsonSchemas().equals(that.getJsonSchemas()); + } else { + return false; + } + } + + /** + * {@link ArraySchema.ArrayItems#jsonSchemas} + * @return the jsonSchemas + */ + public JsonSchema[] getJsonSchemas() { + return jsonSchemas; + } + + /* (non-Javadoc) + * @see com.fasterxml.jackson.databind.jsonschema.types.ArraySchema.Items#isArrayItems() + */ + @Override + public boolean isArrayItems() { return true; } + } /** * This attribute defines the allowed items in an instance array, and - MUST be a schema or an array of schemas. The default value is an - empty schema which allows any value for items in the instance array. + MUST be a jsonSchema or an array of jsonSchemas. The default value is an + empty jsonSchema which allows any value for items in the instance array. */ public static abstract class Items { @@ -186,54 +267,107 @@ public static abstract class Items { public SingleItems asSingleItems() { return null; } public ArrayItems asArrayItems() { return null; } + + @JsonCreator + public static Items jsonCreator(Map props) { + //for now only support deserialization of singleItems + Object typeFound = props.get("type"); + if (typeFound == null || ! (typeFound instanceof String)) { + return null; + } + String type = (String) typeFound; + JsonSchema schema = JsonSchema.minimalForFormat(SchemaType.forValue(type)); + //KNOWN ISSUE: pending https://github.com/FasterXML/jackson-databind/issues/43 + //only deserialize items as minimal schema for type + return new SingleItems(schema); + } + } /** * This can be false to indicate additional items in the array are not allowed */ - public static class NoAdditionalItems { + public static class NoAdditionalItems extends AdditionalItems { + + /* (non-Javadoc) + * @see java.lang.Object#equals(java.lang.Object) + */ + @Override + public boolean equals(Object obj) { + return obj instanceof NoAdditionalItems; + } @JsonValue public Boolean value() { return false; } } /** * or it can - be a schema that defines the schema of the additional items. + be a jsonSchema that defines the jsonSchema of the additional items. */ - public static class SchemaAdditionalItems { + public static class SchemaAdditionalItems extends AdditionalItems { - @JsonUnwrapped - private Schema schema; + @JsonIgnore + private JsonSchema jsonSchema; + + public SchemaAdditionalItems(JsonSchema schema) { + jsonSchema = schema; + } + + /* (non-Javadoc) + * @see java.lang.Object#equals(java.lang.Object) + */ + @Override + public boolean equals(Object obj) { + return obj instanceof SchemaAdditionalItems && + getJsonSchema() == null ? ((SchemaAdditionalItems)obj).getJsonSchema() == null : + getJsonSchema().equals(((SchemaAdditionalItems)obj).getJsonSchema()); + } + + @JsonValue + public JsonSchema getJsonSchema() { + return jsonSchema; + } } /** - * When this attribute value is a schema and the instance value is an + * When this attribute value is a jsonSchema and the instance value is an array, then all the items in the array MUST be valid according to the - schema. + jsonSchema. */ public static class SingleItems extends ArraySchema.Items { - @JsonUnwrapped - private Schema schema; + @JsonIgnore + private JsonSchema jsonSchema; - public SingleItems(Schema schema) { - this.schema = schema; + public SingleItems(JsonSchema jsonSchema) { + this.jsonSchema = jsonSchema; + } + + /* (non-Javadoc) + * @see java.lang.Object#equals(java.lang.Object) + */ + @Override + public boolean equals(Object obj) { + return obj instanceof SingleItems && + getSchema() == null ? ((SingleItems)obj).getSchema() == null : + getSchema().equals(((SingleItems)obj).getSchema()); } /** - * {@link ArraySchema.SingleItems#schema} - * @return the schema + * {@link ArraySchema.SingleItems#jsonSchema} + * @return the jsonSchema */ - public Schema getSchema() { - return schema; + @JsonValue + public JsonSchema getSchema() { + return jsonSchema; } /** - * {@link ArraySchema.SingleItems#schema} - * @param schema the schema to set + * {@link ArraySchema.SingleItems#jsonSchema} + * @param jsonSchema the jsonSchema to set */ - public void setSchema(Schema schema) { - this.schema = schema; + public void setSchema(JsonSchema jsonSchema) { + this.jsonSchema = jsonSchema; } /* (non-Javadoc) diff --git a/src/main/java/com/fasterxml/jackson/databind/jsonschema/types/BooleanSchema.java b/src/main/java/com/fasterxml/jackson/databind/jsonschema/types/BooleanSchema.java index e7fdbbf55f..2d0bbb9bfa 100644 --- a/src/main/java/com/fasterxml/jackson/databind/jsonschema/types/BooleanSchema.java +++ b/src/main/java/com/fasterxml/jackson/databind/jsonschema/types/BooleanSchema.java @@ -1,23 +1,34 @@ package com.fasterxml.jackson.databind.jsonschema.types; -import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.annotation.JsonIgnore; +/** + * This class represents a {@link JsonSchema} of type boolean + * @author jphelan + * + */ public class BooleanSchema extends ValueTypeSchema { - @JsonProperty(required = true) + @JsonIgnore private final SchemaType type = SchemaType.BOOLEAN; + /* (non-Javadoc) + * @see com.fasterxml.jackson.databind.jsonschema.types.JsonSchema#isBooleanSchema() + */ @Override public boolean isBooleanSchema() { return true; } /* (non-Javadoc) - * @see com.fasterxml.jackson.databind.jsonschema.types.Schema#getType() + * @see com.fasterxml.jackson.databind.jsonschema.types.JsonSchema#getType() */ @Override public SchemaType getType() { return type; } + /* (non-Javadoc) + * @see com.fasterxml.jackson.databind.jsonschema.types.JsonSchema#asBooleanSchema() + */ @Override public BooleanSchema asBooleanSchema() { return this; } } \ No newline at end of file diff --git a/src/main/java/com/fasterxml/jackson/databind/jsonschema/types/ContainerTypeSchema.java b/src/main/java/com/fasterxml/jackson/databind/jsonschema/types/ContainerTypeSchema.java index 595e43cd82..c73b14cad6 100644 --- a/src/main/java/com/fasterxml/jackson/databind/jsonschema/types/ContainerTypeSchema.java +++ b/src/main/java/com/fasterxml/jackson/databind/jsonschema/types/ContainerTypeSchema.java @@ -5,7 +5,12 @@ import com.fasterxml.jackson.annotation.JsonProperty; - +/** + * This class encapsulates the functionality of container type {@link JsonSchema} + * Array and Object + * @author jphelan + * + */ public abstract class ContainerTypeSchema extends SimpleTypeSchema { /** * This provides an enumeration of all possible values that are valid @@ -24,13 +29,27 @@ of enum values uses the same algorithm as defined in "uniqueItems" enums = new HashSet(); } - /** - * {@link ContainerTypeSchema#enums} - * @param enums the enums to set + /* (non-Javadoc) + * @see com.fasterxml.jackson.databind.jsonschema.types.JsonSchema#asContainerSchema() */ - public void setEnums(Set enums) { - this.enums = enums; - } + @Override + public ContainerTypeSchema asContainerSchema() { return this; } + + /* (non-Javadoc) + * @see com.fasterxml.jackson.databind.jsonschema.types.SimpleTypeSchema#equals(java.lang.Object) + */ + @Override + public boolean equals(Object obj) { + if (obj instanceof ContainerTypeSchema) { + ContainerTypeSchema that = (ContainerTypeSchema)obj; + return getEnums() == null ? that.getEnums() == null : + getEnums().equals(that.getEnums()) && + super.equals(obj); + } else { + return false; + } + } + /** * {@link ContainerTypeSchema#enums} * @return the enums @@ -39,9 +58,17 @@ public Set getEnums() { return enums; } + /* (non-Javadoc) + * @see com.fasterxml.jackson.databind.jsonschema.types.JsonSchema#isContainerTypeSchema() + */ @Override public boolean isContainerTypeSchema() { return true; } - @Override - public ContainerTypeSchema asContainerSchema() { return this; } + /** + * {@link ContainerTypeSchema#enums} + * @param enums the enums to set + */ + public void setEnums(Set enums) { + this.enums = enums; + } } \ No newline at end of file diff --git a/src/main/java/com/fasterxml/jackson/databind/jsonschema/types/HyperSchema.java b/src/main/java/com/fasterxml/jackson/databind/jsonschema/types/HyperSchema.java index 053eaf3d22..3019549e34 100644 --- a/src/main/java/com/fasterxml/jackson/databind/jsonschema/types/HyperSchema.java +++ b/src/main/java/com/fasterxml/jackson/databind/jsonschema/types/HyperSchema.java @@ -2,7 +2,13 @@ import com.fasterxml.jackson.annotation.JsonProperty; -public class HyperSchema extends Schema { +/** + * This class represents the HyperSchema portion of a {@link JsonSchema} + * It is a skeleton intended as a starting point for customization. + * @author jphelan + * + */ +public class HyperSchema extends JsonSchema { /** @@ -16,7 +22,7 @@ public class HyperSchema extends Schema { /** * If the instance property value is a string, this attribute defines that the string SHOULD be interpreted as binary data and decoded - using the encoding named by this schema property. RFC 2045, Sec 6.1 + using the encoding named by this jsonSchema property. RFC 2045, Sec 6.1 [RFC2045] lists the possible values for this property. */ @JsonProperty @@ -30,12 +36,12 @@ public class HyperSchema extends Schema { relative to the instance's URI. When multiple schemas have been referenced for an instance, the user - agent can determine if this schema is applicable for a particular + agent can determine if this jsonSchema is applicable for a particular instance by determining if the URI of the instance begins with the the value of the "pathStart" attribute. If the URI of the instance - does not start with this URI, or if another schema specifies a + does not start with this URI, or if another jsonSchema specifies a starting URI that is longer and also matches the instance, this - schema SHOULD NOT be applied to the instance. Any schema that does + jsonSchema SHOULD NOT be applied to the instance. Any jsonSchema that does not have a pathStart attribute SHOULD be considered applicable to all the instances for which it is referenced. */ @@ -44,7 +50,7 @@ public class HyperSchema extends Schema { /** * This attribute defines the media type of the instance representations - that this schema is defining. + that this jsonSchema is defining. */ @JsonProperty private String mediaType; @@ -131,11 +137,11 @@ public class HyperSchema extends Schema { /** * A link description object is used to describe link relations. In the - context of a schema, it defines the link relations of the instances - of the schema, and can be parameterized by the instance values. The - link description format can be used on its own in regular (non-schema + context of a jsonSchema, it defines the link relations of the instances + of the jsonSchema, and can be parameterized by the instance values. The + link description format can be used on its own in regular (non-jsonSchema documents), and use of this format can be declared by referencing the - normative link description schema as the the schema for the data + normative link description jsonSchema as the the jsonSchema for the data structure that uses the links. */ public class LinkDescriptionObject { @@ -146,8 +152,8 @@ public class LinkDescriptionObject { property SHOULD be resolved as a URI-Reference per RFC 3986 [RFC3986] and MAY be a relative URI. The base URI to be used for relative resolution SHOULD be the URI used to retrieve the instance object - (not the schema) when used within a schema. Also, when links are - used within a schema, the URI SHOULD be parametrized by the property + (not the jsonSchema) when used within a jsonSchema. Also, when links are + used within a jsonSchema, the URI SHOULD be parametrized by the property values of the instance object, if property values exist for the corresponding variables in the template (otherwise they MAY be provided from alternate sources, like user input). @@ -180,19 +186,19 @@ in situations where the instance is a scalar (string, boolean, or /** * The value of the "rel" property indicates the name of the relation to the target resource. The relation to the target SHOULD be - interpreted as specifically from the instance object that the schema - (or sub-schema) applies to, not just the top level resource that + interpreted as specifically from the instance object that the jsonSchema + (or sub-jsonSchema) applies to, not just the top level resource that contains the object within its hierarchy. If a resource JSON representation contains a sub object with a property interpreted as a link, that sub-object holds the relation with the target. A relation to target from the top level resource MUST be indicated with the - schema describing the top level JSON representation. + jsonSchema describing the top level JSON representation. Relationship definitions SHOULD NOT be media type dependent, and users are encouraged to utilize existing accepted relation definitions, including those in existing relation registries (see RFC 4287 [RFC4287]). However, we define these relations here for clarity - of normative interpretation within the context of JSON hyper schema + of normative interpretation within the context of JSON hyper jsonSchema defined relations: self If the relation value is "self", when this property is @@ -205,7 +211,7 @@ definitions, including those in existing relation registries (see RFC representation for the instance object. The object that contains this link possibly may not be the full representation. - describedby This indicates the target of the link is the schema for + describedby This indicates the target of the link is the jsonSchema for the instance object. This MAY be used to specifically denote the schemas of objects within a JSON object hierarchy, facilitating polymorphic type data structures. @@ -216,17 +222,17 @@ definitions, including those in existing relation registries (see RFC other properties of the instance objects can be regarded as meta- data descriptions for the data. - The following relations are applicable for schemas (the schema as the + The following relations are applicable for schemas (the jsonSchema as the "from" resource in the relation): instances This indicates the target resource that represents - collection of instances of a schema. + collection of instances of a jsonSchema. create This indicates a target to use for creating new instances of - a schema. This link definition SHOULD be a submission link with a + a jsonSchema. This link definition SHOULD be a submission link with a non-safe method (like POST). - For example, if a schema is defined: + For example, if a jsonSchema is defined: { "links": [ @@ -271,11 +277,11 @@ The following relations are applicable for schemas (the schema as the private String rel; /** - * This property value is a schema that defines the expected structure + * This property value is a jsonSchema that defines the expected structure of the JSON representation of the target of the link. */ @JsonProperty - private Schema targetSchema; + private JsonSchema targetSchema; /** * This attribute defines which method can be used to access the target @@ -294,7 +300,7 @@ The following relations are applicable for schemas (the schema as the target URI to query the collection with property-based constraints on the resources that SHOULD be returned from the server or used to post data to the resource (depending on the method). For example, with - the following schema: + the following jsonSchema: { "links":[ @@ -321,22 +327,21 @@ data to the resource (depending on the method). For example, with private String enctype; /** - * This attribute contains a schema which defines the acceptable - structure of the submitted request (for a GET request, this schema + * This attribute contains a jsonSchema which defines the acceptable + structure of the submitted request (for a GET request, this jsonSchema would define the properties for the query string and for a POST request, this would define the body). */ @JsonProperty - private Schema schema; + private JsonSchema jsonSchema; } /* (non-Javadoc) - * @see com.fasterxml.jackson.databind.jsonschema.types.Schema#getType() + * @see com.fasterxml.jackson.databind.jsonschema.types.JsonSchema#getType() */ @Override public SchemaType getType() { - // TODO Auto-generated method stub return null; } } \ No newline at end of file diff --git a/src/main/java/com/fasterxml/jackson/databind/jsonschema/types/IntegerSchema.java b/src/main/java/com/fasterxml/jackson/databind/jsonschema/types/IntegerSchema.java index 33fd02663d..4baaaacb7c 100644 --- a/src/main/java/com/fasterxml/jackson/databind/jsonschema/types/IntegerSchema.java +++ b/src/main/java/com/fasterxml/jackson/databind/jsonschema/types/IntegerSchema.java @@ -2,11 +2,13 @@ import com.fasterxml.jackson.annotation.JsonProperty; +/** + * This class represents a {@link JsonSchema} as an integer type + * @author jphelan + * + */ public class IntegerSchema extends NumberSchema { - @JsonProperty(required = true) - public final SchemaType type = SchemaType.INTEGER; - /** * This attribute defines what value the number instance must be divisible by with no remainder (the result of the division must be an @@ -15,13 +17,28 @@ divisible by with no remainder (the result of the division must be an @JsonProperty private Integer divisibleBy; - /** - * {@link IntegerSchema#divisibleBy} - * @param divisibleBy the divisibleBy to set + @JsonProperty(required = true) + public final SchemaType type = SchemaType.INTEGER; + + @Override + public IntegerSchema asIntegerSchema() { return this; } + + /* (non-Javadoc) + * @see com.fasterxml.jackson.databind.jsonschema.types.NumberSchema#equals(java.lang.Object) */ - public void setDivisibleBy(Integer divisibleBy) { - this.divisibleBy = divisibleBy; - } + @Override + public boolean equals(Object obj) { + if (obj instanceof IntegerSchema) { + IntegerSchema that = (IntegerSchema)obj; + return getDivisibleBy() == null ? that.getDivisibleBy() == null : + getDivisibleBy().equals(that.getDivisibleBy()) && + super.equals(obj); + } else { + return false; + } + } + + /** * {@link IntegerSchema#divisibleBy} * @return the divisibleBy @@ -33,6 +50,11 @@ public Integer getDivisibleBy() { @Override public boolean isIntegerSchema() { return true; } - @Override - public IntegerSchema asIntegerSchema() { return this; } + /** + * {@link IntegerSchema#divisibleBy} + * @param divisibleBy the divisibleBy to set + */ + public void setDivisibleBy(Integer divisibleBy) { + this.divisibleBy = divisibleBy; + } } \ No newline at end of file diff --git a/src/main/java/com/fasterxml/jackson/databind/jsonschema/types/JsonSchema.java b/src/main/java/com/fasterxml/jackson/databind/jsonschema/types/JsonSchema.java new file mode 100644 index 0000000000..95301a0f74 --- /dev/null +++ b/src/main/java/com/fasterxml/jackson/databind/jsonschema/types/JsonSchema.java @@ -0,0 +1,613 @@ +package com.fasterxml.jackson.databind.jsonschema.types; + +import com.fasterxml.jackson.annotation.JsonGetter; +import com.fasterxml.jackson.annotation.JsonIgnore; +import com.fasterxml.jackson.annotation.JsonInclude; +import com.fasterxml.jackson.annotation.JsonInclude.Include; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.annotation.JsonSetter; +import com.fasterxml.jackson.annotation.JsonTypeInfo; +import com.fasterxml.jackson.annotation.JsonTypeInfo.As; +import com.fasterxml.jackson.annotation.JsonTypeInfo.Id; +import com.fasterxml.jackson.databind.JavaType; +import com.fasterxml.jackson.databind.annotation.JsonTypeIdResolver; +import com.fasterxml.jackson.databind.jsontype.TypeIdResolver; +import com.fasterxml.jackson.databind.jsontype.impl.TypeIdResolverBase; +import com.fasterxml.jackson.databind.type.TypeFactory; + +/** + * The type wraps the json schema specification at : + * Json JsonSchema + * Draft
JSON (JavaScript Object Notation) JsonSchema defines the + * media type "application/schema+json", a JSON based format for defining the + * structure of JSON data. JSON JsonSchema provides a contract for what JSON data is + * required for a given application and how to interact with it. JSON JsonSchema is + * intended to define validation, documentation, hyperlink navigation, and + * interaction control of JSON data.
+ * + *
JSON (JavaScript Object Notation) JsonSchema is a JSON media type + * for defining the structure of JSON data. JSON JsonSchema provides a contract for + * what JSON data is required for a given application and how to interact with + * it. JSON JsonSchema is intended to define validation, documentation, hyperlink + * navigation, and interaction control of JSON data.
+ * + * An example JSON JsonSchema provided by the JsonSchema draft: + * + *
+ * 	{
+ * 	  "name":"Product",
+ * 	  "properties":{
+ * 	    "id":{
+ * 	      "type":"number",
+ * 	      "description":"Product identifier",
+ * 	      "required":true
+ * 	    },
+ * 	    "name":{
+ * 	      "description":"Name of the product",
+ * 	      "type":"string",
+ * 	      "required":true
+ * 	    },
+ * 	    "price":{
+ * 	      "required":true,
+ * 	      "type": "number",
+ * 	      "minimum":0,
+ * 	      "required":true
+ * 	    },
+ * 	    "tags":{
+ * 	      "type":"array",
+ * 	      "items":{
+ * 	        "type":"string"
+ * 	      }
+ * 	    }
+ * 	  },
+ * 	  "links":[
+ * 	    {
+ * 	      "rel":"full",
+ * 	      "href":"{id}"
+ * 	    },
+ * 	    {
+ * 	      "rel":"comments",
+ * 	      "href":"comments/?id={id}"
+ * 	    }
+ * 	  ]
+ * 	}
+ * 
+ * + * @author jphelan + */ +@JsonInclude(Include.NON_EMPTY) +@JsonTypeInfo(use = Id.CUSTOM, include = As.PROPERTY, property = "type") +@JsonTypeIdResolver(JsonSchema.JsonSchemaIdResolver.class) +public abstract class JsonSchema { + + /** + * This attribute defines a URI of a schema that contains the full + * representation of this schema. When a validator encounters this + * attribute, it SHOULD replace the current schema with the schema + * referenced by the value's URI (if known and available) and re- validate + * the instance. This URI MAY be relative or absolute, and relative URIs + * SHOULD be resolved against the URI of the current schema. + */ + @JsonProperty + private String $ref; + + /** + * This attribute defines a URI of a JSON JsonSchema that is the schema of the + * current schema. When this attribute is defined, a validator SHOULD use + * the schema referenced by the value's URI (if known and available) when + * resolving Hyper JsonSchema (Section 6) links (Section 6.1). + * + * A validator MAY use this attribute's value to determine which version of + * JSON JsonSchema the current schema is written in, and provide the appropriate + * validation features and behavior. Therefore, it is RECOMMENDED that all + * schema authors include this attribute in their schemas to prevent + * conflicts with future JSON JsonSchema specification changes. + */ + @JsonProperty + private String $schema; + + /** + * This attribute takes the same values as the "type" attribute, however if + * the instance matches the type or if this value is an array and the + * instance matches any type or schema in the array, then this instance is + * not valid. + */ + @JsonProperty + private JsonSchema[] disallow; + /** + * The value of this property MUST be another schema which will provide a + * base schema which the current schema will inherit from. The inheritance + * rules are such that any instance that is valid according to the current + * schema MUST be valid according to the referenced schema. This MAY also be + * an array, in which case, the instance MUST be valid for all the schemas + * in the array. A schema that extends another schema MAY define additional + * attributes, constrain existing attributes, or add other constraints. + * + * Conceptually, the behavior of extends can be seen as validating an + * instance against all constraints in the extending schema as well as the + * extended schema(s). More optimized implementations that merge schemas are + * possible, but are not required. An example of using "extends": + * + * { "description":"An adult", "properties":{"age":{"minimum": 21}}, + * "extends":"person" } { "description":"Extended schema", + * "properties":{"deprecated":{"type": "boolean"}}, + * "extends":"http://json-schema.org/draft-03/schema" } + */ + @JsonIgnore + private JsonSchema[] extendsextends; + /** + * This attribute defines the current URI of this schema (this attribute is + * effectively a "self" link). This URI MAY be relative or absolute. If the + * URI is relative it is resolved against the current URI of the parent + * schema it is contained in. If this schema is not contained in any parent + * schema, the current URI of the parent schema is held to be the URI under + * which this schema was addressed. If id is missing, the current URI of a + * schema is defined to be that of the parent schema. The current URI of the + * schema is also used to construct relative references such as for $ref. + */ + @JsonProperty + private String id; + /** + * This attribute indicates if the instance must have a value, and not be + * undefined. This is false by default, making the instance optional. + */ + @JsonProperty + private Boolean required = null; + + + /** + * Attempt to return this JsonSchema as an {@link AnySchema} + * @return this as an AnySchema if possible, or null otherwise + */ + public AnySchema asAnySchema() { + return null; + } + + /** + * Attempt to return this JsonSchema as an {@link ArraySchema} + * @return this as an ArraySchema if possible, or null otherwise + */ + public ArraySchema asArraySchema() { + return null; + } + + /** + * Attempt to return this JsonSchema as a {@link BooleanSchema} + * @return this as a BooleanSchema if possible, or null otherwise + */ + public BooleanSchema asBooleanSchema() { + return null; + } + + /** + * Attempt to return this JsonSchema as a {@link ContainerTypeSchema} + * @return this as an ContainerTypeSchema if possible, or null otherwise + */ + public ContainerTypeSchema asContainerSchema() { + return null; + } + + /** + * Attempt to return this JsonSchema as an {@link IntegerSchema} + * @return this as an IntegerSchema if possible, or null otherwise + */ + public IntegerSchema asIntegerSchema() { + return null; + } + + /** + * Attempt to return this JsonSchema as a {@link NullSchema} + * @return this as a NullSchema if possible, or null otherwise + */ + public NullSchema asNullSchema() { + return null; + } + + /** + * Attempt to return this JsonSchema as a {@link NumberSchema} + * @return this as a NumberSchema if possible, or null otherwise + */ + public NumberSchema asNumberSchema() { + return null; + } + + /** + * Attempt to return this JsonSchema as an {@link ObjectSchema} + * @return this as an ObjectSchema if possible, or null otherwise + */ + public ObjectSchema asObjectSchema() { + return null; + } + + /** + * Attempt to return this JsonSchema as a {@link SimpleTypeSchema} + * @return this as a SimpleTypeSchema if possible, or null otherwise + */ + public SimpleTypeSchema asSimpleTypeSchema() { + return null; + } + + /** + * Attempt to return this JsonSchema as a {@link StringSchema} + * @return this as a StringSchema if possible, or null otherwise + */ + public StringSchema asStringSchema() { + return null; + } + + /** + * Attempt to return this JsonSchema as an {@link UnionTypeSchema} + * @return this as a UnionTypeSchema if possible, or null otherwise + */ + public UnionTypeSchema asUnionTypeSchema() { + return null; + } + + /** + * Attempt to return this JsonSchema as a {@link ValueTypeSchema} + * @return this as a ValueTypeSchema if possible, or null otherwise + */ + public ValueTypeSchema asValueSchemaSchema() { + return null; + } + + + /* (non-Javadoc) + * @see java.lang.Object#equals(java.lang.Object) + */ + @Override + public boolean equals(Object obj) { + if (obj instanceof JsonSchema) { + JsonSchema that = ((JsonSchema)obj); + return that.getType() == getType() && + getRequired() == null ? that.getRequired() == null : + getRequired().equals(that.getRequired()) && + get$ref() == null ? that.get$ref() == null : + get$ref().equals(that.get$ref()) && + get$schema() == null ? that.get$schema() == null : + get$schema().equals(that.get$schema()) && + getDisallow() == null ? that.getDisallow() == null : + getDisallow().equals(that.getDisallow()) && + getExtends() == null ? that.getExtends() == null : + getExtends().equals(that.getExtends()); + } + return false; + } + + /** + * {@link JsonSchema#$ref} + * + * @return the $ref + */ + public String get$ref() { + return $ref; + } + + /** + * {@link JsonSchema#$schema} + * + * @return the $schema + */ + public String get$schema() { + return $schema; + } + + /** + * {@link JsonSchema#disallow} + * + * @return the disallow + */ + public JsonSchema[] getDisallow() { + return disallow; + } + + /** + * {@link JsonSchema#extendsextends} + * + * @return the extendsextends + */ + @JsonGetter("extends") + public JsonSchema[] getExtends() { + return extendsextends; + } + + /** + * {@link JsonSchema#id} + * + * @return the id + */ + public String getId() { + return id; + } + + /** + * {@link JsonSchema#required} + * + * @return the required + */ + public Boolean getRequired() { + return required; + } + + @JsonIgnore + public abstract SchemaType getType(); + + + /** + * determine if this JsonSchema is an {@link AnySchema}. + * + * @return true if this JsonSchema is an AnySchema, false otherwise + */ + @JsonIgnore + public boolean isAnySchema() { + return false; + } + + /** + * determine if this JsonSchema is an {@link ArraySchema}. + * + * @return true if this JsonSchema is an ArraySchema, false otherwise + */ + @JsonIgnore + public boolean isArraySchema() { + return false; + } + + /** + * determine if this JsonSchema is an {@link BooleanSchema}. + * + * @return true if this JsonSchema is an BooleanSchema, false otherwise + */ + @JsonIgnore + public boolean isBooleanSchema() { + return false; + } + + /** + * determine if this JsonSchema is an {@link ContainerTypeSchema}. + * + * @return true if this JsonSchema is an ContainerTypeSchema, false otherwise + */ + @JsonIgnore + public boolean isContainerTypeSchema() { + return false; + } + + /** + * determine if this JsonSchema is an {@link IntegerSchema}. + * + * @return true if this JsonSchema is an IntegerSchema, false otherwise + */ + @JsonIgnore + public boolean isIntegerSchema() { + return false; + } + + /** + * determine if this JsonSchema is an {@link NullSchema}. + * + * @return true if this JsonSchema is an NullSchema, false otherwise + */ + @JsonIgnore + public boolean isNullSchema() { + return false; + } + + /** + * determine if this JsonSchema is an {@link NumberSchema}. + * + * @return true if this JsonSchema is an NumberSchema, false otherwise + */ + @JsonIgnore + public boolean isNumberSchema() { + return false; + } + + /** + * determine if this JsonSchema is an {@link ObjectSchema}. + * + * @return true if this JsonSchema is an ObjectSchema, false otherwise + */ + @JsonIgnore + public boolean isObjectSchema() { + return false; + } + + /** + * determine if this JsonSchema is an {@link SimpleTypeSchema}. + * + * @return true if this JsonSchema is an SimpleTypeSchema, false otherwise + */ + @JsonIgnore + public boolean isSimpleTypeSchema() { + return false; + } + + /** + * determine if this JsonSchema is an {@link StringSchema}. + * + * @return true if this JsonSchema is an StringSchema, false otherwise + */ + @JsonIgnore + public boolean isStringSchema() { + return false; + } + + /** + * determine if this JsonSchema is an {@link UnionTypeSchema}. + * + * @return true if this JsonSchema is an UnionTypeSchema, false otherwise + */ + @JsonIgnore + public boolean isUnionTypeSchema() { + return false; + } + + + /** + * determine if this JsonSchema is an {@link ValueTypeSchema}. + * + * @return true if this JsonSchema is an ValueTypeSchema, false otherwise + */ + @JsonIgnore + public boolean isValueTypeSchema() { + return false; + } + + /** + * {@link JsonSchema#$ref} + * + * @param $ref + * the $ref to set + */ + public void set$ref(String $ref) { + this.$ref = $ref; + } + + /** + * {@link JsonSchema#$schema} + * + * @param $schema + * the $schema to set + */ + public void set$schema(String $schema) { + this.$schema = $schema; + } + + /** + * {@link JsonSchema#disallow} + * + * @param disallow + * the disallow to set + */ + public void setDisallow(JsonSchema[] disallow) { + this.disallow = disallow; + } + + /** + * {@link JsonSchema#extendsextends} + * + * @param extendsextends + * the extendsextends to set + */ + @JsonSetter("extends") + public void setExtends(JsonSchema[] extendsextends) { + this.extendsextends = extendsextends; + } + + /** + * {@link JsonSchema#id} + * + * @param id + * the id to set + */ + public void setId(String id) { + this.id = id; + } + + /** + * {@link JsonSchema#required} + * + * @param required + * the required to set + */ + public void setRequired(Boolean required) { + this.required = required; + } + + /** + * Create a schema which verifies only that an object is of the given format. + * @param format the format to expect + * @return the schema verifying the given format + */ + public static JsonSchema minimalForFormat(SchemaType format) { + switch (format) { + case ARRAY: + return new ArraySchema(); + case OBJECT: + return new ObjectSchema(); + case BOOLEAN: + return new BooleanSchema(); + case INTEGER: + return new IntegerSchema(); + case NUMBER: + return new NumberSchema(); + case STRING: + return new StringSchema(); + case NULL: + return new NullSchema(); + + default: + return new AnySchema(); + } + } + + public static class JsonSchemaIdResolver implements TypeIdResolver { + + + /* (non-Javadoc) + * @see com.fasterxml.jackson.databind.jsontype.TypeIdResolver#idFromValue(java.lang.Object) + */ + public String idFromValue(Object value) { + if ( value instanceof JsonSchema) { + return ((JsonSchema)value).getType().value(); + } else { + return null; + } + } + + /* (non-Javadoc) + * @see com.fasterxml.jackson.databind.jsontype.TypeIdResolver#idFromValueAndType(java.lang.Object, java.lang.Class) + */ + public String idFromValueAndType(Object value, Class suggestedType) { + return idFromValue(value); + } + + private static JavaType any = TypeFactory.defaultInstance().constructType(AnySchema.class); + private static JavaType array = TypeFactory.defaultInstance().constructType(ArraySchema.class); + private static JavaType booleanboolean = TypeFactory.defaultInstance().constructType(BooleanSchema.class); + private static JavaType integer = TypeFactory.defaultInstance().constructType(IntegerSchema.class); + private static JavaType nullnull = TypeFactory.defaultInstance().constructType(NullSchema.class); + private static JavaType number = TypeFactory.defaultInstance().constructType(NumberSchema.class); + private static JavaType object = TypeFactory.defaultInstance().constructType(ObjectSchema.class); + private static JavaType string = TypeFactory.defaultInstance().constructType(StringSchema.class); + + /* (non-Javadoc) + * @see com.fasterxml.jackson.databind.jsontype.TypeIdResolver#typeFromId(java.lang.String) + */ + public JavaType typeFromId(String id) { + switch (SchemaType.forValue(id)) { + case ANY: return any; + case ARRAY: return array; + case BOOLEAN: return booleanboolean; + case INTEGER: return integer; + case NULL: return nullnull; + case NUMBER: return number; + case OBJECT: return object; + case STRING: return string; + default: + return null; + } + } + + /* (non-Javadoc) + * @see com.fasterxml.jackson.databind.jsontype.TypeIdResolver#getMechanism() + */ + public Id getMechanism() { + return Id.CUSTOM; + } + + /* (non-Javadoc) + * @see com.fasterxml.jackson.databind.jsontype.TypeIdResolver#init(com.fasterxml.jackson.databind.JavaType) + */ + public void init(JavaType baseType) { } + + /* (non-Javadoc) + * @see com.fasterxml.jackson.databind.jsontype.TypeIdResolver#idFromBaseType() + */ + public String idFromBaseType() { + return null; + } + + } +} \ No newline at end of file diff --git a/src/main/java/com/fasterxml/jackson/databind/jsonschema/types/JsonValueFormat.java b/src/main/java/com/fasterxml/jackson/databind/jsonschema/types/JsonValueFormat.java index f02cf78449..d4d4a2bb3f 100644 --- a/src/main/java/com/fasterxml/jackson/databind/jsonschema/types/JsonValueFormat.java +++ b/src/main/java/com/fasterxml/jackson/databind/jsonschema/types/JsonValueFormat.java @@ -1,7 +1,12 @@ package com.fasterxml.jackson.databind.jsonschema.types; +/** + * This enum represents the encoded format for a jsonSchema value type + * @author jphelan + * + */ public enum JsonValueFormat { - /* + /** * This SHOULD be a date in ISO 8601 format of YYYY-MM- DDThh:mm:ssZ in UTC time. This is the recommended form of date/ timestamp. @@ -11,7 +16,7 @@ public enum JsonValueFormat { public String toString() { return "date-time"; } }, - /* + /** * This SHOULD be a date in the format of YYYY-MM-DD. It is recommended that you use the "date-time" format instead of "date" unless you need to transfer only the date part. @@ -21,7 +26,7 @@ public enum JsonValueFormat { public String toString() { return "date"; } }, - /* + /** * This SHOULD be a time in the format of hh:mm:ss. It is recommended that you use the "date-time" format instead of "time" unless you need to transfer only the time part. @@ -31,7 +36,7 @@ public enum JsonValueFormat { public String toString() { return "time"; } }, - /* + /** * This SHOULD be the difference, measured in milliseconds, between the specified time and midnight, 00:00 of January 1, 1970 UTC. The value SHOULD be a number (integer or @@ -42,7 +47,7 @@ public enum JsonValueFormat { public String toString() { return "utc-millisec"; } }, - /* + /** * A regular expression, following the regular expression specification from ECMA 262/Perl 5. */ @@ -51,7 +56,7 @@ public enum JsonValueFormat { public String toString() { return "regex"; } }, - /* + /** * This is a CSS color (like "#FF0000" or "red"), based on CSS 2.1 [W3C.CR-CSS21-20070719]. */ @@ -60,7 +65,7 @@ public enum JsonValueFormat { public String toString() { return "color"; } }, - /* + /** * This is a CSS style definition (like "color: red; background- color:#FFF"), based on CSS 2.1 [W3C.CR-CSS21-20070719]. */ @@ -69,7 +74,7 @@ public enum JsonValueFormat { public String toString() { return "style"; } }, - /* + /** * This SHOULD be a phone number (format MAY follow E.123). */ PHONE { @@ -77,7 +82,7 @@ public enum JsonValueFormat { public String toString() { return "phone"; } }, - /* + /** * This value SHOULD be a URI.. */ URI { @@ -85,14 +90,14 @@ public enum JsonValueFormat { public String toString() { return "uri"; } }, - /* + /** * This SHOULD be an email address. */ EMAIL { @Override public String toString() { return "email"; } }, - /* + /** * This SHOULD be an ip version 4 address. */ IP_ADDRESS { @@ -100,7 +105,7 @@ public enum JsonValueFormat { public String toString() { return "ip-address"; } }, - /* + /** * This SHOULD be an ip version 6 address. */ IPV6 { @@ -108,7 +113,7 @@ public enum JsonValueFormat { public String toString() { return "ipv6"; } }, - /* + /** * This SHOULD be a host-name. */ HOST_NAME { diff --git a/src/main/java/com/fasterxml/jackson/databind/jsonschema/types/NullSchema.java b/src/main/java/com/fasterxml/jackson/databind/jsonschema/types/NullSchema.java index dcf772ccd3..83c5acdad3 100644 --- a/src/main/java/com/fasterxml/jackson/databind/jsonschema/types/NullSchema.java +++ b/src/main/java/com/fasterxml/jackson/databind/jsonschema/types/NullSchema.java @@ -1,17 +1,29 @@ package com.fasterxml.jackson.databind.jsonschema.types; -import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.annotation.JsonIgnore; /** - * value must be null; + * This class represents a {@link JsonSchema} as a null type + * @author jphelan */ public class NullSchema extends SimpleTypeSchema { - @JsonProperty(required = true) + @JsonIgnore private final SchemaType type = SchemaType.NULL; + @Override + public NullSchema asNullSchema() { return this; } + + /* (non-Javadoc) + * @see com.fasterxml.jackson.databind.jsonschema.types.JsonSchema#equals(java.lang.Object) + */ + @Override + public boolean equals(Object obj) { + return (obj instanceof NullSchema && super.equals(obj)); + } + /* (non-Javadoc) - * @see com.fasterxml.jackson.databind.jsonschema.types.Schema#getType() + * @see com.fasterxml.jackson.databind.jsonschema.types.JsonSchema#getType() */ @Override public SchemaType getType() { @@ -21,6 +33,4 @@ public SchemaType getType() { @Override public boolean isNullSchema() { return true; } - @Override - public NullSchema asNullSchema() { return this; } } \ No newline at end of file diff --git a/src/main/java/com/fasterxml/jackson/databind/jsonschema/types/NumberSchema.java b/src/main/java/com/fasterxml/jackson/databind/jsonschema/types/NumberSchema.java index 0a27f43506..c1ff5aa002 100644 --- a/src/main/java/com/fasterxml/jackson/databind/jsonschema/types/NumberSchema.java +++ b/src/main/java/com/fasterxml/jackson/databind/jsonschema/types/NumberSchema.java @@ -1,7 +1,13 @@ package com.fasterxml.jackson.databind.jsonschema.types; +import com.fasterxml.jackson.annotation.JsonIgnore; import com.fasterxml.jackson.annotation.JsonProperty; +/** + * This class represents a {@link JsonSchema} as a number type + * @author jphelan + * + */ public class NumberSchema extends ValueTypeSchema { /** @@ -28,11 +34,34 @@ public class NumberSchema extends ValueTypeSchema { @JsonProperty private Double minimum = null; - @JsonProperty(required = true) + @JsonIgnore private final SchemaType type = SchemaType.NUMBER; @Override public NumberSchema asNumberSchema() { return this; } + + /* (non-Javadoc) + * @see com.fasterxml.jackson.databind.jsonschema.types.ValueTypeSchema#equals(java.lang.Object) + */ + @Override + public boolean equals(Object obj) { + if (obj instanceof NumberSchema) { + NumberSchema that = (NumberSchema)obj; + return getExclusiveMaximum() == null ? that.getExclusiveMaximum() == null : + getExclusiveMaximum().equals(that.getExclusiveMaximum()) && + getExclusiveMinimum() == null ? that.getExclusiveMinimum() == null : + getExclusiveMinimum().equals(that.getExclusiveMinimum()) && + getMaximum() == null ? that.getMaximum() == null : + getMaximum().equals(that.getMaximum()) && + getMinimum() == null ? that.getMinimum() == null : + getMinimum().equals(that.getMinimum()) && + super.equals(obj); + } else { + return false; + } + } + + /** * {@link NumberSchema#exclusiveMaximum} * @return the exclusiveMaximum @@ -64,7 +93,7 @@ public Double getMinimum() { } /* (non-Javadoc) - * @see com.fasterxml.jackson.databind.jsonschema.types.Schema#getType() + * @see com.fasterxml.jackson.databind.jsonschema.types.JsonSchema#getType() */ @Override public SchemaType getType() { diff --git a/src/main/java/com/fasterxml/jackson/databind/jsonschema/types/ObjectSchema.java b/src/main/java/com/fasterxml/jackson/databind/jsonschema/types/ObjectSchema.java index 6e75650e42..af65dc45fd 100644 --- a/src/main/java/com/fasterxml/jackson/databind/jsonschema/types/ObjectSchema.java +++ b/src/main/java/com/fasterxml/jackson/databind/jsonschema/types/ObjectSchema.java @@ -5,17 +5,24 @@ import java.util.List; import java.util.Map; +import com.fasterxml.jackson.annotation.JsonCreator; +import com.fasterxml.jackson.annotation.JsonIgnore; import com.fasterxml.jackson.annotation.JsonProperty; import com.fasterxml.jackson.annotation.JsonValue; +/** + * This type represents a {@link JsonSchema} as an object type + * @author jphelan + * + */ public class ObjectSchema extends ContainerTypeSchema { /** - * This attribute defines a schema for all properties that are not + * This attribute defines a jsonSchema for all properties that are not * explicitly defined in an object type definition. If specified, the value - * MUST be a schema or a boolean. If false is provided, no additional - * properties are allowed beyond the properties defined in the schema. The - * default value is an empty schema which allows any value for additional + * MUST be a jsonSchema or a boolean. If false is provided, no additional + * properties are allowed beyond the properties defined in the jsonSchema. The + * default value is an empty jsonSchema which allows any value for additional * properties. */ @JsonProperty @@ -32,41 +39,41 @@ public class ObjectSchema extends ContainerTypeSchema { /** * - This attribute is an object that defines the schema for a set of property + This attribute is an object that defines the jsonSchema for a set of property * names of an object instance. The name of each property of this * attribute's object is a regular expression pattern in the ECMA 262/Perl 5 - * format, while the value is a schema. If the pattern matches the name of a + * format, while the value is a jsonSchema. If the pattern matches the name of a * property on the instance object, the value of the instance's property - * MUST be valid against the pattern name's schema value. + * MUST be valid against the pattern name's jsonSchema value. */ @JsonProperty - private Map patternProperties; + private Map patternProperties; /** * This attribute is an object with property definitions that define the * valid values of instance object property values. When the instance value * is an object, the property values of the instance object MUST conform to * the property definitions in this object. In this object, each property - * definition's value MUST be a schema, and the property's name MUST be the + * definition's value MUST be a jsonSchema, and the property's name MUST be the * name of the instance property that it defines. The instance property - * value MUST be valid according to the schema from the property definition. + * value MUST be valid according to the jsonSchema from the property definition. * Properties are considered unordered, the order of the instance properties * MAY be in any order. */ @JsonProperty - private Map properties; + private Map properties; - @JsonProperty(required = true) + @JsonIgnore private final SchemaType type = SchemaType.OBJECT; // instance initializer block { dependencies = new ArrayList(); - patternProperties = new HashMap(); - properties = new HashMap(); + patternProperties = new HashMap(); + properties = new HashMap(); } - public boolean addSchemaDependency(String depender, Schema parentMustMatch) { + public boolean addSchemaDependency(String depender, JsonSchema parentMustMatch) { return dependencies .add(new SchemaDependency(depender, parentMustMatch)); } @@ -75,11 +82,36 @@ public boolean addSimpleDependency(String depender, String dependsOn) { return dependencies.add(new SimpleDependency(depender, dependsOn)); } + /* (non-Javadoc) + * @see com.fasterxml.jackson.databind.jsonschema.types.JsonSchema#asObjectSchema() + */ @Override public ObjectSchema asObjectSchema() { return this; } + /* (non-Javadoc) + * @see com.fasterxml.jackson.databind.jsonschema.types.JsonSchema#equals(java.lang.Object) + */ + @Override + public boolean equals(Object obj) { + if (obj instanceof ObjectSchema) { + ObjectSchema that = (ObjectSchema) obj; + return getAdditionalProperties() == null ? that.getAdditionalProperties() == null : + getAdditionalProperties().equals(that.getAdditionalProperties()) && + getDependencies() == null ? that.getDependencies() == null : + getDependencies().equals(that.getDependencies()) && + getPatternProperties() == null ? that.getPatternProperties() == null : + getPatternProperties().equals(that.getPatternProperties()) && + getProperties() == null ? that.getProperties() == null : + getProperties().equals(that.getProperties()) && + super.equals(obj); + } else { + return false; + } + + } + /** * {@link ObjectSchema#additionalProperties} * @@ -103,7 +135,7 @@ public List getDependencies() { * * @return the patternProperties */ - public Map getPatternProperties() { + public Map getPatternProperties() { return patternProperties; } @@ -112,32 +144,35 @@ public Map getPatternProperties() { * * @return the properties */ - public Map getProperties() { + public Map getProperties() { return properties; } /* (non-Javadoc) - * @see com.fasterxml.jackson.databind.jsonschema.types.Schema#getType() + * @see com.fasterxml.jackson.databind.jsonschema.types.JsonSchema#getType() */ @Override public SchemaType getType() { return type; } + /* (non-Javadoc) + * @see com.fasterxml.jackson.databind.jsonschema.types.JsonSchema#isObjectSchema() + */ @Override public boolean isObjectSchema() { return true; } - public void putOptionalProperty(String name, Schema schema) { - properties.put(name, schema); + public void putOptionalProperty(String name, JsonSchema jsonSchema) { + properties.put(name, jsonSchema); } - public Schema putPatternProperty(String regex, Schema value) { + public JsonSchema putPatternProperty(String regex, JsonSchema value) { return patternProperties.put(regex, value); } - public Schema putProperty(String name, Schema value) { + public JsonSchema putProperty(String name, JsonSchema value) { value.setRequired(true); return properties.put(name, value); } @@ -173,7 +208,7 @@ public void setDependencies(List dependencies) { * @param patternProperties * the patternProperties to set */ - public void setPatternProperties(Map patternProperties) { + public void setPatternProperties(Map patternProperties) { this.patternProperties = patternProperties; } @@ -183,14 +218,25 @@ public void setPatternProperties(Map patternProperties) { * @param properties * the properties to set */ - public void setProperties(Map properties) { + public void setProperties(Map properties) { this.properties = properties; } public static abstract class AdditionalProperties { + + @JsonCreator + public AdditionalProperties jsonCreator() { + //KNOWN ISSUE: pending https://github.com/FasterXML/jackson-databind/issues/43 + return null; + } } public static abstract class Dependency { + @JsonCreator + public Dependency jsonCreator() { + //KNOWN ISSUE: pending https://github.com/FasterXML/jackson-databind/issues/43 + return null; + } } public static class NoAdditionalProperties extends AdditionalProperties { @@ -198,6 +244,14 @@ public static class NoAdditionalProperties extends AdditionalProperties { protected NoAdditionalProperties() { } + + /* (non-Javadoc) + * @see java.lang.Object#equals(java.lang.Object) + */ + @Override + public boolean equals(Object obj) { + return obj instanceof NoAdditionalProperties; + } @JsonValue public Boolean value() { @@ -210,16 +264,34 @@ public Boolean value() { public static class SchemaAdditionalProperties extends AdditionalProperties { @JsonProperty - private Schema schema; - - public SchemaAdditionalProperties(Schema schema) { - this.schema = schema; + private JsonSchema jsonSchema; + + /* (non-Javadoc) + * @see java.lang.Object#equals(java.lang.Object) + */ + @Override + public boolean equals(Object obj) { + return obj instanceof SchemaAdditionalProperties && + getJsonSchema() == null ? ((SchemaAdditionalProperties)obj).getJsonSchema() == null : + getJsonSchema().equals(((SchemaAdditionalProperties)obj).getJsonSchema()); + } + + /** + * {@link ObjectSchema.SchemaAdditionalProperties#jsonSchema} + * @return the jsonSchema + */ + public JsonSchema getJsonSchema() { + return jsonSchema; + } + + public SchemaAdditionalProperties(JsonSchema jsonSchema) { + this.jsonSchema = jsonSchema; } } /** - * Schema Dependency If the dependency value is a schema, then the instance - * object MUST be valid against the schema. + * JsonSchema Dependency If the dependency value is a jsonSchema, then the instance + * object MUST be valid against the jsonSchema. */ public static class SchemaDependency extends Dependency { @@ -227,12 +299,44 @@ public static class SchemaDependency extends Dependency { private String depender; @JsonProperty(required = true) - private Schema parentMustMatch; + private JsonSchema parentMustMatch; - public SchemaDependency(String depender, Schema parentMustMatch) { + public SchemaDependency(String depender, JsonSchema parentMustMatch) { this.depender = depender; this.parentMustMatch = parentMustMatch; } + + /* (non-Javadoc) + * @see java.lang.Object#equals(java.lang.Object) + */ + @Override + public boolean equals(Object obj) { + if (obj instanceof SchemaDependency) { + SchemaDependency that = (SchemaDependency) obj; + return getDepender() == null ? that.getDepender() == null : + getDepender().equals(that.getDepender()) && + getParentMustMatch() == null ? that.getParentMustMatch() == null : + getParentMustMatch().equals(that.getParentMustMatch()); + } else { + return false; + } + } + + /** + * {@link ObjectSchema.SchemaDependency#depender} + * @return the depender + */ + public String getDepender() { + return depender; + } + + /** + * {@link ObjectSchema.SchemaDependency#parentMustMatch} + * @return the parentMustMatch + */ + public JsonSchema getParentMustMatch() { + return parentMustMatch; + } } /** @@ -254,6 +358,38 @@ public SimpleDependency(String depender, String dependsOn) { this.depender = depender; this.dependsOn = dependsOn; } + + /* (non-Javadoc) + * @see java.lang.Object#equals(java.lang.Object) + */ + @Override + public boolean equals(Object obj) { + if (obj instanceof SchemaDependency) { + SimpleDependency that = (SimpleDependency) obj; + return getDepender() == null ? that.getDepender() == null : + getDepender().equals(that.getDepender()) && + getDependsOn() == null ? that.getDependsOn() == null : + getDependsOn().equals(that.getDependsOn()); + } else { + return false; + } + } + + /** + * {@link ObjectSchema.SimpleDependency#depender} + * @return the depender + */ + public String getDepender() { + return depender; + } + + /** + * {@link ObjectSchema.SimpleDependency#dependsOn} + * @return the dependsOn + */ + public String getDependsOn() { + return dependsOn; + } } } \ No newline at end of file diff --git a/src/main/java/com/fasterxml/jackson/databind/jsonschema/types/Schema.java b/src/main/java/com/fasterxml/jackson/databind/jsonschema/types/Schema.java deleted file mode 100644 index 12ceded5e2..0000000000 --- a/src/main/java/com/fasterxml/jackson/databind/jsonschema/types/Schema.java +++ /dev/null @@ -1,395 +0,0 @@ -package com.fasterxml.jackson.databind.jsonschema.types; - -import com.fasterxml.jackson.annotation.JsonGetter; -import com.fasterxml.jackson.annotation.JsonIgnore; -import com.fasterxml.jackson.annotation.JsonInclude; -import com.fasterxml.jackson.annotation.JsonInclude.Include; -import com.fasterxml.jackson.annotation.JsonProperty; -import com.fasterxml.jackson.annotation.JsonSetter; -import com.fasterxml.jackson.databind.annotation.JsonSerialize; - -/** - * Json Schema - * Draft
JSON (JavaScript Object Notation) Schema defines the - * media type "application/schema+json", a JSON based format for defining the - * structure of JSON data. JSON Schema provides a contract for what JSON data is - * required for a given application and how to interact with it. JSON Schema is - * intended to define validation, documentation, hyperlink navigation, and - * interaction control of JSON data.
- * - *
JSON (JavaScript Object Notation) Schema is a JSON media type - * for defining the structure of JSON data. JSON Schema provides a contract for - * what JSON data is required for a given application and how to interact with - * it. JSON Schema is intended to define validation, documentation, hyperlink - * navigation, and interaction control of JSON data.
- * - * An example JSON Schema provided by the Schema draft: - * - *
- * 	{
- * 	  "name":"Product",
- * 	  "properties":{
- * 	    "id":{
- * 	      "type":"number",
- * 	      "description":"Product identifier",
- * 	      "required":true
- * 	    },
- * 	    "name":{
- * 	      "description":"Name of the product",
- * 	      "type":"string",
- * 	      "required":true
- * 	    },
- * 	    "price":{
- * 	      "required":true,
- * 	      "type": "number",
- * 	      "minimum":0,
- * 	      "required":true
- * 	    },
- * 	    "tags":{
- * 	      "type":"array",
- * 	      "items":{
- * 	        "type":"string"
- * 	      }
- * 	    }
- * 	  },
- * 	  "links":[
- * 	    {
- * 	      "rel":"full",
- * 	      "href":"{id}"
- * 	    },
- * 	    {
- * 	      "rel":"comments",
- * 	      "href":"comments/?id={id}"
- * 	    }
- * 	  ]
- * 	}
- * 
- * - * @author jphelan - */ -@JsonInclude(Include.NON_EMPTY) -public abstract class Schema { - - /** - * This attribute defines a URI of a schema that contains the full - * representation of this schema. When a validator encounters this - * attribute, it SHOULD replace the current schema with the schema - * referenced by the value's URI (if known and available) and re- validate - * the instance. This URI MAY be relative or absolute, and relative URIs - * SHOULD be resolved against the URI of the current schema. - */ - @JsonProperty - private String $ref; - - /** - * This attribute defines a URI of a JSON Schema that is the schema of the - * current schema. When this attribute is defined, a validator SHOULD use - * the schema referenced by the value's URI (if known and available) when - * resolving Hyper Schema (Section 6) links (Section 6.1). - * - * A validator MAY use this attribute's value to determine which version of - * JSON Schema the current schema is written in, and provide the appropriate - * validation features and behavior. Therefore, it is RECOMMENDED that all - * schema authors include this attribute in their schemas to prevent - * conflicts with future JSON Schema specification changes. - */ - @JsonProperty - private String $schema; - - /** - * This attribute takes the same values as the "type" attribute, however if - * the instance matches the type or if this value is an array and the - * instance matches any type or schema in the array, then this instance is - * not valid. - */ - @JsonProperty - private Schema[] disallow; - /** - * The value of this property MUST be another schema which will provide a - * base schema which the current schema will inherit from. The inheritance - * rules are such that any instance that is valid according to the current - * schema MUST be valid according to the referenced schema. This MAY also be - * an array, in which case, the instance MUST be valid for all the schemas - * in the array. A schema that extends another schema MAY define additional - * attributes, constrain existing attributes, or add other constraints. - * - * Conceptually, the behavior of extends can be seen as validating an - * instance against all constraints in the extending schema as well as the - * extended schema(s). More optimized implementations that merge schemas are - * possible, but are not required. An example of using "extends": - * - * { "description":"An adult", "properties":{"age":{"minimum": 21}}, - * "extends":"person" } { "description":"Extended schema", - * "properties":{"deprecated":{"type": "boolean"}}, - * "extends":"http://json-schema.org/draft-03/schema" } - */ - @JsonIgnore - private Schema[] extendsextends; - /** - * This attribute defines the current URI of this schema (this attribute is - * effectively a "self" link). This URI MAY be relative or absolute. If the - * URI is relative it is resolved against the current URI of the parent - * schema it is contained in. If this schema is not contained in any parent - * schema, the current URI of the parent schema is held to be the URI under - * which this schema was addressed. If id is missing, the current URI of a - * schema is defined to be that of the parent schema. The current URI of the - * schema is also used to construct relative references such as for $ref. - */ - @JsonProperty - private String id; - /** - * This attribute indicates if the instance must have a value, and not be - * undefined. This is false by default, making the instance optional. - */ - @JsonProperty - private Boolean required = null; - - public AnySchema asAnySchema() { - return null; - } - - public ArraySchema asArraySchema() { - return null; - } - - public BooleanSchema asBooleanSchema() { - return null; - } - - public ContainerTypeSchema asContainerSchema() { - return null; - } - - public IntegerSchema asIntegerSchema() { - return null; - } - - public NullSchema asNullSchema() { - return null; - } - - public NumberSchema asNumberSchema() { - return null; - } - - public ObjectSchema asObjectSchema() { - return null; - } - - public SimpleTypeSchema asSimpleTypeSchema() { - return null; - } - - public StringSchema asStringSchema() { - return null; - } - - public UnionTypeSchema asUnionTypeSchema() { - return null; - } - - public ValueTypeSchema asValueSchemaSchema() { - return null; - } - - /** - * {@link Schema#$ref} - * - * @return the $ref - */ - public String get$ref() { - return $ref; - } - - /** - * {@link Schema#$schema} - * - * @return the $schema - */ - public String get$schema() { - return $schema; - } - - /** - * {@link Schema#disallow} - * - * @return the disallow - */ - public Schema[] getDisallow() { - return disallow; - } - - /** - * {@link Schema#extendsextends} - * - * @return the extendsextends - */ - @JsonGetter("extends") - public Schema[] getExtends() { - return extendsextends; - } - - /** - * {@link Schema#id} - * - * @return the id - */ - public String getId() { - return id; - } - - /** - * {@link Schema#required} - * - * @return the required - */ - public Boolean getRequired() { - return required; - } - - public abstract SchemaType getType(); - - @JsonIgnore - public boolean isAnySchema() { - return false; - } - - @JsonIgnore - public boolean isArraySchema() { - return false; - } - - @JsonIgnore - public boolean isBooleanSchema() { - return false; - } - - @JsonIgnore - public boolean isContainerTypeSchema() { - return false; - } - - @JsonIgnore - public boolean isIntegerSchema() { - return false; - } - - @JsonIgnore - public boolean isNullSchema() { - return false; - } - - @JsonIgnore - public boolean isNumberSchema() { - return false; - } - - @JsonIgnore - public boolean isObjectSchema() { - return false; - } - - @JsonIgnore - public boolean isSimpleTypeSchema() { - return false; - } - - @JsonIgnore - public boolean isStringSchema() { - return false; - } - - @JsonIgnore - public boolean isUnionTypeSchema() { - return false; - } - - @JsonIgnore - public boolean isValueTypeSchema() { - return false; - } - - /** - * {@link Schema#$ref} - * - * @param $ref - * the $ref to set - */ - public void set$ref(String $ref) { - this.$ref = $ref; - } - - /** - * {@link Schema#$schema} - * - * @param $schema - * the $schema to set - */ - public void set$schema(String $schema) { - this.$schema = $schema; - } - - /** - * {@link Schema#disallow} - * - * @param disallow - * the disallow to set - */ - public void setDisallow(Schema[] disallow) { - this.disallow = disallow; - } - - /** - * {@link Schema#extendsextends} - * - * @param extendsextends - * the extendsextends to set - */ - @JsonSetter("extends") - public void setExtends(Schema[] extendsextends) { - this.extendsextends = extendsextends; - } - - /** - * {@link Schema#id} - * - * @param id - * the id to set - */ - public void setId(String id) { - this.id = id; - } - - /** - * {@link Schema#required} - * - * @param required - * the required to set - */ - public void setRequired(Boolean required) { - this.required = required; - } - - public static Schema minimalForFormat(SchemaType format) { - switch (format) { - case ARRAY: - return new ArraySchema(); - case OBJECT: - return new ObjectSchema(); - case BOOLEAN: - return new BooleanSchema(); - case INTEGER: - return new IntegerSchema(); - case NUMBER: - return new NumberSchema(); - case STRING: - return new StringSchema(); - case NULL: - return new NullSchema(); - - default: - return new AnySchema(); - } - } - -} \ No newline at end of file diff --git a/src/main/java/com/fasterxml/jackson/databind/jsonschema/types/SimpleTypeSchema.java b/src/main/java/com/fasterxml/jackson/databind/jsonschema/types/SimpleTypeSchema.java index 80190efcab..3c8a0db0ac 100644 --- a/src/main/java/com/fasterxml/jackson/databind/jsonschema/types/SimpleTypeSchema.java +++ b/src/main/java/com/fasterxml/jackson/databind/jsonschema/types/SimpleTypeSchema.java @@ -5,7 +5,12 @@ import com.fasterxml.jackson.annotation.JsonProperty; import com.fasterxml.jackson.annotation.JsonSetter; -public abstract class SimpleTypeSchema extends Schema { +/** + * This class encapsulates the functionality of {@link JsonSchema} simple types + * @author jphelan + * + */ +public abstract class SimpleTypeSchema extends JsonSchema { /** * This attribute defines the default value of the instance when the @@ -26,11 +31,34 @@ public abstract class SimpleTypeSchema extends Schema { @JsonProperty private String title; + /* (non-Javadoc) + * @see com.fasterxml.jackson.databind.jsonschema.types.JsonSchema#asSimpleTypeSchema() + */ @Override public SimpleTypeSchema asSimpleTypeSchema() { return this; } + /* (non-Javadoc) + * @see com.fasterxml.jackson.databind.jsonschema.types.JsonSchema#equals(java.lang.Object) + */ + @Override + public boolean equals(Object obj) { + if (obj instanceof SimpleTypeSchema) { + SimpleTypeSchema that = (SimpleTypeSchema)obj; + return getDefault() == null ? that.getDefault() == null : + getDefault().equals(that.getDefault()) && + getDescription() == null ? that.getDescription() == null : + getDescription().equals(that.getDescription()) && + getTitle() == null ? that.getTitle() == null : + getTitle().equals(that.getTitle()) && + super.equals(obj); + } else { + return false; + } + } + + /** * {@link SimpleTypeSchema#defaultdefault} * @@ -59,6 +87,9 @@ public String getTitle() { return title; } + /* (non-Javadoc) + * @see com.fasterxml.jackson.databind.jsonschema.types.JsonSchema#isSimpleTypeSchema() + */ @Override public boolean isSimpleTypeSchema() { return true; diff --git a/src/main/java/com/fasterxml/jackson/databind/jsonschema/types/StringSchema.java b/src/main/java/com/fasterxml/jackson/databind/jsonschema/types/StringSchema.java index 87bee09a49..f17dc25a09 100644 --- a/src/main/java/com/fasterxml/jackson/databind/jsonschema/types/StringSchema.java +++ b/src/main/java/com/fasterxml/jackson/databind/jsonschema/types/StringSchema.java @@ -1,7 +1,13 @@ package com.fasterxml.jackson.databind.jsonschema.types; +import com.fasterxml.jackson.annotation.JsonIgnore; import com.fasterxml.jackson.annotation.JsonProperty; +/** + * This represents a {@link JsonSchema} as a String + * @author jphelan + * + */ public class StringSchema extends ValueTypeSchema { /** this defines the maximum length of the string. */ @@ -19,13 +25,36 @@ public class StringSchema extends ValueTypeSchema { @JsonProperty private String pattern; - @JsonProperty(required = true) + @JsonIgnore private final SchemaType type = SchemaType.STRING; + /* (non-Javadoc) + * @see com.fasterxml.jackson.databind.jsonschema.types.JsonSchema#asStringSchema() + */ @Override public StringSchema asStringSchema() { return this; } + + /* (non-Javadoc) + * @see com.fasterxml.jackson.databind.jsonschema.types.ValueTypeSchema#equals(java.lang.Object) + */ + @Override + public boolean equals(Object obj) { + if (obj instanceof StringSchema) { + StringSchema that = (StringSchema)obj; + return getMaxLength() == null ? that.getMaxLength() == null : + getMaxLength().equals(that.getMaxLength()) && + getMinLength() == null ? that.getMinLength() == null : + getMinLength().equals(that.getMinLength()) && + getPattern() == null ? that.getPattern() == null : + getPattern().equals(that.getPattern()) && + super.equals(obj); + } else { + return false; + } + } + /** * {@link StringSchema#maxLength} @@ -55,13 +84,16 @@ public String getPattern() { } /* (non-Javadoc) - * @see com.fasterxml.jackson.databind.jsonschema.types.Schema#getType() + * @see com.fasterxml.jackson.databind.jsonschema.types.JsonSchema#getType() */ @Override public SchemaType getType() { return type; } + /* (non-Javadoc) + * @see com.fasterxml.jackson.databind.jsonschema.types.JsonSchema#isStringSchema() + */ @Override public boolean isStringSchema() { return true; diff --git a/src/main/java/com/fasterxml/jackson/databind/jsonschema/types/UnionTypeSchema.java b/src/main/java/com/fasterxml/jackson/databind/jsonschema/types/UnionTypeSchema.java index 4fb78ae55c..9f9d4ef751 100644 --- a/src/main/java/com/fasterxml/jackson/databind/jsonschema/types/UnionTypeSchema.java +++ b/src/main/java/com/fasterxml/jackson/databind/jsonschema/types/UnionTypeSchema.java @@ -2,7 +2,18 @@ import com.fasterxml.jackson.annotation.JsonProperty; -public class UnionTypeSchema extends Schema { +/** + * This class represents a {@link JsonSchema} as a Union Type Schema: + * "An array of two or more simple type definitions. Each + item in the array MUST be a simple type definition or a schema. + The instance value is valid if it is of the same type as one of + the simple type definitions, or valid by one of the schemas, in + the array." + + * @author jphelan + * + */ +public class UnionTypeSchema extends JsonSchema { @JsonProperty private ValueTypeSchema[] elements; @@ -12,6 +23,21 @@ public UnionTypeSchema asUnionTypeSchema() { return this; } + /* (non-Javadoc) + * @see com.fasterxml.jackson.databind.jsonschema.types.JsonSchema#equals(java.lang.Object) + */ + @Override + public boolean equals(Object obj) { + if (obj instanceof UnionTypeSchema) { + UnionTypeSchema that = (UnionTypeSchema) obj; + return getElements() == null ? that.getElements() == null : + getElements().equals(that.getElements()) && + super.equals(obj); + } else { + return false; + } + } + /** * {@link UnionTypeSchema#elements} * @@ -22,7 +48,7 @@ public ValueTypeSchema[] getElements() { } /* (non-Javadoc) - * @see com.fasterxml.jackson.databind.jsonschema.types.Schema#getType() + * @see com.fasterxml.jackson.databind.jsonschema.types.JsonSchema#getType() */ @Override public SchemaType getType() { diff --git a/src/main/java/com/fasterxml/jackson/databind/jsonschema/types/ValueTypeSchema.java b/src/main/java/com/fasterxml/jackson/databind/jsonschema/types/ValueTypeSchema.java index 9a41ea72f6..0358b10c55 100644 --- a/src/main/java/com/fasterxml/jackson/databind/jsonschema/types/ValueTypeSchema.java +++ b/src/main/java/com/fasterxml/jackson/databind/jsonschema/types/ValueTypeSchema.java @@ -6,8 +6,9 @@ import com.fasterxml.jackson.annotation.JsonProperty; /** -* A primitive type. -*/ + * This class represents a {@link JsonSchema} + * A primitive type. + */ public abstract class ValueTypeSchema extends SimpleTypeSchema { /** @@ -42,9 +43,27 @@ of enum values uses the same algorithm as defined in "uniqueItems" enums = new HashSet(); } + /* (non-Javadoc) + * @see com.fasterxml.jackson.databind.jsonschema.types.JsonSchema#asValueSchemaSchema() + */ @Override public ValueTypeSchema asValueSchemaSchema() { return this; } + /* (non-Javadoc) + * @see com.fasterxml.jackson.databind.jsonschema.types.JsonSchema#equals(java.lang.Object) + */ + @Override + public boolean equals(Object obj) { + if (obj instanceof ValueTypeSchema) { + ValueTypeSchema that = (ValueTypeSchema) obj; + return getEnums() == null ? that.getEnums() == null : + getEnums().equals(that.getEnums()) && + getFormat() == null ? that.getFormat() == null : + getFormat().equals(that.getFormat()) && + super.equals(obj); + } + return false; + } /** * {@link ValueTypeSchema#enums} @@ -60,6 +79,10 @@ public Set getEnums() { public JsonValueFormat getFormat() { return format; } + + /* (non-Javadoc) + * @see com.fasterxml.jackson.databind.jsonschema.types.JsonSchema#isValueTypeSchema() + */ @Override public boolean isValueTypeSchema() { return true; } diff --git a/src/main/java/com/fasterxml/jackson/databind/jsonschema/visitors/JsonArrayFormatVisitor.java b/src/main/java/com/fasterxml/jackson/databind/jsonschema/visitors/JsonArrayFormatVisitor.java index 6331a6d57d..fa0cc3d6d5 100644 --- a/src/main/java/com/fasterxml/jackson/databind/jsonschema/visitors/JsonArrayFormatVisitor.java +++ b/src/main/java/com/fasterxml/jackson/databind/jsonschema/visitors/JsonArrayFormatVisitor.java @@ -1,7 +1,7 @@ package com.fasterxml.jackson.databind.jsonschema.visitors; import com.fasterxml.jackson.databind.JavaType; -import com.fasterxml.jackson.databind.jsonschema.SchemaAware; +import com.fasterxml.jackson.databind.jsonschema.JsonFormatVisitorAware; import com.fasterxml.jackson.databind.jsonschema.types.SchemaType; public interface JsonArrayFormatVisitor { @@ -10,6 +10,6 @@ public interface JsonArrayFormatVisitor { void itemsFormat(SchemaType format); - void itemsFormat(SchemaAware toVisit); + void itemsFormat(JsonFormatVisitorAware toVisit); } diff --git a/src/main/java/com/fasterxml/jackson/databind/jsonschema/visitors/JsonObjectFormatVisitor.java b/src/main/java/com/fasterxml/jackson/databind/jsonschema/visitors/JsonObjectFormatVisitor.java index 679da671e2..81965497f0 100644 --- a/src/main/java/com/fasterxml/jackson/databind/jsonschema/visitors/JsonObjectFormatVisitor.java +++ b/src/main/java/com/fasterxml/jackson/databind/jsonschema/visitors/JsonObjectFormatVisitor.java @@ -2,7 +2,7 @@ import com.fasterxml.jackson.databind.JavaType; -import com.fasterxml.jackson.databind.jsonschema.SchemaAware; +import com.fasterxml.jackson.databind.jsonschema.JsonFormatVisitorAware; import com.fasterxml.jackson.databind.ser.BeanPropertyWriter; public interface JsonObjectFormatVisitor extends JsonFormatVisitor { @@ -11,9 +11,9 @@ public interface JsonObjectFormatVisitor extends JsonFormatVisitor { public void optionalProperty(BeanPropertyWriter writer); - public void property(String name, SchemaAware handler, JavaType propertyTypeHint); + public void property(String name, JsonFormatVisitorAware handler, JavaType propertyTypeHint); - public void optionalProperty(String name, SchemaAware handler, + public void optionalProperty(String name, JsonFormatVisitorAware handler, JavaType propertyTypeHint); public void property(String name); diff --git a/src/main/java/com/fasterxml/jackson/databind/ser/DefaultSerializerProvider.java b/src/main/java/com/fasterxml/jackson/databind/ser/DefaultSerializerProvider.java index 88f7e9debb..985e8b0574 100644 --- a/src/main/java/com/fasterxml/jackson/databind/ser/DefaultSerializerProvider.java +++ b/src/main/java/com/fasterxml/jackson/databind/ser/DefaultSerializerProvider.java @@ -13,7 +13,7 @@ import com.fasterxml.jackson.databind.cfg.HandlerInstantiator; import com.fasterxml.jackson.databind.introspect.Annotated; import com.fasterxml.jackson.databind.introspect.ObjectIdInfo; -import com.fasterxml.jackson.databind.jsonschema.SchemaAware; +import com.fasterxml.jackson.databind.jsonschema.JsonFormatVisitorAware; import com.fasterxml.jackson.databind.jsonschema.visitors.JsonFormatVisitor; import com.fasterxml.jackson.databind.ser.impl.WritableObjectId; import com.fasterxml.jackson.databind.util.ClassUtil; @@ -246,8 +246,8 @@ public void acceptJsonFormatVisitor(Class type, JsonFormatVisitor visitor) * type information it needs is accessible via "untyped" serializer) */ JsonSerializer ser = findValueSerializer(type, null); - if (ser instanceof SchemaAware) { - ((SchemaAware) ser).acceptJsonFormatVisitor(visitor, constructType(type)); + if (ser instanceof JsonFormatVisitorAware) { + ((JsonFormatVisitorAware) ser).acceptJsonFormatVisitor(visitor, constructType(type)); } else { visitor.anyFormat(); } diff --git a/src/main/java/com/fasterxml/jackson/databind/ser/impl/SimpleBeanPropertyFilter.java b/src/main/java/com/fasterxml/jackson/databind/ser/impl/SimpleBeanPropertyFilter.java index 9b0d186e63..d516e3214e 100644 --- a/src/main/java/com/fasterxml/jackson/databind/ser/impl/SimpleBeanPropertyFilter.java +++ b/src/main/java/com/fasterxml/jackson/databind/ser/impl/SimpleBeanPropertyFilter.java @@ -1,15 +1,11 @@ package com.fasterxml.jackson.databind.ser.impl; -import java.lang.reflect.Type; import java.util.*; import com.fasterxml.jackson.core.JsonGenerator; import com.fasterxml.jackson.databind.*; -import com.fasterxml.jackson.databind.jsonschema.JsonSchema; -import com.fasterxml.jackson.databind.jsonschema.SchemaAware; import com.fasterxml.jackson.databind.jsonschema.visitors.JsonObjectFormatVisitor; -import com.fasterxml.jackson.databind.node.ObjectNode; import com.fasterxml.jackson.databind.ser.BeanPropertyFilter; import com.fasterxml.jackson.databind.ser.BeanPropertyWriter; import com.fasterxml.jackson.databind.ser.std.BeanSerializerBase; diff --git a/src/main/java/com/fasterxml/jackson/databind/ser/std/BeanSerializerBase.java b/src/main/java/com/fasterxml/jackson/databind/ser/std/BeanSerializerBase.java index debded7843..677867d248 100644 --- a/src/main/java/com/fasterxml/jackson/databind/ser/std/BeanSerializerBase.java +++ b/src/main/java/com/fasterxml/jackson/databind/ser/std/BeanSerializerBase.java @@ -13,8 +13,7 @@ import com.fasterxml.jackson.databind.introspect.Annotated; import com.fasterxml.jackson.databind.introspect.AnnotatedMember; import com.fasterxml.jackson.databind.introspect.ObjectIdInfo; -import com.fasterxml.jackson.databind.jsonschema.JsonSerializableSchema; -import com.fasterxml.jackson.databind.jsonschema.SchemaAware; +import com.fasterxml.jackson.databind.jsonschema.JsonFormatVisitorAware; import com.fasterxml.jackson.databind.jsonschema.visitors.JsonFormatVisitor; import com.fasterxml.jackson.databind.jsonschema.visitors.JsonObjectFormatVisitor; import com.fasterxml.jackson.databind.jsontype.TypeSerializer; @@ -36,7 +35,7 @@ public abstract class BeanSerializerBase extends StdSerializer implements ContextualSerializer, ResolvableSerializer, - SchemaAware + JsonFormatVisitorAware { final protected static BeanPropertyWriter[] NO_PROPS = new BeanPropertyWriter[0]; @@ -629,16 +628,6 @@ protected BeanPropertyFilter findFilter(SerializerProvider provider) public void acceptJsonFormatVisitor(JsonFormatVisitor visitor, JavaType typeHint) { JsonObjectFormatVisitor objectVisitor = visitor.objectFormat(typeHint); - // [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); - if (ann != null) { - String id = ann.id(); - if (id != null && id.length() > 0) { - //o.put("id", id); what is this? - //objectVisitor.expect?? - } - } BeanPropertyFilter filter; if (_propertyFilterId != null) { diff --git a/src/main/java/com/fasterxml/jackson/databind/ser/std/EnumMapSerializer.java b/src/main/java/com/fasterxml/jackson/databind/ser/std/EnumMapSerializer.java index d5c36555c8..59431819c7 100644 --- a/src/main/java/com/fasterxml/jackson/databind/ser/std/EnumMapSerializer.java +++ b/src/main/java/com/fasterxml/jackson/databind/ser/std/EnumMapSerializer.java @@ -10,8 +10,7 @@ import com.fasterxml.jackson.databind.*; import com.fasterxml.jackson.databind.annotation.JacksonStdImpl; -import com.fasterxml.jackson.databind.jsonschema.JsonSchema; -import com.fasterxml.jackson.databind.jsonschema.SchemaAware; +import com.fasterxml.jackson.databind.jsonschema.JsonFormatVisitorAware; import com.fasterxml.jackson.databind.jsonschema.visitors.JsonFormatVisitor; import com.fasterxml.jackson.databind.jsonschema.visitors.JsonObjectFormatVisitor; import com.fasterxml.jackson.databind.jsontype.TypeSerializer; @@ -267,8 +266,8 @@ public void acceptJsonFormatVisitor(JsonFormatVisitor visitor, JavaType typeHint String name = visitor.getProvider().getConfig().getAnnotationIntrospector().findEnumValue((Enum)enumValue); try { ser = visitor.getProvider().findValueSerializer(valueType.getRawClass(), _property); - if (ser instanceof SchemaAware) { - objectVisitor.property(name, (SchemaAware) ser, valueType); + if (ser instanceof JsonFormatVisitorAware) { + objectVisitor.property(name, (JsonFormatVisitorAware) ser, valueType); } continue; } catch (JsonMappingException e) { diff --git a/src/main/java/com/fasterxml/jackson/databind/ser/std/JsonValueSerializer.java b/src/main/java/com/fasterxml/jackson/databind/ser/std/JsonValueSerializer.java index 797d3bb486..39337096d8 100644 --- a/src/main/java/com/fasterxml/jackson/databind/ser/std/JsonValueSerializer.java +++ b/src/main/java/com/fasterxml/jackson/databind/ser/std/JsonValueSerializer.java @@ -9,8 +9,7 @@ import com.fasterxml.jackson.databind.*; import com.fasterxml.jackson.databind.annotation.JacksonStdImpl; -import com.fasterxml.jackson.databind.jsonschema.JsonSchema; -import com.fasterxml.jackson.databind.jsonschema.SchemaAware; +import com.fasterxml.jackson.databind.jsonschema.JsonFormatVisitorAware; import com.fasterxml.jackson.databind.jsonschema.visitors.JsonFormatVisitor; import com.fasterxml.jackson.databind.jsontype.TypeSerializer; import com.fasterxml.jackson.databind.ser.BeanSerializer; @@ -31,7 +30,7 @@ @JacksonStdImpl public class JsonValueSerializer extends StdSerializer - implements ContextualSerializer, SchemaAware + implements ContextualSerializer, JsonFormatVisitorAware { protected final Method _accessorMethod; @@ -232,8 +231,8 @@ public void serializeWithType(Object bean, JsonGenerator jgen, SerializerProvide @Override public void acceptJsonFormatVisitor(JsonFormatVisitor visitor, JavaType typeHint) { - if (_valueSerializer instanceof SchemaAware) { - ((SchemaAware) _valueSerializer).acceptJsonFormatVisitor(visitor, null); + if (_valueSerializer instanceof JsonFormatVisitorAware) { + ((JsonFormatVisitorAware) _valueSerializer).acceptJsonFormatVisitor(visitor, null); } else { visitor.anyFormat(); } diff --git a/src/main/java/com/fasterxml/jackson/databind/ser/std/ObjectArraySerializer.java b/src/main/java/com/fasterxml/jackson/databind/ser/std/ObjectArraySerializer.java index 275a402aaa..9e4e0bd3d8 100644 --- a/src/main/java/com/fasterxml/jackson/databind/ser/std/ObjectArraySerializer.java +++ b/src/main/java/com/fasterxml/jackson/databind/ser/std/ObjectArraySerializer.java @@ -7,16 +7,11 @@ import com.fasterxml.jackson.databind.*; import com.fasterxml.jackson.databind.annotation.JacksonStdImpl; -import com.fasterxml.jackson.databind.jsonschema.JsonSchema; -import com.fasterxml.jackson.databind.jsonschema.SchemaAware; -import com.fasterxml.jackson.databind.jsonschema.visitors.JsonArrayFormatVisitor; import com.fasterxml.jackson.databind.jsonschema.visitors.JsonFormatVisitor; import com.fasterxml.jackson.databind.jsontype.TypeSerializer; -import com.fasterxml.jackson.databind.node.ObjectNode; import com.fasterxml.jackson.databind.ser.ContainerSerializer; import com.fasterxml.jackson.databind.ser.ContextualSerializer; import com.fasterxml.jackson.databind.ser.impl.PropertySerializerMap; -import com.fasterxml.jackson.databind.type.ArrayType; /** * Generic serializer for Object arrays (Object[]). diff --git a/src/main/java/com/fasterxml/jackson/databind/ser/std/SerializableSerializer.java b/src/main/java/com/fasterxml/jackson/databind/ser/std/SerializableSerializer.java index da24334f37..2c42d6c142 100644 --- a/src/main/java/com/fasterxml/jackson/databind/ser/std/SerializableSerializer.java +++ b/src/main/java/com/fasterxml/jackson/databind/ser/std/SerializableSerializer.java @@ -7,20 +7,12 @@ import com.fasterxml.jackson.databind.JavaType; -import com.fasterxml.jackson.databind.JsonMappingException; -import com.fasterxml.jackson.databind.JsonNode; import com.fasterxml.jackson.databind.JsonSerializable; import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.databind.SerializerProvider; import com.fasterxml.jackson.databind.annotation.JacksonStdImpl; -import com.fasterxml.jackson.databind.jsonschema.JsonSerializableSchema; -import com.fasterxml.jackson.databind.jsonschema.types.Schema; -import com.fasterxml.jackson.databind.jsonschema.types.SchemaType; import com.fasterxml.jackson.databind.jsonschema.visitors.JsonFormatVisitor; -import com.fasterxml.jackson.databind.jsonschema.visitors.JsonObjectFormatVisitor; import com.fasterxml.jackson.databind.jsontype.TypeSerializer; -import com.fasterxml.jackson.databind.node.ObjectNode; -import com.fasterxml.jackson.databind.type.TypeFactory; /** * Generic handler for types that implement {@link JsonSerializable}. @@ -57,56 +49,6 @@ public final void serializeWithType(JsonSerializable value, JsonGenerator jgen, @Override public void acceptJsonFormatVisitor(JsonFormatVisitor visitor, JavaType typeHint) { - if (typeHint == null) { - visitor.anyFormat(); - } else { - Class rawClass = typeHint.getRawClass(); - if (rawClass.isAnnotationPresent(JsonSerializableSchema.class)) { - JsonSerializableSchema schemaInfo = rawClass.getAnnotation(JsonSerializableSchema.class); - - if (!JsonSerializableSchema.NO_VALUE.equals(schemaInfo.schemaObjectPropertiesDefinition())) { - visitor.objectFormat(typeHint); - //objectProperties = schemaInfo.schemaObjectPropertiesDefinition(); - } else - if (!JsonSerializableSchema.NO_VALUE.equals(schemaInfo.schemaItemDefinition())) { - visitor.arrayFormat(typeHint); - //itemDefinition = schemaInfo.schemaItemDefinition(); - } else { - visitor.anyFormat(); - //visitor.forFormat(SchemaType.valueOf(schemaInfo.schemaType())); - } - } else { - visitor.anyFormat(); - } - } - /* 19-Mar-2012, tatu: geez, this is butt-ugly abonimation of code... - * really, really should not require back ref to an ObjectMapper. - */ -// objectNode.put("type", schemaType); -// if (objectProperties != null) { -// try { -// objectNode.put("properties", _getObjectMapper().readTree(objectProperties)); -// } catch (IOException e) { -// throw new JsonMappingException("Failed to parse @JsonSerializableSchema.schemaObjectPropertiesDefinition value"); -// } -// } -// if (itemDefinition != null) { -// try { -// objectNode.put("items", _getObjectMapper().readTree(itemDefinition)); -// } catch (IOException e) { -// throw new JsonMappingException("Failed to parse @JsonSerializableSchema.schemaItemDefinition value"); -// } -// } - + visitor.anyFormat(); } - - private final static synchronized ObjectMapper _getObjectMapper() - { - ObjectMapper mapper = _mapperReference.get(); - if (mapper == null) { - mapper = new ObjectMapper(); - _mapperReference.set(mapper); - } - return mapper; } -} diff --git a/src/main/java/com/fasterxml/jackson/databind/ser/std/StaticListSerializerBase.java b/src/main/java/com/fasterxml/jackson/databind/ser/std/StaticListSerializerBase.java index 798eaa454d..690ff3a71f 100644 --- a/src/main/java/com/fasterxml/jackson/databind/ser/std/StaticListSerializerBase.java +++ b/src/main/java/com/fasterxml/jackson/databind/ser/std/StaticListSerializerBase.java @@ -5,7 +5,7 @@ import com.fasterxml.jackson.databind.JavaType; import com.fasterxml.jackson.databind.JsonNode; import com.fasterxml.jackson.databind.SerializerProvider; -import com.fasterxml.jackson.databind.jsonschema.SchemaAware; +import com.fasterxml.jackson.databind.jsonschema.JsonFormatVisitorAware; import com.fasterxml.jackson.databind.jsonschema.visitors.JsonArrayFormatVisitor; import com.fasterxml.jackson.databind.jsonschema.visitors.JsonFormatVisitor; import com.fasterxml.jackson.databind.node.ObjectNode; diff --git a/src/main/java/com/fasterxml/jackson/databind/ser/std/StdSerializer.java b/src/main/java/com/fasterxml/jackson/databind/ser/std/StdSerializer.java index 18aae8d2ea..08d6f0f34e 100644 --- a/src/main/java/com/fasterxml/jackson/databind/ser/std/StdSerializer.java +++ b/src/main/java/com/fasterxml/jackson/databind/ser/std/StdSerializer.java @@ -6,7 +6,7 @@ import com.fasterxml.jackson.core.*; import com.fasterxml.jackson.databind.*; import com.fasterxml.jackson.databind.annotation.JacksonStdImpl; -import com.fasterxml.jackson.databind.jsonschema.SchemaAware; +import com.fasterxml.jackson.databind.jsonschema.JsonFormatVisitorAware; import com.fasterxml.jackson.databind.jsonschema.visitors.JsonFormatVisitor; import com.fasterxml.jackson.databind.node.JsonNodeFactory; import com.fasterxml.jackson.databind.node.ObjectNode; @@ -15,11 +15,11 @@ * Base class used by all standard serializers, and can also * be used for custom serializers (in fact, this is the recommended * base class to use). - * Provides convenience methods for implementing {@link SchemaAware} + * Provides convenience methods for implementing {@link JsonFormatVisitorAware} */ public abstract class StdSerializer extends JsonSerializer - implements SchemaAware + implements JsonFormatVisitorAware { /** * Nominal type supported, usually declared type of @@ -71,7 +71,7 @@ public abstract void serialize(T value, JsonGenerator jgen, SerializerProvider p /* /********************************************************** - /* Helper methods for JSON Schema generation + /* Helper methods for JSON JsonSchema generation /********************************************************** */ diff --git a/src/test/java/com/fasterxml/jackson/databind/jsonschema/TestGenerateJsonSchema.java b/src/test/java/com/fasterxml/jackson/databind/jsonschema/TestGenerateJsonSchema.java index e103fc6f70..c1ee2391bd 100644 --- a/src/test/java/com/fasterxml/jackson/databind/jsonschema/TestGenerateJsonSchema.java +++ b/src/test/java/com/fasterxml/jackson/databind/jsonschema/TestGenerateJsonSchema.java @@ -8,7 +8,7 @@ import com.fasterxml.jackson.annotation.JsonProperty; import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.databind.jsonschema.types.ObjectSchema; -import com.fasterxml.jackson.databind.jsonschema.types.Schema; +import com.fasterxml.jackson.databind.jsonschema.types.JsonSchema; import com.fasterxml.jackson.databind.jsonschema.types.ArraySchema.Items; import com.fasterxml.jackson.databind.ser.DefaultSerializerProvider; import com.fasterxml.jackson.databind.ser.FilterProvider; @@ -113,41 +113,41 @@ public void testGeneratingJsonSchema() DefaultSerializerProvider sp = new DefaultSerializerProvider.Impl(); ObjectMapper m = new ObjectMapper(); m.setSerializerProvider(sp); - Schema schema = m.generateJsonSchema(SimpleBean.class); + JsonSchema jsonSchema = m.generateJsonSchema(SimpleBean.class); - assertNotNull(schema); + assertNotNull(jsonSchema); // test basic equality, and that equals() handles null, other obs - assertTrue(schema.equals(schema)); - assertFalse(schema.equals(null)); - assertFalse(schema.equals("foo")); + assertTrue(jsonSchema.equals(jsonSchema)); + assertFalse(jsonSchema.equals(null)); + assertFalse(jsonSchema.equals("foo")); - assertTrue(schema.isObjectSchema()); - ObjectSchema object = schema.asObjectSchema(); + assertTrue(jsonSchema.isObjectSchema()); + ObjectSchema object = jsonSchema.asObjectSchema(); assertNotNull(object); - Map properties = object.getProperties(); + Map properties = object.getProperties(); assertNotNull(properties); - Schema prop1 = properties.get("property1"); + JsonSchema prop1 = properties.get("property1"); assertNotNull(prop1); assertTrue(prop1.isIntegerSchema()); assertNull(prop1.getRequired()); - Schema prop2 = properties.get("property2"); + JsonSchema prop2 = properties.get("property2"); assertNotNull(prop2); assertTrue(prop2.isStringSchema()); assertNull(prop2.getRequired()); - Schema prop3 = properties.get("property3"); + JsonSchema prop3 = properties.get("property3"); assertNotNull(prop3); assertTrue(prop3.isArraySchema()); assertNull(prop3.getRequired()); Items items = prop3.asArraySchema().getItems(); assertTrue(items.isSingleItems()); - Schema itemType = items.asSingleItems().getSchema(); + JsonSchema itemType = items.asSingleItems().getSchema(); assertNotNull(itemType); assertTrue(itemType.isStringSchema()); - Schema prop4 = properties.get("property4"); + JsonSchema prop4 = properties.get("property4"); assertNotNull(prop4); assertTrue(prop4.isArraySchema()); assertNull(prop4.getRequired()); @@ -157,7 +157,7 @@ public void testGeneratingJsonSchema() assertNotNull(itemType); assertTrue(itemType.isNumberSchema()); - Schema prop5 = properties.get("property5"); + JsonSchema prop5 = properties.get("property5"); assertNotNull(prop5); assertTrue(prop5.getRequired()); @@ -185,14 +185,14 @@ private static class FilteredBean { public void testGeneratingJsonSchemaWithFilters() throws Exception { ObjectMapper mapper = new ObjectMapper(); mapper.setFilters(secretFilterProvider); - Schema schema = mapper.generateJsonSchema(FilteredBean.class); - assertNotNull(schema); - assertTrue(schema.isObjectSchema()); - ObjectSchema object = schema.asObjectSchema(); + JsonSchema jsonSchema = mapper.generateJsonSchema(FilteredBean.class); + assertNotNull(jsonSchema); + assertTrue(jsonSchema.isObjectSchema()); + ObjectSchema object = jsonSchema.asObjectSchema(); assertNotNull(object); - Map properties = object.getProperties(); + Map properties = object.getProperties(); assertNotNull(properties); - Schema obvious = properties.get("obvious"); + JsonSchema obvious = properties.get("obvious"); assertNotNull(obvious); assertTrue(obvious.isStringSchema()); assertNull(properties.get("secret")); @@ -205,7 +205,7 @@ public void testGeneratingJsonSchemaWithFilters() throws Exception { public void testSchemaSerialization() throws Exception { - Schema jsonSchema = MAPPER.generateJsonSchema(SimpleBean.class); + JsonSchema jsonSchema = MAPPER.generateJsonSchema(SimpleBean.class); Map result = writeAndMap(MAPPER, jsonSchema); assertNotNull(result); // no need to check out full structure, just basics... @@ -232,7 +232,7 @@ public void testInvalidCall() */ public void testThatObjectsHaveNoItems() throws Exception { - Schema jsonSchema = MAPPER.generateJsonSchema(TrivialBean.class); + JsonSchema jsonSchema = MAPPER.generateJsonSchema(TrivialBean.class); Map result = writeAndMap(MAPPER, jsonSchema); // can we count on ordering being stable? I think this is true with current ObjectNode impl // as perh [JACKSON-563]; 'required' is only included if true @@ -240,14 +240,15 @@ public void testThatObjectsHaveNoItems() throws Exception } - public void testSchemaId() throws Exception + @SuppressWarnings({ "unchecked", "rawtypes", "serial" }) + public void testSchemaId() throws Exception { - Schema jsonSchema = MAPPER.generateJsonSchema(BeanWithId.class); + JsonSchema jsonSchema = MAPPER.generateJsonSchema(BeanWithId.class); Map result = writeAndMap(MAPPER, jsonSchema); assertEquals(new HashMap() {{ put("type", "object"); - put("id", "myType"); + //put("id", "myType"); /* This is not a correct use of id. see "http://tools.ietf.org/html/draft-zyp-json-schema-03#section-5.27" */ put("properties", new HashMap(){{ put("value", new HashMap() {{ put("type", "string");}} diff --git a/src/test/java/com/fasterxml/jackson/databind/jsonschema/TestReadJsonSchema.java b/src/test/java/com/fasterxml/jackson/databind/jsonschema/TestReadJsonSchema.java index a8460a5068..f786f173e9 100644 --- a/src/test/java/com/fasterxml/jackson/databind/jsonschema/TestReadJsonSchema.java +++ b/src/test/java/com/fasterxml/jackson/databind/jsonschema/TestReadJsonSchema.java @@ -3,8 +3,7 @@ import java.util.*; import com.fasterxml.jackson.databind.*; -import com.fasterxml.jackson.databind.jsonschema.JsonSchema; -import com.fasterxml.jackson.databind.jsonschema.types.Schema; +import com.fasterxml.jackson.databind.jsonschema.types.JsonSchema; /** * Trivial test to ensure {@link JsonSchema} can be also deserialized @@ -51,12 +50,12 @@ static class Schemable { public void testDeserializeSimple() throws Exception { ObjectMapper mapper = new ObjectMapper(); - Schema schema = mapper.generateJsonSchema(Schemable.class); - assertNotNull(schema); + JsonSchema jsonSchema = mapper.generateJsonSchema(Schemable.class); + assertNotNull(jsonSchema); - String schemaStr = mapper.writeValueAsString(schema); + String schemaStr = mapper.writeValueAsString(jsonSchema); assertNotNull(schemaStr); JsonSchema result = mapper.readValue(schemaStr, JsonSchema.class); - assertEquals("Trying to read from '"+schemaStr+"'", schema, result); + assertEquals("Trying to read from '"+schemaStr+"'", jsonSchema, result); } } From 91c4467412bb324f9931ecdf9d34fe5d9a6d285c Mon Sep 17 00:00:00 2001 From: jackphel Date: Mon, 6 Aug 2012 20:01:51 -0400 Subject: [PATCH 11/19] continuous loop property filter checking into separate loops. --- .../databind/ser/std/BeanSerializerBase.java | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) diff --git a/src/main/java/com/fasterxml/jackson/databind/ser/std/BeanSerializerBase.java b/src/main/java/com/fasterxml/jackson/databind/ser/std/BeanSerializerBase.java index 677867d248..3474f20d40 100644 --- a/src/main/java/com/fasterxml/jackson/databind/ser/std/BeanSerializerBase.java +++ b/src/main/java/com/fasterxml/jackson/databind/ser/std/BeanSerializerBase.java @@ -629,24 +629,23 @@ public void acceptJsonFormatVisitor(JsonFormatVisitor visitor, JavaType typeHint { JsonObjectFormatVisitor objectVisitor = visitor.objectFormat(typeHint); - BeanPropertyFilter filter; if (_propertyFilterId != null) { try { - filter = findFilter(visitor.getProvider()); + BeanPropertyFilter filter = findFilter(visitor.getProvider()); + for (int i = 0; i < _props.length; i++) { + BeanPropertyWriter prop = _props[i]; + filter.depositSchemaProperty(prop, objectVisitor, visitor.getProvider()); + } + return; } catch (JsonMappingException e) { // TODO Auto-generated catch block - filter = null; + } - } else { - filter = null; - } + } for (int i = 0; i < _props.length; i++) { BeanPropertyWriter prop = _props[i]; - if (filter != null) { - filter.depositSchemaProperty(prop, objectVisitor, visitor.getProvider()); - continue; - } + JavaType propType = prop.getSerializationType(); BeanSerializerBase.depositSchemaProperty(prop, objectVisitor); } From 3bbe215e5e73a4c9c4b2b08b187a93ce48763f9d Mon Sep 17 00:00:00 2001 From: jackphel Date: Mon, 6 Aug 2012 22:04:24 -0400 Subject: [PATCH 12/19] removed Schema knowledge from objectMapper ObjectMapper now acceptsJsonFormatVisitor rather than generateJsonSchema. Added setProvider to JsonFormatVisitor so that ObjectMapper can pass reference to first visitor. Schema Hierarchy passes parent references, and gets provider from parent. --- .../jackson/databind/ObjectMapper.java | 18 ++++++----- .../factories/AnySchemaFactory.java | 2 +- .../factories/ArraySchemaFactory.java | 5 +-- .../factories/BooleanSchemaFactory.java | 4 +-- .../factories/IntegerSchemaFactory.java | 4 +-- .../factories/NullSchemaFactory.java | 2 +- .../factories/NumberSchemaFactory.java | 3 +- .../factories/ObjectSchemaFactory.java | 8 +++-- .../jsonschema/factories/SchemaFactory.java | 11 +++++-- .../factories/StringSchemaFactory.java | 4 +-- .../factories/ValueTypeSchemaFactory.java | 8 +++-- .../visitors/JsonFormatVisitor.java | 1 + .../jsonschema/TestGenerateJsonSchema.java | 31 ++++++++++++------- .../jsonschema/TestReadJsonSchema.java | 5 ++- 14 files changed, 63 insertions(+), 43 deletions(-) diff --git a/src/main/java/com/fasterxml/jackson/databind/ObjectMapper.java b/src/main/java/com/fasterxml/jackson/databind/ObjectMapper.java index 819a5b6f12..1e71a1dcaa 100644 --- a/src/main/java/com/fasterxml/jackson/databind/ObjectMapper.java +++ b/src/main/java/com/fasterxml/jackson/databind/ObjectMapper.java @@ -26,8 +26,7 @@ import com.fasterxml.jackson.databind.introspect.ClassIntrospector; import com.fasterxml.jackson.databind.introspect.JacksonAnnotationIntrospector; import com.fasterxml.jackson.databind.introspect.VisibilityChecker; -import com.fasterxml.jackson.databind.jsonschema.factories.SchemaFactory; -import com.fasterxml.jackson.databind.jsonschema.types.JsonSchema; +import com.fasterxml.jackson.databind.jsonschema.visitors.JsonFormatVisitor; import com.fasterxml.jackson.databind.jsontype.*; import com.fasterxml.jackson.databind.jsontype.impl.StdSubtypeResolver; import com.fasterxml.jackson.databind.jsontype.impl.StdTypeResolverBuilder; @@ -2396,13 +2395,18 @@ protected Object _convert(Object fromValue, JavaType toValueType) * instance for specified class. * * @param t The class to generate schema for - * @return Constructed JSON schema. */ - public JsonSchema generateJsonSchema(Class t) throws JsonMappingException { + public void acceptJsonFormatVisitor(Class t, JsonFormatVisitor visitor) throws JsonMappingException { + if (t == null) { + throw new IllegalArgumentException("class must be provided"); + } + + if (visitor == null) { + return; + } DefaultSerializerProvider provider = _serializerProvider(getSerializationConfig()); - SchemaFactory visitor = new SchemaFactory(provider); - provider.acceptJsonFormatVisitor(t, visitor); - return visitor.finalSchema(); + visitor.setProvider(provider); + provider.acceptJsonFormatVisitor(t, visitor); } /* diff --git a/src/main/java/com/fasterxml/jackson/databind/jsonschema/factories/AnySchemaFactory.java b/src/main/java/com/fasterxml/jackson/databind/jsonschema/factories/AnySchemaFactory.java index f948d90610..f9e0b089c3 100644 --- a/src/main/java/com/fasterxml/jackson/databind/jsonschema/factories/AnySchemaFactory.java +++ b/src/main/java/com/fasterxml/jackson/databind/jsonschema/factories/AnySchemaFactory.java @@ -11,8 +11,8 @@ public class AnySchemaFactory extends SchemaFactory implements protected AnySchema anySchema; public AnySchemaFactory(SchemaFactory parent) { - super(parent.provider); this.parent = parent; + setProvider(parent.getProvider()); anySchema = new AnySchema(); } diff --git a/src/main/java/com/fasterxml/jackson/databind/jsonschema/factories/ArraySchemaFactory.java b/src/main/java/com/fasterxml/jackson/databind/jsonschema/factories/ArraySchemaFactory.java index afd02fa5c0..9ef546b876 100644 --- a/src/main/java/com/fasterxml/jackson/databind/jsonschema/factories/ArraySchemaFactory.java +++ b/src/main/java/com/fasterxml/jackson/databind/jsonschema/factories/ArraySchemaFactory.java @@ -17,8 +17,8 @@ public class ArraySchemaFactory extends SchemaFactory implements JsonArrayFormat protected BeanProperty _property; public ArraySchemaFactory(SchemaFactory parent, BeanProperty property) { - super(parent.provider); this.parent = parent; + setProvider(parent.getProvider()); arraySchema = new ArraySchema(); } @@ -34,7 +34,8 @@ public void itemsFormat(JavaType contentType) { try { ser = getProvider().findValueSerializer(contentType, _property); if (ser instanceof JsonFormatVisitorAware) { - SchemaFactory visitor = new SchemaFactory(provider); + SchemaFactory visitor = new SchemaFactory(); + visitor.setProvider(provider); ((JsonFormatVisitorAware) ser).acceptJsonFormatVisitor(visitor, contentType); arraySchema.setItemsSchema(visitor.finalSchema()); } diff --git a/src/main/java/com/fasterxml/jackson/databind/jsonschema/factories/BooleanSchemaFactory.java b/src/main/java/com/fasterxml/jackson/databind/jsonschema/factories/BooleanSchemaFactory.java index 61b4e16cdc..179ad28404 100644 --- a/src/main/java/com/fasterxml/jackson/databind/jsonschema/factories/BooleanSchemaFactory.java +++ b/src/main/java/com/fasterxml/jackson/databind/jsonschema/factories/BooleanSchemaFactory.java @@ -7,12 +7,10 @@ public class BooleanSchemaFactory extends ValueTypeSchemaFactory implements SchemaFactoryDelegate, JsonBooleanFormatVisitor { - protected SchemaFactory parent; protected BooleanSchema booleanSchema; public BooleanSchemaFactory(SchemaFactory parent) { - super(parent.provider); - this.parent = parent; + super(parent); booleanSchema = new BooleanSchema(); } diff --git a/src/main/java/com/fasterxml/jackson/databind/jsonschema/factories/IntegerSchemaFactory.java b/src/main/java/com/fasterxml/jackson/databind/jsonschema/factories/IntegerSchemaFactory.java index f073fb26db..3d821a1d6e 100644 --- a/src/main/java/com/fasterxml/jackson/databind/jsonschema/factories/IntegerSchemaFactory.java +++ b/src/main/java/com/fasterxml/jackson/databind/jsonschema/factories/IntegerSchemaFactory.java @@ -7,12 +7,10 @@ public class IntegerSchemaFactory extends ValueTypeSchemaFactory implements JsonIntegerFormatVisitor, SchemaFactoryDelegate { - protected SchemaFactory parent; protected IntegerSchema integerSchema; public IntegerSchemaFactory(SchemaFactory parent) { - super(parent.provider); - this.parent = parent; + super(parent); integerSchema = new IntegerSchema(); } diff --git a/src/main/java/com/fasterxml/jackson/databind/jsonschema/factories/NullSchemaFactory.java b/src/main/java/com/fasterxml/jackson/databind/jsonschema/factories/NullSchemaFactory.java index c71d2cadd3..1d945b5828 100644 --- a/src/main/java/com/fasterxml/jackson/databind/jsonschema/factories/NullSchemaFactory.java +++ b/src/main/java/com/fasterxml/jackson/databind/jsonschema/factories/NullSchemaFactory.java @@ -11,8 +11,8 @@ public class NullSchemaFactory extends SchemaFactory implements protected NullSchema nullSchema; public NullSchemaFactory(SchemaFactory parent) { - super(parent.provider); this.parent = parent; + setProvider(parent.getProvider()); nullSchema = new NullSchema(); } diff --git a/src/main/java/com/fasterxml/jackson/databind/jsonschema/factories/NumberSchemaFactory.java b/src/main/java/com/fasterxml/jackson/databind/jsonschema/factories/NumberSchemaFactory.java index 49582b9cb6..05d5a28972 100644 --- a/src/main/java/com/fasterxml/jackson/databind/jsonschema/factories/NumberSchemaFactory.java +++ b/src/main/java/com/fasterxml/jackson/databind/jsonschema/factories/NumberSchemaFactory.java @@ -7,11 +7,10 @@ public class NumberSchemaFactory extends ValueTypeSchemaFactory implements JsonNumberFormatVisitor, SchemaFactoryDelegate { - protected SchemaFactory parent; protected NumberSchema numberSchema; public NumberSchemaFactory(SchemaFactory parent) { - super(parent.provider); + super(parent); this.parent = parent; numberSchema = new NumberSchema(); } diff --git a/src/main/java/com/fasterxml/jackson/databind/jsonschema/factories/ObjectSchemaFactory.java b/src/main/java/com/fasterxml/jackson/databind/jsonschema/factories/ObjectSchemaFactory.java index 78206b8fe1..2f2bb58b27 100644 --- a/src/main/java/com/fasterxml/jackson/databind/jsonschema/factories/ObjectSchemaFactory.java +++ b/src/main/java/com/fasterxml/jackson/databind/jsonschema/factories/ObjectSchemaFactory.java @@ -17,8 +17,8 @@ public class ObjectSchemaFactory extends SchemaFactory implements JsonObjectForm protected ObjectSchema objectSchema; public ObjectSchemaFactory(SchemaFactory parent) { - super(parent.provider); this.parent = parent; + setProvider(parent.getProvider()); objectSchema = new ObjectSchema(); } @@ -40,7 +40,8 @@ private JsonSerializer getSer(BeanPropertyWriter writer) { } protected JsonSchema propertySchema(BeanPropertyWriter writer) { - SchemaFactory visitor = new SchemaFactory(provider); + SchemaFactory visitor = new SchemaFactory(); + visitor.setProvider(provider); JsonSerializer ser = getSer(writer); if (ser != null && ser instanceof JsonFormatVisitorAware) { ((JsonFormatVisitorAware)ser).acceptJsonFormatVisitor(visitor, writer.getType()); @@ -51,7 +52,8 @@ protected JsonSchema propertySchema(BeanPropertyWriter writer) { } protected JsonSchema propertySchema(JsonFormatVisitorAware handler, JavaType propertyTypeHint) { - SchemaFactory visitor = new SchemaFactory(provider); + SchemaFactory visitor = new SchemaFactory(); + visitor.setProvider(provider); handler.acceptJsonFormatVisitor(visitor, propertyTypeHint); return visitor.finalSchema(); } diff --git a/src/main/java/com/fasterxml/jackson/databind/jsonschema/factories/SchemaFactory.java b/src/main/java/com/fasterxml/jackson/databind/jsonschema/factories/SchemaFactory.java index 53407d101e..fd8b766869 100644 --- a/src/main/java/com/fasterxml/jackson/databind/jsonschema/factories/SchemaFactory.java +++ b/src/main/java/com/fasterxml/jackson/databind/jsonschema/factories/SchemaFactory.java @@ -18,8 +18,7 @@ public class SchemaFactory implements JsonFormatVisitor { private SchemaFactoryDelegate delegate; protected SerializerProvider provider; - public SchemaFactory(SerializerProvider mapper) { - this.provider = mapper; + public SchemaFactory() { } public JsonAnyFormatVisitor anyFormat() { @@ -47,6 +46,14 @@ public JsonSchema finalSchema() { } + /** + * {@link SchemaFactory#provider} + * @param provider the provider to set + */ + public void setProvider(SerializerProvider provider) { + this.provider = provider; + } + public SerializerProvider getProvider() { return provider; } diff --git a/src/main/java/com/fasterxml/jackson/databind/jsonschema/factories/StringSchemaFactory.java b/src/main/java/com/fasterxml/jackson/databind/jsonschema/factories/StringSchemaFactory.java index 26560c2cf5..c5fdf91120 100644 --- a/src/main/java/com/fasterxml/jackson/databind/jsonschema/factories/StringSchemaFactory.java +++ b/src/main/java/com/fasterxml/jackson/databind/jsonschema/factories/StringSchemaFactory.java @@ -8,11 +8,9 @@ public class StringSchemaFactory extends ValueTypeSchemaFactory implements JsonS SchemaFactoryDelegate { protected StringSchema stringSchema; - protected SchemaFactory parent; public StringSchemaFactory(SchemaFactory parent) { - super(parent.provider); - this.parent = parent; + super(parent); stringSchema = new StringSchema(); } diff --git a/src/main/java/com/fasterxml/jackson/databind/jsonschema/factories/ValueTypeSchemaFactory.java b/src/main/java/com/fasterxml/jackson/databind/jsonschema/factories/ValueTypeSchemaFactory.java index 2041accc55..8f7141ad91 100644 --- a/src/main/java/com/fasterxml/jackson/databind/jsonschema/factories/ValueTypeSchemaFactory.java +++ b/src/main/java/com/fasterxml/jackson/databind/jsonschema/factories/ValueTypeSchemaFactory.java @@ -2,7 +2,6 @@ import java.util.Set; -import com.fasterxml.jackson.databind.SerializerProvider; import com.fasterxml.jackson.databind.jsonschema.types.JsonValueFormat; import com.fasterxml.jackson.databind.jsonschema.types.JsonSchema; import com.fasterxml.jackson.databind.jsonschema.types.ValueTypeSchema; @@ -11,8 +10,11 @@ public abstract class ValueTypeSchemaFactory extends SchemaFactory implements SchemaFactoryDelegate, JsonValueFormatVisitor { - protected ValueTypeSchemaFactory(SerializerProvider provider) { - super(provider); + protected SchemaFactory parent; + + protected ValueTypeSchemaFactory(SchemaFactory parent) { + this.parent = parent; + setProvider(parent.getProvider()); } public JsonSchema getSchema() { diff --git a/src/main/java/com/fasterxml/jackson/databind/jsonschema/visitors/JsonFormatVisitor.java b/src/main/java/com/fasterxml/jackson/databind/jsonschema/visitors/JsonFormatVisitor.java index 66181e385e..ff0ec987dd 100644 --- a/src/main/java/com/fasterxml/jackson/databind/jsonschema/visitors/JsonFormatVisitor.java +++ b/src/main/java/com/fasterxml/jackson/databind/jsonschema/visitors/JsonFormatVisitor.java @@ -15,5 +15,6 @@ public interface JsonFormatVisitor { public JsonAnyFormatVisitor anyFormat(); public SerializerProvider getProvider(); + public abstract void setProvider(SerializerProvider provider); } diff --git a/src/test/java/com/fasterxml/jackson/databind/jsonschema/TestGenerateJsonSchema.java b/src/test/java/com/fasterxml/jackson/databind/jsonschema/TestGenerateJsonSchema.java index c1ee2391bd..f22943f8fc 100644 --- a/src/test/java/com/fasterxml/jackson/databind/jsonschema/TestGenerateJsonSchema.java +++ b/src/test/java/com/fasterxml/jackson/databind/jsonschema/TestGenerateJsonSchema.java @@ -7,10 +7,10 @@ import com.fasterxml.jackson.annotation.JsonFilter; import com.fasterxml.jackson.annotation.JsonProperty; import com.fasterxml.jackson.databind.ObjectMapper; +import com.fasterxml.jackson.databind.jsonschema.factories.SchemaFactory; import com.fasterxml.jackson.databind.jsonschema.types.ObjectSchema; import com.fasterxml.jackson.databind.jsonschema.types.JsonSchema; import com.fasterxml.jackson.databind.jsonschema.types.ArraySchema.Items; -import com.fasterxml.jackson.databind.ser.DefaultSerializerProvider; import com.fasterxml.jackson.databind.ser.FilterProvider; import com.fasterxml.jackson.databind.ser.impl.SimpleBeanPropertyFilter; import com.fasterxml.jackson.databind.ser.impl.SimpleFilterProvider; @@ -110,10 +110,10 @@ public class BeanWithId { public void testGeneratingJsonSchema() throws Exception { - DefaultSerializerProvider sp = new DefaultSerializerProvider.Impl(); ObjectMapper m = new ObjectMapper(); - m.setSerializerProvider(sp); - JsonSchema jsonSchema = m.generateJsonSchema(SimpleBean.class); + SchemaFactory visitor = new SchemaFactory(); + m.acceptJsonFormatVisitor(SimpleBean.class, visitor); + JsonSchema jsonSchema = visitor.finalSchema(); assertNotNull(jsonSchema); @@ -185,7 +185,9 @@ private static class FilteredBean { public void testGeneratingJsonSchemaWithFilters() throws Exception { ObjectMapper mapper = new ObjectMapper(); mapper.setFilters(secretFilterProvider); - JsonSchema jsonSchema = mapper.generateJsonSchema(FilteredBean.class); + SchemaFactory visitor = new SchemaFactory(); + mapper.acceptJsonFormatVisitor(FilteredBean.class, visitor); + JsonSchema jsonSchema = visitor.finalSchema(); assertNotNull(jsonSchema); assertTrue(jsonSchema.isObjectSchema()); ObjectSchema object = jsonSchema.asObjectSchema(); @@ -205,7 +207,9 @@ public void testGeneratingJsonSchemaWithFilters() throws Exception { public void testSchemaSerialization() throws Exception { - JsonSchema jsonSchema = MAPPER.generateJsonSchema(SimpleBean.class); + SchemaFactory visitor = new SchemaFactory(); + MAPPER.acceptJsonFormatVisitor(SimpleBean.class, visitor); + JsonSchema jsonSchema = visitor.finalSchema(); Map result = writeAndMap(MAPPER, jsonSchema); assertNotNull(result); // no need to check out full structure, just basics... @@ -220,7 +224,9 @@ public void testInvalidCall() { // not ok to pass null try { - MAPPER.generateJsonSchema(null); + SchemaFactory visitor = new SchemaFactory(); + MAPPER.acceptJsonFormatVisitor(null, visitor); + JsonSchema jsonSchema = visitor.finalSchema(); fail("Should have failed"); } catch (IllegalArgumentException iae) { verifyException(iae, "class must be provided"); @@ -232,7 +238,9 @@ public void testInvalidCall() */ public void testThatObjectsHaveNoItems() throws Exception { - JsonSchema jsonSchema = MAPPER.generateJsonSchema(TrivialBean.class); + SchemaFactory visitor = new SchemaFactory(); + MAPPER.acceptJsonFormatVisitor(TrivialBean.class, visitor); + JsonSchema jsonSchema = visitor.finalSchema(); Map result = writeAndMap(MAPPER, jsonSchema); // can we count on ordering being stable? I think this is true with current ObjectNode impl // as perh [JACKSON-563]; 'required' is only included if true @@ -243,18 +251,17 @@ public void testThatObjectsHaveNoItems() throws Exception @SuppressWarnings({ "unchecked", "rawtypes", "serial" }) public void testSchemaId() throws Exception { - JsonSchema jsonSchema = MAPPER.generateJsonSchema(BeanWithId.class); + SchemaFactory visitor = new SchemaFactory(); + MAPPER.acceptJsonFormatVisitor(BeanWithId.class, visitor); + JsonSchema jsonSchema = visitor.finalSchema(); Map result = writeAndMap(MAPPER, jsonSchema); assertEquals(new HashMap() {{ put("type", "object"); - //put("id", "myType"); /* This is not a correct use of id. see "http://tools.ietf.org/html/draft-zyp-json-schema-03#section-5.27" */ put("properties", new HashMap(){{ put("value", new HashMap() {{ put("type", "string");}} );}} );}}, result); - //assertEquals("{'type':'object','id':'myType','properties':{'value':{'type':'string'}}}", - // json); } } diff --git a/src/test/java/com/fasterxml/jackson/databind/jsonschema/TestReadJsonSchema.java b/src/test/java/com/fasterxml/jackson/databind/jsonschema/TestReadJsonSchema.java index f786f173e9..4865cbb76f 100644 --- a/src/test/java/com/fasterxml/jackson/databind/jsonschema/TestReadJsonSchema.java +++ b/src/test/java/com/fasterxml/jackson/databind/jsonschema/TestReadJsonSchema.java @@ -3,6 +3,7 @@ import java.util.*; import com.fasterxml.jackson.databind.*; +import com.fasterxml.jackson.databind.jsonschema.factories.SchemaFactory; import com.fasterxml.jackson.databind.jsonschema.types.JsonSchema; /** @@ -50,7 +51,9 @@ static class Schemable { public void testDeserializeSimple() throws Exception { ObjectMapper mapper = new ObjectMapper(); - JsonSchema jsonSchema = mapper.generateJsonSchema(Schemable.class); + SchemaFactory visitor = new SchemaFactory(); + mapper.acceptJsonFormatVisitor(Schemable.class, visitor); + JsonSchema jsonSchema = visitor.finalSchema(); assertNotNull(jsonSchema); String schemaStr = mapper.writeValueAsString(jsonSchema); From 7e5067227705dce9b620287245886403deceb825 Mon Sep 17 00:00:00 2001 From: jackphel Date: Tue, 7 Aug 2012 13:54:51 -0400 Subject: [PATCH 13/19] Added javatype reference to all factories, organized imports - All jsonformat visitors now accept the javatype of the translated java type in their factory constructor call - organized imports to remove references to jsonnodes and such --- .../jackson/databind/ext/DOMSerializer.java | 2 +- .../factories/NullSchemaFactory.java | 2 +- .../factories/ObjectSchemaFactory.java | 4 +-- .../jsonschema/factories/SchemaFactory.java | 16 ++++----- .../factories/ValueTypeSchemaFactory.java | 2 +- .../jsonschema/types/ArraySchema.java | 2 -- .../databind/jsonschema/types/JsonSchema.java | 1 - .../visitors/JsonFormatVisitor.java | 16 ++++----- .../visitors/JsonNumberFormatVisitor.java | 1 - .../ser/DefaultSerializerProvider.java | 2 +- .../databind/ser/impl/UnknownSerializer.java | 2 +- .../databind/ser/std/ArraySerializerBase.java | 10 +++--- .../ser/std/AsArraySerializerBase.java | 12 +++++-- .../databind/ser/std/BeanSerializerBase.java | 25 +++++++++---- .../databind/ser/std/BooleanSerializer.java | 4 +-- .../databind/ser/std/CalendarSerializer.java | 4 +-- .../ser/std/CollectionSerializer.java | 3 +- .../databind/ser/std/DateSerializer.java | 8 ++--- .../ser/std/DateTimeSerializerBase.java | 11 ++++-- .../databind/ser/std/EnumMapSerializer.java | 14 +++++--- .../databind/ser/std/EnumSerializer.java | 19 +++++----- .../databind/ser/std/EnumSetSerializer.java | 9 +++-- .../ser/std/InetAddressSerializer.java | 4 +-- .../databind/ser/std/IterableSerializer.java | 4 +-- .../databind/ser/std/JsonValueSerializer.java | 14 +++++--- .../databind/ser/std/MapSerializer.java | 21 +++++++---- .../ser/std/NonTypedScalarSerializerBase.java | 4 +-- .../databind/ser/std/NullSerializer.java | 9 ++--- .../databind/ser/std/NumberSerializers.java | 19 +++++----- .../ser/std/ObjectArraySerializer.java | 10 ++++-- .../databind/ser/std/RawSerializer.java | 10 +++--- .../ser/std/SerializableSerializer.java | 7 ++-- .../databind/ser/std/SqlDateSerializer.java | 4 +-- .../databind/ser/std/SqlTimeSerializer.java | 4 +-- .../ser/std/StaticListSerializerBase.java | 6 +--- .../databind/ser/std/StdArraySerializers.java | 11 +++--- .../ser/std/StdContainerSerializers.java | 5 +-- .../databind/ser/std/StdJdkSerializers.java | 36 ++++++++++++------- .../databind/ser/std/StdKeySerializer.java | 7 ++-- .../databind/ser/std/StdKeySerializers.java | 4 +-- .../databind/ser/std/StdScalarSerializer.java | 8 ++--- .../databind/ser/std/StdSerializer.java | 13 ++++--- .../databind/ser/std/StringSerializer.java | 6 ++-- .../databind/ser/std/TimeZoneSerializer.java | 4 +-- .../databind/ser/std/ToStringSerializer.java | 8 ++--- .../ser/std/TokenBufferSerializer.java | 7 ++-- .../databind/module/TestSimpleModule.java | 4 +-- 47 files changed, 226 insertions(+), 172 deletions(-) diff --git a/src/main/java/com/fasterxml/jackson/databind/ext/DOMSerializer.java b/src/main/java/com/fasterxml/jackson/databind/ext/DOMSerializer.java index f22f628ec1..7f6515b710 100644 --- a/src/main/java/com/fasterxml/jackson/databind/ext/DOMSerializer.java +++ b/src/main/java/com/fasterxml/jackson/databind/ext/DOMSerializer.java @@ -43,6 +43,6 @@ public void serialize(Node value, JsonGenerator jgen, SerializerProvider provide @Override public void acceptJsonFormatVisitor(JsonFormatVisitor visitor, JavaType typeHint) { - visitor.anyFormat(); + visitor.anyFormat(typeHint); } } diff --git a/src/main/java/com/fasterxml/jackson/databind/jsonschema/factories/NullSchemaFactory.java b/src/main/java/com/fasterxml/jackson/databind/jsonschema/factories/NullSchemaFactory.java index 1d945b5828..07d3630dfd 100644 --- a/src/main/java/com/fasterxml/jackson/databind/jsonschema/factories/NullSchemaFactory.java +++ b/src/main/java/com/fasterxml/jackson/databind/jsonschema/factories/NullSchemaFactory.java @@ -1,7 +1,7 @@ package com.fasterxml.jackson.databind.jsonschema.factories; -import com.fasterxml.jackson.databind.jsonschema.types.NullSchema; import com.fasterxml.jackson.databind.jsonschema.types.JsonSchema; +import com.fasterxml.jackson.databind.jsonschema.types.NullSchema; import com.fasterxml.jackson.databind.jsonschema.visitors.JsonNullFormatVisitor; public class NullSchemaFactory extends SchemaFactory implements diff --git a/src/main/java/com/fasterxml/jackson/databind/jsonschema/factories/ObjectSchemaFactory.java b/src/main/java/com/fasterxml/jackson/databind/jsonschema/factories/ObjectSchemaFactory.java index 2f2bb58b27..3af3921bdd 100644 --- a/src/main/java/com/fasterxml/jackson/databind/jsonschema/factories/ObjectSchemaFactory.java +++ b/src/main/java/com/fasterxml/jackson/databind/jsonschema/factories/ObjectSchemaFactory.java @@ -5,8 +5,8 @@ import com.fasterxml.jackson.databind.JsonMappingException; import com.fasterxml.jackson.databind.JsonSerializer; import com.fasterxml.jackson.databind.jsonschema.JsonFormatVisitorAware; -import com.fasterxml.jackson.databind.jsonschema.types.ObjectSchema; import com.fasterxml.jackson.databind.jsonschema.types.JsonSchema; +import com.fasterxml.jackson.databind.jsonschema.types.ObjectSchema; import com.fasterxml.jackson.databind.jsonschema.types.SchemaType; import com.fasterxml.jackson.databind.jsonschema.visitors.JsonObjectFormatVisitor; import com.fasterxml.jackson.databind.ser.BeanPropertyWriter; @@ -46,7 +46,7 @@ protected JsonSchema propertySchema(BeanPropertyWriter writer) { if (ser != null && ser instanceof JsonFormatVisitorAware) { ((JsonFormatVisitorAware)ser).acceptJsonFormatVisitor(visitor, writer.getType()); } else { - visitor.anyFormat(); + visitor.anyFormat(writer.getType()); } return visitor.finalSchema(); } diff --git a/src/main/java/com/fasterxml/jackson/databind/jsonschema/factories/SchemaFactory.java b/src/main/java/com/fasterxml/jackson/databind/jsonschema/factories/SchemaFactory.java index fd8b766869..2c42699c0f 100644 --- a/src/main/java/com/fasterxml/jackson/databind/jsonschema/factories/SchemaFactory.java +++ b/src/main/java/com/fasterxml/jackson/databind/jsonschema/factories/SchemaFactory.java @@ -21,17 +21,17 @@ public class SchemaFactory implements JsonFormatVisitor { public SchemaFactory() { } - public JsonAnyFormatVisitor anyFormat() { + public JsonAnyFormatVisitor anyFormat(JavaType convertedType) { delegate = new AnySchemaFactory(this); return (JsonAnyFormatVisitor) delegate; } - public JsonArrayFormatVisitor arrayFormat(JavaType elementType) { + public JsonArrayFormatVisitor arrayFormat(JavaType convertedType) { delegate = new ArraySchemaFactory(this); return (JsonArrayFormatVisitor) delegate; } - public JsonBooleanFormatVisitor booleanFormat() { + public JsonBooleanFormatVisitor booleanFormat(JavaType convertedType) { delegate = new BooleanSchemaFactory(this); return (JsonBooleanFormatVisitor) delegate; } @@ -58,28 +58,28 @@ public SerializerProvider getProvider() { return provider; } - public JsonIntegerFormatVisitor integerFormat() { + public JsonIntegerFormatVisitor integerFormat(JavaType convertedType) { delegate = new IntegerSchemaFactory(this); return (JsonIntegerFormatVisitor) delegate; } - public JsonNullFormatVisitor nullFormat() { + public JsonNullFormatVisitor nullFormat(JavaType convertedType) { delegate = new NullSchemaFactory(this); return (JsonNullFormatVisitor) delegate; } - public JsonNumberFormatVisitor numberFormat() { + public JsonNumberFormatVisitor numberFormat(JavaType convertedType) { delegate = new NumberSchemaFactory(this); return (JsonNumberFormatVisitor) delegate; } - public JsonObjectFormatVisitor objectFormat(JavaType type) { + public JsonObjectFormatVisitor objectFormat(JavaType convertedType) { // BasicClassIntrospector.instance. delegate = new ObjectSchemaFactory(this); return (JsonObjectFormatVisitor) delegate; } - public JsonStringFormatVisitor stringFormat() { + public JsonStringFormatVisitor stringFormat(JavaType convertedType) { delegate = new StringSchemaFactory(this); return (JsonStringFormatVisitor) delegate; } diff --git a/src/main/java/com/fasterxml/jackson/databind/jsonschema/factories/ValueTypeSchemaFactory.java b/src/main/java/com/fasterxml/jackson/databind/jsonschema/factories/ValueTypeSchemaFactory.java index 8f7141ad91..6efde9a903 100644 --- a/src/main/java/com/fasterxml/jackson/databind/jsonschema/factories/ValueTypeSchemaFactory.java +++ b/src/main/java/com/fasterxml/jackson/databind/jsonschema/factories/ValueTypeSchemaFactory.java @@ -2,8 +2,8 @@ import java.util.Set; -import com.fasterxml.jackson.databind.jsonschema.types.JsonValueFormat; import com.fasterxml.jackson.databind.jsonschema.types.JsonSchema; +import com.fasterxml.jackson.databind.jsonschema.types.JsonValueFormat; import com.fasterxml.jackson.databind.jsonschema.types.ValueTypeSchema; import com.fasterxml.jackson.databind.jsonschema.visitors.JsonValueFormatVisitor; diff --git a/src/main/java/com/fasterxml/jackson/databind/jsonschema/types/ArraySchema.java b/src/main/java/com/fasterxml/jackson/databind/jsonschema/types/ArraySchema.java index 0c81f87a26..f0cfeba286 100644 --- a/src/main/java/com/fasterxml/jackson/databind/jsonschema/types/ArraySchema.java +++ b/src/main/java/com/fasterxml/jackson/databind/jsonschema/types/ArraySchema.java @@ -5,9 +5,7 @@ import com.fasterxml.jackson.annotation.JsonCreator; import com.fasterxml.jackson.annotation.JsonIgnore; import com.fasterxml.jackson.annotation.JsonProperty; -import com.fasterxml.jackson.annotation.JsonUnwrapped; import com.fasterxml.jackson.annotation.JsonValue; -import com.fasterxml.jackson.databind.jsonschema.factories.SchemaFactory; /* * This attribute defines the allowed items in an instance array, and diff --git a/src/main/java/com/fasterxml/jackson/databind/jsonschema/types/JsonSchema.java b/src/main/java/com/fasterxml/jackson/databind/jsonschema/types/JsonSchema.java index 95301a0f74..09482afb0b 100644 --- a/src/main/java/com/fasterxml/jackson/databind/jsonschema/types/JsonSchema.java +++ b/src/main/java/com/fasterxml/jackson/databind/jsonschema/types/JsonSchema.java @@ -12,7 +12,6 @@ import com.fasterxml.jackson.databind.JavaType; import com.fasterxml.jackson.databind.annotation.JsonTypeIdResolver; import com.fasterxml.jackson.databind.jsontype.TypeIdResolver; -import com.fasterxml.jackson.databind.jsontype.impl.TypeIdResolverBase; import com.fasterxml.jackson.databind.type.TypeFactory; /** diff --git a/src/main/java/com/fasterxml/jackson/databind/jsonschema/visitors/JsonFormatVisitor.java b/src/main/java/com/fasterxml/jackson/databind/jsonschema/visitors/JsonFormatVisitor.java index ff0ec987dd..ca1c3deeeb 100644 --- a/src/main/java/com/fasterxml/jackson/databind/jsonschema/visitors/JsonFormatVisitor.java +++ b/src/main/java/com/fasterxml/jackson/databind/jsonschema/visitors/JsonFormatVisitor.java @@ -5,14 +5,14 @@ public interface JsonFormatVisitor { - public JsonObjectFormatVisitor objectFormat(JavaType type); - public JsonArrayFormatVisitor arrayFormat(JavaType elementType); - public JsonStringFormatVisitor stringFormat(); - public JsonNumberFormatVisitor numberFormat(); - public JsonIntegerFormatVisitor integerFormat(); - public JsonBooleanFormatVisitor booleanFormat(); - public JsonNullFormatVisitor nullFormat(); - public JsonAnyFormatVisitor anyFormat(); + public JsonObjectFormatVisitor objectFormat(JavaType convertedType); + public JsonArrayFormatVisitor arrayFormat(JavaType convertedType); + public JsonStringFormatVisitor stringFormat(JavaType convertedType); + public JsonNumberFormatVisitor numberFormat(JavaType convertedType); + public JsonIntegerFormatVisitor integerFormat(JavaType convertedType); + public JsonBooleanFormatVisitor booleanFormat(JavaType convertedType); + public JsonNullFormatVisitor nullFormat(JavaType convertedType); + public JsonAnyFormatVisitor anyFormat(JavaType convertedType); public SerializerProvider getProvider(); public abstract void setProvider(SerializerProvider provider); diff --git a/src/main/java/com/fasterxml/jackson/databind/jsonschema/visitors/JsonNumberFormatVisitor.java b/src/main/java/com/fasterxml/jackson/databind/jsonschema/visitors/JsonNumberFormatVisitor.java index 78e5064f32..a06e19f6de 100644 --- a/src/main/java/com/fasterxml/jackson/databind/jsonschema/visitors/JsonNumberFormatVisitor.java +++ b/src/main/java/com/fasterxml/jackson/databind/jsonschema/visitors/JsonNumberFormatVisitor.java @@ -1,6 +1,5 @@ package com.fasterxml.jackson.databind.jsonschema.visitors; -import com.fasterxml.jackson.databind.jsonschema.types.JsonValueFormat; public interface JsonNumberFormatVisitor extends JsonValueFormatVisitor{ diff --git a/src/main/java/com/fasterxml/jackson/databind/ser/DefaultSerializerProvider.java b/src/main/java/com/fasterxml/jackson/databind/ser/DefaultSerializerProvider.java index 985e8b0574..c60560f016 100644 --- a/src/main/java/com/fasterxml/jackson/databind/ser/DefaultSerializerProvider.java +++ b/src/main/java/com/fasterxml/jackson/databind/ser/DefaultSerializerProvider.java @@ -249,7 +249,7 @@ public void acceptJsonFormatVisitor(Class type, JsonFormatVisitor visitor) if (ser instanceof JsonFormatVisitorAware) { ((JsonFormatVisitorAware) ser).acceptJsonFormatVisitor(visitor, constructType(type)); } else { - visitor.anyFormat(); + visitor.anyFormat(constructType(type)); } } /** diff --git a/src/main/java/com/fasterxml/jackson/databind/ser/impl/UnknownSerializer.java b/src/main/java/com/fasterxml/jackson/databind/ser/impl/UnknownSerializer.java index 800ccc41f7..de231d8193 100644 --- a/src/main/java/com/fasterxml/jackson/databind/ser/impl/UnknownSerializer.java +++ b/src/main/java/com/fasterxml/jackson/databind/ser/impl/UnknownSerializer.java @@ -43,7 +43,7 @@ public final void serializeWithType(Object value, JsonGenerator jgen, Serializer @Override public void acceptJsonFormatVisitor(JsonFormatVisitor visitor, JavaType typeHint) { - visitor.anyFormat(); + visitor.anyFormat(typeHint); } protected void failForEmpty(Object value) throws JsonMappingException diff --git a/src/main/java/com/fasterxml/jackson/databind/ser/std/ArraySerializerBase.java b/src/main/java/com/fasterxml/jackson/databind/ser/std/ArraySerializerBase.java index 15073c3057..7801c82743 100644 --- a/src/main/java/com/fasterxml/jackson/databind/ser/std/ArraySerializerBase.java +++ b/src/main/java/com/fasterxml/jackson/databind/ser/std/ArraySerializerBase.java @@ -2,11 +2,13 @@ import java.io.IOException; -import com.fasterxml.jackson.core.*; - -import com.fasterxml.jackson.databind.*; +import com.fasterxml.jackson.core.JsonGenerationException; +import com.fasterxml.jackson.core.JsonGenerator; +import com.fasterxml.jackson.databind.BeanProperty; +import com.fasterxml.jackson.databind.SerializationFeature; +import com.fasterxml.jackson.databind.SerializerProvider; import com.fasterxml.jackson.databind.jsontype.TypeSerializer; -import com.fasterxml.jackson.databind.ser.*; +import com.fasterxml.jackson.databind.ser.ContainerSerializer; /** * Intermediate base class for serializers used for various diff --git a/src/main/java/com/fasterxml/jackson/databind/ser/std/AsArraySerializerBase.java b/src/main/java/com/fasterxml/jackson/databind/ser/std/AsArraySerializerBase.java index 71b4ff67c8..36ac786416 100644 --- a/src/main/java/com/fasterxml/jackson/databind/ser/std/AsArraySerializerBase.java +++ b/src/main/java/com/fasterxml/jackson/databind/ser/std/AsArraySerializerBase.java @@ -4,9 +4,15 @@ import java.lang.reflect.ParameterizedType; import java.lang.reflect.Type; -import com.fasterxml.jackson.core.*; - -import com.fasterxml.jackson.databind.*; +import com.fasterxml.jackson.core.JsonGenerationException; +import com.fasterxml.jackson.core.JsonGenerator; +import com.fasterxml.jackson.databind.BeanProperty; +import com.fasterxml.jackson.databind.JavaType; +import com.fasterxml.jackson.databind.JsonMappingException; +import com.fasterxml.jackson.databind.JsonNode; +import com.fasterxml.jackson.databind.JsonSerializer; +import com.fasterxml.jackson.databind.SerializationFeature; +import com.fasterxml.jackson.databind.SerializerProvider; import com.fasterxml.jackson.databind.jsonschema.visitors.JsonArrayFormatVisitor; import com.fasterxml.jackson.databind.jsonschema.visitors.JsonFormatVisitor; import com.fasterxml.jackson.databind.jsontype.TypeSerializer; diff --git a/src/main/java/com/fasterxml/jackson/databind/ser/std/BeanSerializerBase.java b/src/main/java/com/fasterxml/jackson/databind/ser/std/BeanSerializerBase.java index 3474f20d40..3163555828 100644 --- a/src/main/java/com/fasterxml/jackson/databind/ser/std/BeanSerializerBase.java +++ b/src/main/java/com/fasterxml/jackson/databind/ser/std/BeanSerializerBase.java @@ -1,15 +1,22 @@ package com.fasterxml.jackson.databind.ser.std; import java.io.IOException; -import java.util.*; +import java.util.ArrayList; +import java.util.HashSet; import com.fasterxml.jackson.annotation.JsonFormat; import com.fasterxml.jackson.annotation.ObjectIdGenerator; import com.fasterxml.jackson.annotation.ObjectIdGenerators; -import com.fasterxml.jackson.core.*; +import com.fasterxml.jackson.core.JsonGenerationException; +import com.fasterxml.jackson.core.JsonGenerator; import com.fasterxml.jackson.core.io.SerializedString; - -import com.fasterxml.jackson.databind.*; +import com.fasterxml.jackson.databind.AnnotationIntrospector; +import com.fasterxml.jackson.databind.BeanProperty; +import com.fasterxml.jackson.databind.JavaType; +import com.fasterxml.jackson.databind.JsonMappingException; +import com.fasterxml.jackson.databind.JsonNode; +import com.fasterxml.jackson.databind.JsonSerializer; +import com.fasterxml.jackson.databind.SerializerProvider; import com.fasterxml.jackson.databind.introspect.Annotated; import com.fasterxml.jackson.databind.introspect.AnnotatedMember; import com.fasterxml.jackson.databind.introspect.ObjectIdInfo; @@ -18,11 +25,17 @@ import com.fasterxml.jackson.databind.jsonschema.visitors.JsonObjectFormatVisitor; import com.fasterxml.jackson.databind.jsontype.TypeSerializer; import com.fasterxml.jackson.databind.node.ObjectNode; -import com.fasterxml.jackson.databind.ser.*; +import com.fasterxml.jackson.databind.ser.AnyGetterWriter; +import com.fasterxml.jackson.databind.ser.BeanPropertyFilter; +import com.fasterxml.jackson.databind.ser.BeanPropertyWriter; +import com.fasterxml.jackson.databind.ser.BeanSerializerBuilder; +import com.fasterxml.jackson.databind.ser.ContainerSerializer; +import com.fasterxml.jackson.databind.ser.ContextualSerializer; +import com.fasterxml.jackson.databind.ser.FilterProvider; +import com.fasterxml.jackson.databind.ser.ResolvableSerializer; import com.fasterxml.jackson.databind.ser.impl.ObjectIdWriter; import com.fasterxml.jackson.databind.ser.impl.PropertyBasedObjectIdGenerator; import com.fasterxml.jackson.databind.ser.impl.WritableObjectId; -import com.fasterxml.jackson.databind.type.TypeFactory; import com.fasterxml.jackson.databind.util.ArrayBuilders; import com.fasterxml.jackson.databind.util.NameTransformer; diff --git a/src/main/java/com/fasterxml/jackson/databind/ser/std/BooleanSerializer.java b/src/main/java/com/fasterxml/jackson/databind/ser/std/BooleanSerializer.java index 3c11db1f99..e603a2a72e 100644 --- a/src/main/java/com/fasterxml/jackson/databind/ser/std/BooleanSerializer.java +++ b/src/main/java/com/fasterxml/jackson/databind/ser/std/BooleanSerializer.java @@ -4,9 +4,7 @@ import com.fasterxml.jackson.core.JsonGenerationException; import com.fasterxml.jackson.core.JsonGenerator; - import com.fasterxml.jackson.databind.JavaType; -import com.fasterxml.jackson.databind.JsonNode; import com.fasterxml.jackson.databind.SerializerProvider; import com.fasterxml.jackson.databind.annotation.JacksonStdImpl; import com.fasterxml.jackson.databind.jsonschema.visitors.JsonFormatVisitor; @@ -44,6 +42,6 @@ public void serialize(Boolean value, JsonGenerator jgen, SerializerProvider prov @Override public void acceptJsonFormatVisitor(JsonFormatVisitor visitor, JavaType typeHint) { - visitor.booleanFormat(); + visitor.booleanFormat(typeHint); } } \ No newline at end of file diff --git a/src/main/java/com/fasterxml/jackson/databind/ser/std/CalendarSerializer.java b/src/main/java/com/fasterxml/jackson/databind/ser/std/CalendarSerializer.java index 847a93b298..eb4c77f702 100644 --- a/src/main/java/com/fasterxml/jackson/databind/ser/std/CalendarSerializer.java +++ b/src/main/java/com/fasterxml/jackson/databind/ser/std/CalendarSerializer.java @@ -4,8 +4,8 @@ import java.text.DateFormat; import java.util.Calendar; -import com.fasterxml.jackson.core.*; - +import com.fasterxml.jackson.core.JsonGenerationException; +import com.fasterxml.jackson.core.JsonGenerator; import com.fasterxml.jackson.databind.SerializerProvider; import com.fasterxml.jackson.databind.annotation.JacksonStdImpl; diff --git a/src/main/java/com/fasterxml/jackson/databind/ser/std/CollectionSerializer.java b/src/main/java/com/fasterxml/jackson/databind/ser/std/CollectionSerializer.java index 2e85d39277..06e1b89a58 100644 --- a/src/main/java/com/fasterxml/jackson/databind/ser/std/CollectionSerializer.java +++ b/src/main/java/com/fasterxml/jackson/databind/ser/std/CollectionSerializer.java @@ -4,7 +4,8 @@ import java.util.Collection; import java.util.Iterator; -import com.fasterxml.jackson.core.*; +import com.fasterxml.jackson.core.JsonGenerationException; +import com.fasterxml.jackson.core.JsonGenerator; import com.fasterxml.jackson.databind.BeanProperty; import com.fasterxml.jackson.databind.JavaType; import com.fasterxml.jackson.databind.JsonSerializer; diff --git a/src/main/java/com/fasterxml/jackson/databind/ser/std/DateSerializer.java b/src/main/java/com/fasterxml/jackson/databind/ser/std/DateSerializer.java index 8834edd22d..6ea25e0921 100644 --- a/src/main/java/com/fasterxml/jackson/databind/ser/std/DateSerializer.java +++ b/src/main/java/com/fasterxml/jackson/databind/ser/std/DateSerializer.java @@ -2,11 +2,11 @@ import java.io.IOException; import java.text.DateFormat; -import java.util.*; +import java.util.Date; -import com.fasterxml.jackson.core.*; - -import com.fasterxml.jackson.databind.*; +import com.fasterxml.jackson.core.JsonGenerationException; +import com.fasterxml.jackson.core.JsonGenerator; +import com.fasterxml.jackson.databind.SerializerProvider; import com.fasterxml.jackson.databind.annotation.JacksonStdImpl; /** diff --git a/src/main/java/com/fasterxml/jackson/databind/ser/std/DateTimeSerializerBase.java b/src/main/java/com/fasterxml/jackson/databind/ser/std/DateTimeSerializerBase.java index 31f5910c67..634d5982fa 100644 --- a/src/main/java/com/fasterxml/jackson/databind/ser/std/DateTimeSerializerBase.java +++ b/src/main/java/com/fasterxml/jackson/databind/ser/std/DateTimeSerializerBase.java @@ -9,7 +9,12 @@ import com.fasterxml.jackson.annotation.JsonFormat; import com.fasterxml.jackson.core.JsonGenerationException; import com.fasterxml.jackson.core.JsonGenerator; -import com.fasterxml.jackson.databind.*; +import com.fasterxml.jackson.databind.BeanProperty; +import com.fasterxml.jackson.databind.JavaType; +import com.fasterxml.jackson.databind.JsonMappingException; +import com.fasterxml.jackson.databind.JsonSerializer; +import com.fasterxml.jackson.databind.SerializationFeature; +import com.fasterxml.jackson.databind.SerializerProvider; import com.fasterxml.jackson.databind.introspect.Annotated; import com.fasterxml.jackson.databind.jsonschema.types.JsonValueFormat; import com.fasterxml.jackson.databind.jsonschema.visitors.JsonFormatVisitor; @@ -111,9 +116,9 @@ public void acceptJsonFormatVisitor(JsonFormatVisitor visitor, JavaType typeHint } } if (asNumber) { - visitor.numberFormat().format(JsonValueFormat.UTC_MILLISEC); + visitor.numberFormat(typeHint).format(JsonValueFormat.UTC_MILLISEC); } else { - visitor.stringFormat().format(JsonValueFormat.DATE_TIME); + visitor.stringFormat(typeHint).format(JsonValueFormat.DATE_TIME); } } diff --git a/src/main/java/com/fasterxml/jackson/databind/ser/std/EnumMapSerializer.java b/src/main/java/com/fasterxml/jackson/databind/ser/std/EnumMapSerializer.java index 59431819c7..2e761b94af 100644 --- a/src/main/java/com/fasterxml/jackson/databind/ser/std/EnumMapSerializer.java +++ b/src/main/java/com/fasterxml/jackson/databind/ser/std/EnumMapSerializer.java @@ -3,12 +3,16 @@ import java.io.IOException; import java.lang.reflect.ParameterizedType; import java.lang.reflect.Type; -import java.util.*; +import java.util.EnumMap; +import java.util.Map; -import com.fasterxml.jackson.core.*; - - -import com.fasterxml.jackson.databind.*; +import com.fasterxml.jackson.core.JsonGenerationException; +import com.fasterxml.jackson.core.JsonGenerator; +import com.fasterxml.jackson.databind.BeanProperty; +import com.fasterxml.jackson.databind.JavaType; +import com.fasterxml.jackson.databind.JsonMappingException; +import com.fasterxml.jackson.databind.JsonSerializer; +import com.fasterxml.jackson.databind.SerializerProvider; import com.fasterxml.jackson.databind.annotation.JacksonStdImpl; import com.fasterxml.jackson.databind.jsonschema.JsonFormatVisitorAware; import com.fasterxml.jackson.databind.jsonschema.visitors.JsonFormatVisitor; diff --git a/src/main/java/com/fasterxml/jackson/databind/ser/std/EnumSerializer.java b/src/main/java/com/fasterxml/jackson/databind/ser/std/EnumSerializer.java index 59d09eba17..ecbd02168d 100644 --- a/src/main/java/com/fasterxml/jackson/databind/ser/std/EnumSerializer.java +++ b/src/main/java/com/fasterxml/jackson/databind/ser/std/EnumSerializer.java @@ -4,17 +4,18 @@ import java.util.HashSet; import java.util.Set; -import com.fasterxml.jackson.core.*; +import com.fasterxml.jackson.core.JsonGenerationException; +import com.fasterxml.jackson.core.JsonGenerator; import com.fasterxml.jackson.core.io.SerializedString; - - -import com.fasterxml.jackson.databind.*; +import com.fasterxml.jackson.databind.AnnotationIntrospector; +import com.fasterxml.jackson.databind.BeanDescription; +import com.fasterxml.jackson.databind.JavaType; +import com.fasterxml.jackson.databind.SerializationConfig; +import com.fasterxml.jackson.databind.SerializationFeature; +import com.fasterxml.jackson.databind.SerializerProvider; import com.fasterxml.jackson.databind.annotation.JacksonStdImpl; import com.fasterxml.jackson.databind.jsonschema.visitors.JsonFormatVisitor; -import com.fasterxml.jackson.databind.jsonschema.visitors.JsonObjectFormatVisitor; import com.fasterxml.jackson.databind.jsonschema.visitors.JsonStringFormatVisitor; -import com.fasterxml.jackson.databind.node.ArrayNode; -import com.fasterxml.jackson.databind.node.ObjectNode; import com.fasterxml.jackson.databind.util.EnumValues; /** @@ -68,9 +69,9 @@ public void acceptJsonFormatVisitor(JsonFormatVisitor visitor, JavaType typeHint { // [JACKSON-684]: serialize as index? if (visitor.getProvider().isEnabled(SerializationFeature.WRITE_ENUMS_USING_INDEX)) { - visitor.integerFormat(); + visitor.integerFormat(typeHint); } else { - JsonStringFormatVisitor stringVisitor = visitor.stringFormat(); + JsonStringFormatVisitor stringVisitor = visitor.stringFormat(typeHint); if (typeHint != null) { if (typeHint.isEnumType()) { Set enums = new HashSet(); diff --git a/src/main/java/com/fasterxml/jackson/databind/ser/std/EnumSetSerializer.java b/src/main/java/com/fasterxml/jackson/databind/ser/std/EnumSetSerializer.java index e1edbf6c4b..db7cd7597e 100644 --- a/src/main/java/com/fasterxml/jackson/databind/ser/std/EnumSetSerializer.java +++ b/src/main/java/com/fasterxml/jackson/databind/ser/std/EnumSetSerializer.java @@ -3,9 +3,12 @@ import java.io.IOException; import java.util.EnumSet; -import com.fasterxml.jackson.core.*; - -import com.fasterxml.jackson.databind.*; +import com.fasterxml.jackson.core.JsonGenerationException; +import com.fasterxml.jackson.core.JsonGenerator; +import com.fasterxml.jackson.databind.BeanProperty; +import com.fasterxml.jackson.databind.JavaType; +import com.fasterxml.jackson.databind.JsonSerializer; +import com.fasterxml.jackson.databind.SerializerProvider; import com.fasterxml.jackson.databind.jsontype.TypeSerializer; public class EnumSetSerializer diff --git a/src/main/java/com/fasterxml/jackson/databind/ser/std/InetAddressSerializer.java b/src/main/java/com/fasterxml/jackson/databind/ser/std/InetAddressSerializer.java index 834a2e7488..8371f775ab 100644 --- a/src/main/java/com/fasterxml/jackson/databind/ser/std/InetAddressSerializer.java +++ b/src/main/java/com/fasterxml/jackson/databind/ser/std/InetAddressSerializer.java @@ -3,8 +3,8 @@ import java.io.IOException; import java.net.InetAddress; -import com.fasterxml.jackson.core.*; - +import com.fasterxml.jackson.core.JsonGenerationException; +import com.fasterxml.jackson.core.JsonGenerator; import com.fasterxml.jackson.databind.SerializerProvider; import com.fasterxml.jackson.databind.jsontype.TypeSerializer; diff --git a/src/main/java/com/fasterxml/jackson/databind/ser/std/IterableSerializer.java b/src/main/java/com/fasterxml/jackson/databind/ser/std/IterableSerializer.java index aa65e10cf0..962864a839 100644 --- a/src/main/java/com/fasterxml/jackson/databind/ser/std/IterableSerializer.java +++ b/src/main/java/com/fasterxml/jackson/databind/ser/std/IterableSerializer.java @@ -3,8 +3,8 @@ import java.io.IOException; import java.util.Iterator; -import com.fasterxml.jackson.core.*; - +import com.fasterxml.jackson.core.JsonGenerationException; +import com.fasterxml.jackson.core.JsonGenerator; import com.fasterxml.jackson.databind.BeanProperty; import com.fasterxml.jackson.databind.JavaType; import com.fasterxml.jackson.databind.JsonSerializer; diff --git a/src/main/java/com/fasterxml/jackson/databind/ser/std/JsonValueSerializer.java b/src/main/java/com/fasterxml/jackson/databind/ser/std/JsonValueSerializer.java index 39337096d8..e3c66c918f 100644 --- a/src/main/java/com/fasterxml/jackson/databind/ser/std/JsonValueSerializer.java +++ b/src/main/java/com/fasterxml/jackson/databind/ser/std/JsonValueSerializer.java @@ -5,9 +5,15 @@ import java.lang.reflect.Method; import java.lang.reflect.Modifier; -import com.fasterxml.jackson.core.*; - -import com.fasterxml.jackson.databind.*; +import com.fasterxml.jackson.core.JsonGenerationException; +import com.fasterxml.jackson.core.JsonGenerator; +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.databind.BeanProperty; +import com.fasterxml.jackson.databind.JavaType; +import com.fasterxml.jackson.databind.JsonMappingException; +import com.fasterxml.jackson.databind.JsonSerializer; +import com.fasterxml.jackson.databind.MapperFeature; +import com.fasterxml.jackson.databind.SerializerProvider; import com.fasterxml.jackson.databind.annotation.JacksonStdImpl; import com.fasterxml.jackson.databind.jsonschema.JsonFormatVisitorAware; import com.fasterxml.jackson.databind.jsonschema.visitors.JsonFormatVisitor; @@ -234,7 +240,7 @@ public void acceptJsonFormatVisitor(JsonFormatVisitor visitor, JavaType typeHint if (_valueSerializer instanceof JsonFormatVisitorAware) { ((JsonFormatVisitorAware) _valueSerializer).acceptJsonFormatVisitor(visitor, null); } else { - visitor.anyFormat(); + visitor.anyFormat(typeHint); } } diff --git a/src/main/java/com/fasterxml/jackson/databind/ser/std/MapSerializer.java b/src/main/java/com/fasterxml/jackson/databind/ser/std/MapSerializer.java index d09da061c9..6a749ea42c 100644 --- a/src/main/java/com/fasterxml/jackson/databind/ser/std/MapSerializer.java +++ b/src/main/java/com/fasterxml/jackson/databind/ser/std/MapSerializer.java @@ -1,16 +1,23 @@ package com.fasterxml.jackson.databind.ser.std; import java.io.IOException; -import java.util.*; - -import com.fasterxml.jackson.core.*; - - -import com.fasterxml.jackson.databind.*; +import java.util.HashSet; +import java.util.Map; +import java.util.SortedMap; +import java.util.TreeMap; + +import com.fasterxml.jackson.core.JsonGenerationException; +import com.fasterxml.jackson.core.JsonGenerator; +import com.fasterxml.jackson.databind.AnnotationIntrospector; +import com.fasterxml.jackson.databind.BeanProperty; +import com.fasterxml.jackson.databind.JavaType; +import com.fasterxml.jackson.databind.JsonMappingException; +import com.fasterxml.jackson.databind.JsonSerializer; +import com.fasterxml.jackson.databind.SerializationFeature; +import com.fasterxml.jackson.databind.SerializerProvider; import com.fasterxml.jackson.databind.annotation.JacksonStdImpl; import com.fasterxml.jackson.databind.jsonschema.visitors.JsonFormatVisitor; import com.fasterxml.jackson.databind.jsontype.TypeSerializer; -import com.fasterxml.jackson.databind.node.ObjectNode; import com.fasterxml.jackson.databind.ser.ContainerSerializer; import com.fasterxml.jackson.databind.ser.ContextualSerializer; import com.fasterxml.jackson.databind.ser.impl.PropertySerializerMap; diff --git a/src/main/java/com/fasterxml/jackson/databind/ser/std/NonTypedScalarSerializerBase.java b/src/main/java/com/fasterxml/jackson/databind/ser/std/NonTypedScalarSerializerBase.java index 16050e55b3..2d4da7f72c 100644 --- a/src/main/java/com/fasterxml/jackson/databind/ser/std/NonTypedScalarSerializerBase.java +++ b/src/main/java/com/fasterxml/jackson/databind/ser/std/NonTypedScalarSerializerBase.java @@ -2,8 +2,8 @@ import java.io.IOException; -import com.fasterxml.jackson.core.*; - +import com.fasterxml.jackson.core.JsonGenerationException; +import com.fasterxml.jackson.core.JsonGenerator; import com.fasterxml.jackson.databind.SerializerProvider; import com.fasterxml.jackson.databind.jsontype.TypeSerializer; diff --git a/src/main/java/com/fasterxml/jackson/databind/ser/std/NullSerializer.java b/src/main/java/com/fasterxml/jackson/databind/ser/std/NullSerializer.java index b2f675e38b..046ddf2147 100644 --- a/src/main/java/com/fasterxml/jackson/databind/ser/std/NullSerializer.java +++ b/src/main/java/com/fasterxml/jackson/databind/ser/std/NullSerializer.java @@ -2,9 +2,10 @@ import java.io.IOException; -import com.fasterxml.jackson.core.*; - -import com.fasterxml.jackson.databind.*; +import com.fasterxml.jackson.core.JsonGenerationException; +import com.fasterxml.jackson.core.JsonGenerator; +import com.fasterxml.jackson.databind.JavaType; +import com.fasterxml.jackson.databind.SerializerProvider; import com.fasterxml.jackson.databind.annotation.JacksonStdImpl; import com.fasterxml.jackson.databind.jsonschema.visitors.JsonFormatVisitor; @@ -33,6 +34,6 @@ public void serialize(Object value, JsonGenerator jgen, SerializerProvider provi @Override public void acceptJsonFormatVisitor(JsonFormatVisitor visitor, JavaType typeHint) { - visitor.nullFormat(); + visitor.nullFormat(typeHint); } } diff --git a/src/main/java/com/fasterxml/jackson/databind/ser/std/NumberSerializers.java b/src/main/java/com/fasterxml/jackson/databind/ser/std/NumberSerializers.java index db5c679daf..de3583cb4b 100644 --- a/src/main/java/com/fasterxml/jackson/databind/ser/std/NumberSerializers.java +++ b/src/main/java/com/fasterxml/jackson/databind/ser/std/NumberSerializers.java @@ -5,8 +5,11 @@ import java.math.BigInteger; import java.util.Map; -import com.fasterxml.jackson.core.*; -import com.fasterxml.jackson.databind.*; +import com.fasterxml.jackson.core.JsonGenerationException; +import com.fasterxml.jackson.core.JsonGenerator; +import com.fasterxml.jackson.databind.JavaType; +import com.fasterxml.jackson.databind.JsonSerializer; +import com.fasterxml.jackson.databind.SerializerProvider; import com.fasterxml.jackson.databind.annotation.JacksonStdImpl; import com.fasterxml.jackson.databind.jsonschema.visitors.JsonFormatVisitor; @@ -73,7 +76,7 @@ public void serialize(Integer value, JsonGenerator jgen, SerializerProvider prov @Override public void acceptJsonFormatVisitor(JsonFormatVisitor visitor, JavaType typeHint) { - visitor.integerFormat(); + visitor.integerFormat(typeHint); } } @@ -100,7 +103,7 @@ public void serialize(Number value, JsonGenerator jgen, SerializerProvider provi @Override public void acceptJsonFormatVisitor(JsonFormatVisitor visitor, JavaType typeHint) { - visitor.integerFormat(); + visitor.integerFormat(typeHint); } } @@ -122,7 +125,7 @@ public void serialize(Long value, JsonGenerator jgen, SerializerProvider provide @Override public void acceptJsonFormatVisitor(JsonFormatVisitor visitor, JavaType typeHint) { - visitor.numberFormat(); + visitor.numberFormat(typeHint); } } @@ -144,7 +147,7 @@ public void serialize(Float value, JsonGenerator jgen, SerializerProvider provid @Override public void acceptJsonFormatVisitor(JsonFormatVisitor visitor, JavaType typeHint) { - visitor.numberFormat(); + visitor.numberFormat(typeHint); } } @@ -173,7 +176,7 @@ public void serialize(Double value, JsonGenerator jgen, SerializerProvider provi @Override public void acceptJsonFormatVisitor(JsonFormatVisitor visitor, JavaType typeHint) { - visitor.numberFormat(); + visitor.numberFormat(typeHint); } } @@ -221,7 +224,7 @@ public void serialize(Number value, JsonGenerator jgen, SerializerProvider provi @Override public void acceptJsonFormatVisitor(JsonFormatVisitor visitor, JavaType typeHint) { - visitor.numberFormat(); + visitor.numberFormat(typeHint); } } } diff --git a/src/main/java/com/fasterxml/jackson/databind/ser/std/ObjectArraySerializer.java b/src/main/java/com/fasterxml/jackson/databind/ser/std/ObjectArraySerializer.java index 9e4e0bd3d8..8be2b55502 100644 --- a/src/main/java/com/fasterxml/jackson/databind/ser/std/ObjectArraySerializer.java +++ b/src/main/java/com/fasterxml/jackson/databind/ser/std/ObjectArraySerializer.java @@ -3,9 +3,13 @@ import java.io.IOException; import java.lang.reflect.InvocationTargetException; -import com.fasterxml.jackson.core.*; - -import com.fasterxml.jackson.databind.*; +import com.fasterxml.jackson.core.JsonGenerationException; +import com.fasterxml.jackson.core.JsonGenerator; +import com.fasterxml.jackson.databind.BeanProperty; +import com.fasterxml.jackson.databind.JavaType; +import com.fasterxml.jackson.databind.JsonMappingException; +import com.fasterxml.jackson.databind.JsonSerializer; +import com.fasterxml.jackson.databind.SerializerProvider; import com.fasterxml.jackson.databind.annotation.JacksonStdImpl; import com.fasterxml.jackson.databind.jsonschema.visitors.JsonFormatVisitor; import com.fasterxml.jackson.databind.jsontype.TypeSerializer; diff --git a/src/main/java/com/fasterxml/jackson/databind/ser/std/RawSerializer.java b/src/main/java/com/fasterxml/jackson/databind/ser/std/RawSerializer.java index 891a86964b..a3ab1aed29 100644 --- a/src/main/java/com/fasterxml/jackson/databind/ser/std/RawSerializer.java +++ b/src/main/java/com/fasterxml/jackson/databind/ser/std/RawSerializer.java @@ -2,9 +2,11 @@ import java.io.IOException; -import com.fasterxml.jackson.core.*; - -import com.fasterxml.jackson.databind.*; +import com.fasterxml.jackson.core.JsonGenerationException; +import com.fasterxml.jackson.core.JsonGenerator; +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.databind.JavaType; +import com.fasterxml.jackson.databind.SerializerProvider; import com.fasterxml.jackson.databind.annotation.JacksonStdImpl; import com.fasterxml.jackson.databind.jsonschema.visitors.JsonFormatVisitor; import com.fasterxml.jackson.databind.jsontype.TypeSerializer; @@ -46,6 +48,6 @@ public void serializeWithType(T value, JsonGenerator jgen, SerializerProvider pr @Override public void acceptJsonFormatVisitor(JsonFormatVisitor visitor, JavaType typeHint) { - visitor.stringFormat(); + visitor.stringFormat(typeHint); } } diff --git a/src/main/java/com/fasterxml/jackson/databind/ser/std/SerializableSerializer.java b/src/main/java/com/fasterxml/jackson/databind/ser/std/SerializableSerializer.java index 2c42d6c142..b53191c64a 100644 --- a/src/main/java/com/fasterxml/jackson/databind/ser/std/SerializableSerializer.java +++ b/src/main/java/com/fasterxml/jackson/databind/ser/std/SerializableSerializer.java @@ -3,9 +3,8 @@ import java.io.IOException; import java.util.concurrent.atomic.AtomicReference; -import com.fasterxml.jackson.core.*; - - +import com.fasterxml.jackson.core.JsonGenerationException; +import com.fasterxml.jackson.core.JsonGenerator; import com.fasterxml.jackson.databind.JavaType; import com.fasterxml.jackson.databind.JsonSerializable; import com.fasterxml.jackson.databind.ObjectMapper; @@ -49,6 +48,6 @@ public final void serializeWithType(JsonSerializable value, JsonGenerator jgen, @Override public void acceptJsonFormatVisitor(JsonFormatVisitor visitor, JavaType typeHint) { - visitor.anyFormat(); + visitor.anyFormat(typeHint); } } diff --git a/src/main/java/com/fasterxml/jackson/databind/ser/std/SqlDateSerializer.java b/src/main/java/com/fasterxml/jackson/databind/ser/std/SqlDateSerializer.java index 2e3be58509..2f7db424d6 100644 --- a/src/main/java/com/fasterxml/jackson/databind/ser/std/SqlDateSerializer.java +++ b/src/main/java/com/fasterxml/jackson/databind/ser/std/SqlDateSerializer.java @@ -4,9 +4,7 @@ import com.fasterxml.jackson.core.JsonGenerationException; import com.fasterxml.jackson.core.JsonGenerator; - import com.fasterxml.jackson.databind.JavaType; -import com.fasterxml.jackson.databind.JsonNode; import com.fasterxml.jackson.databind.SerializerProvider; import com.fasterxml.jackson.databind.annotation.JacksonStdImpl; import com.fasterxml.jackson.databind.jsonschema.types.JsonValueFormat; @@ -33,6 +31,6 @@ public void serialize(java.sql.Date value, JsonGenerator jgen, SerializerProvide @Override public void acceptJsonFormatVisitor(JsonFormatVisitor visitor, JavaType typeHint) { - visitor.stringFormat().format(JsonValueFormat.DATE_TIME); + visitor.stringFormat(typeHint).format(JsonValueFormat.DATE_TIME); } } \ No newline at end of file diff --git a/src/main/java/com/fasterxml/jackson/databind/ser/std/SqlTimeSerializer.java b/src/main/java/com/fasterxml/jackson/databind/ser/std/SqlTimeSerializer.java index 25f6fb218e..7726f241ce 100644 --- a/src/main/java/com/fasterxml/jackson/databind/ser/std/SqlTimeSerializer.java +++ b/src/main/java/com/fasterxml/jackson/databind/ser/std/SqlTimeSerializer.java @@ -4,9 +4,7 @@ import com.fasterxml.jackson.core.JsonGenerationException; import com.fasterxml.jackson.core.JsonGenerator; - import com.fasterxml.jackson.databind.JavaType; -import com.fasterxml.jackson.databind.JsonNode; import com.fasterxml.jackson.databind.SerializerProvider; import com.fasterxml.jackson.databind.annotation.JacksonStdImpl; import com.fasterxml.jackson.databind.jsonschema.types.JsonValueFormat; @@ -28,6 +26,6 @@ public void serialize(java.sql.Time value, JsonGenerator jgen, SerializerProvide @Override public void acceptJsonFormatVisitor(JsonFormatVisitor visitor, JavaType typeHint) { - visitor.stringFormat().format(JsonValueFormat.DATE_TIME); + visitor.stringFormat(typeHint).format(JsonValueFormat.DATE_TIME); } } \ No newline at end of file diff --git a/src/main/java/com/fasterxml/jackson/databind/ser/std/StaticListSerializerBase.java b/src/main/java/com/fasterxml/jackson/databind/ser/std/StaticListSerializerBase.java index 690ff3a71f..f7f5957308 100644 --- a/src/main/java/com/fasterxml/jackson/databind/ser/std/StaticListSerializerBase.java +++ b/src/main/java/com/fasterxml/jackson/databind/ser/std/StaticListSerializerBase.java @@ -1,14 +1,10 @@ package com.fasterxml.jackson.databind.ser.std; -import java.util.*; +import java.util.Collection; import com.fasterxml.jackson.databind.JavaType; -import com.fasterxml.jackson.databind.JsonNode; -import com.fasterxml.jackson.databind.SerializerProvider; -import com.fasterxml.jackson.databind.jsonschema.JsonFormatVisitorAware; import com.fasterxml.jackson.databind.jsonschema.visitors.JsonArrayFormatVisitor; import com.fasterxml.jackson.databind.jsonschema.visitors.JsonFormatVisitor; -import com.fasterxml.jackson.databind.node.ObjectNode; /** * Intermediate base class for Lists, Collections and Arrays diff --git a/src/main/java/com/fasterxml/jackson/databind/ser/std/StdArraySerializers.java b/src/main/java/com/fasterxml/jackson/databind/ser/std/StdArraySerializers.java index cd80815a6c..0e5c133ccc 100644 --- a/src/main/java/com/fasterxml/jackson/databind/ser/std/StdArraySerializers.java +++ b/src/main/java/com/fasterxml/jackson/databind/ser/std/StdArraySerializers.java @@ -3,14 +3,17 @@ import java.io.IOException; import java.util.HashMap; -import com.fasterxml.jackson.core.*; - -import com.fasterxml.jackson.databind.*; +import com.fasterxml.jackson.core.JsonGenerationException; +import com.fasterxml.jackson.core.JsonGenerator; +import com.fasterxml.jackson.databind.BeanProperty; +import com.fasterxml.jackson.databind.JavaType; +import com.fasterxml.jackson.databind.JsonSerializer; +import com.fasterxml.jackson.databind.SerializationFeature; +import com.fasterxml.jackson.databind.SerializerProvider; import com.fasterxml.jackson.databind.annotation.JacksonStdImpl; import com.fasterxml.jackson.databind.jsonschema.types.SchemaType; import com.fasterxml.jackson.databind.jsonschema.visitors.JsonFormatVisitor; import com.fasterxml.jackson.databind.jsontype.TypeSerializer; -import com.fasterxml.jackson.databind.node.ObjectNode; import com.fasterxml.jackson.databind.ser.ContainerSerializer; import com.fasterxml.jackson.databind.type.TypeFactory; diff --git a/src/main/java/com/fasterxml/jackson/databind/ser/std/StdContainerSerializers.java b/src/main/java/com/fasterxml/jackson/databind/ser/std/StdContainerSerializers.java index 5785481faa..c3533e1d50 100644 --- a/src/main/java/com/fasterxml/jackson/databind/ser/std/StdContainerSerializers.java +++ b/src/main/java/com/fasterxml/jackson/databind/ser/std/StdContainerSerializers.java @@ -1,11 +1,12 @@ package com.fasterxml.jackson.databind.ser.std; -import com.fasterxml.jackson.databind.*; +import com.fasterxml.jackson.databind.BeanProperty; +import com.fasterxml.jackson.databind.JavaType; +import com.fasterxml.jackson.databind.JsonSerializer; import com.fasterxml.jackson.databind.jsontype.TypeSerializer; import com.fasterxml.jackson.databind.ser.ContainerSerializer; import com.fasterxml.jackson.databind.ser.impl.IndexedListSerializer; import com.fasterxml.jackson.databind.ser.impl.IteratorSerializer; -import com.fasterxml.jackson.databind.ser.std.CollectionSerializer; /** * Dummy container class to group standard container serializers: serializers diff --git a/src/main/java/com/fasterxml/jackson/databind/ser/std/StdJdkSerializers.java b/src/main/java/com/fasterxml/jackson/databind/ser/std/StdJdkSerializers.java index e3a71a1f46..ad1d4c8751 100644 --- a/src/main/java/com/fasterxml/jackson/databind/ser/std/StdJdkSerializers.java +++ b/src/main/java/com/fasterxml/jackson/databind/ser/std/StdJdkSerializers.java @@ -1,12 +1,22 @@ package com.fasterxml.jackson.databind.ser.std; -import java.io.*; -import java.util.*; -import java.util.concurrent.atomic.*; - -import com.fasterxml.jackson.core.*; - -import com.fasterxml.jackson.databind.*; +import java.io.File; +import java.io.IOException; +import java.util.Collection; +import java.util.Currency; +import java.util.HashMap; +import java.util.Locale; +import java.util.Map; +import java.util.UUID; +import java.util.concurrent.atomic.AtomicBoolean; +import java.util.concurrent.atomic.AtomicInteger; +import java.util.concurrent.atomic.AtomicLong; +import java.util.concurrent.atomic.AtomicReference; + +import com.fasterxml.jackson.core.JsonGenerationException; +import com.fasterxml.jackson.core.JsonGenerator; +import com.fasterxml.jackson.databind.JavaType; +import com.fasterxml.jackson.databind.SerializerProvider; import com.fasterxml.jackson.databind.jsonschema.visitors.JsonFormatVisitor; import com.fasterxml.jackson.databind.ser.BasicSerializerFactory; import com.fasterxml.jackson.databind.util.Provider; @@ -79,7 +89,7 @@ public void serialize(AtomicBoolean value, JsonGenerator jgen, SerializerProvide @Override public void acceptJsonFormatVisitor(JsonFormatVisitor visitor, JavaType typeHint) { - visitor.booleanFormat(); + visitor.booleanFormat(typeHint); } } @@ -98,7 +108,7 @@ public void serialize(AtomicInteger value, JsonGenerator jgen, SerializerProvide @Override public void acceptJsonFormatVisitor(JsonFormatVisitor visitor, JavaType typeHint) { - visitor.integerFormat(); + visitor.integerFormat(typeHint); } } @@ -117,7 +127,7 @@ public void serialize(AtomicLong value, JsonGenerator jgen, SerializerProvider p @Override public void acceptJsonFormatVisitor(JsonFormatVisitor visitor, JavaType typeHint) { - visitor.integerFormat(); + visitor.integerFormat(typeHint); } } @@ -136,7 +146,7 @@ public void serialize(AtomicReference value, JsonGenerator jgen, SerializerPr @Override public void acceptJsonFormatVisitor(JsonFormatVisitor visitor, JavaType typeHint) { - visitor.anyFormat(); + visitor.anyFormat(typeHint); } } @@ -165,7 +175,7 @@ public void serialize(File value, JsonGenerator jgen, SerializerProvider provide @Override public void acceptJsonFormatVisitor(JsonFormatVisitor visitor, JavaType typeHint) { - visitor.stringFormat(); + visitor.stringFormat(typeHint); } } @@ -188,7 +198,7 @@ public void serialize(Class value, JsonGenerator jgen, SerializerProvider pro @Override public void acceptJsonFormatVisitor(JsonFormatVisitor visitor, JavaType typeHint) { - visitor.stringFormat(); + visitor.stringFormat(typeHint); } } } diff --git a/src/main/java/com/fasterxml/jackson/databind/ser/std/StdKeySerializer.java b/src/main/java/com/fasterxml/jackson/databind/ser/std/StdKeySerializer.java index 89d09c7fc0..506de40139 100644 --- a/src/main/java/com/fasterxml/jackson/databind/ser/std/StdKeySerializer.java +++ b/src/main/java/com/fasterxml/jackson/databind/ser/std/StdKeySerializer.java @@ -3,12 +3,11 @@ import java.io.IOException; import java.util.Date; -import com.fasterxml.jackson.core.*; - +import com.fasterxml.jackson.core.JsonGenerationException; +import com.fasterxml.jackson.core.JsonGenerator; import com.fasterxml.jackson.databind.JavaType; import com.fasterxml.jackson.databind.SerializerProvider; import com.fasterxml.jackson.databind.jsonschema.visitors.JsonFormatVisitor; -import com.fasterxml.jackson.databind.ser.std.StdSerializer; /** * Specialized serializer that can be used as the generic key @@ -36,6 +35,6 @@ public void serialize(Object value, JsonGenerator jgen, SerializerProvider provi @Override public void acceptJsonFormatVisitor(JsonFormatVisitor visitor, JavaType typeHint) { - visitor.stringFormat(); + visitor.stringFormat(typeHint); } } diff --git a/src/main/java/com/fasterxml/jackson/databind/ser/std/StdKeySerializers.java b/src/main/java/com/fasterxml/jackson/databind/ser/std/StdKeySerializers.java index fe73e800b8..bcb91e89d9 100644 --- a/src/main/java/com/fasterxml/jackson/databind/ser/std/StdKeySerializers.java +++ b/src/main/java/com/fasterxml/jackson/databind/ser/std/StdKeySerializers.java @@ -4,8 +4,8 @@ import java.util.Calendar; import java.util.Date; -import com.fasterxml.jackson.core.*; - +import com.fasterxml.jackson.core.JsonGenerationException; +import com.fasterxml.jackson.core.JsonGenerator; import com.fasterxml.jackson.databind.JavaType; import com.fasterxml.jackson.databind.JsonSerializer; import com.fasterxml.jackson.databind.SerializerProvider; diff --git a/src/main/java/com/fasterxml/jackson/databind/ser/std/StdScalarSerializer.java b/src/main/java/com/fasterxml/jackson/databind/ser/std/StdScalarSerializer.java index 5ba8789ca2..a51149857f 100644 --- a/src/main/java/com/fasterxml/jackson/databind/ser/std/StdScalarSerializer.java +++ b/src/main/java/com/fasterxml/jackson/databind/ser/std/StdScalarSerializer.java @@ -2,11 +2,9 @@ import java.io.IOException; -import com.fasterxml.jackson.core.*; - +import com.fasterxml.jackson.core.JsonGenerationException; +import com.fasterxml.jackson.core.JsonGenerator; import com.fasterxml.jackson.databind.JavaType; -import com.fasterxml.jackson.databind.JsonMappingException; -import com.fasterxml.jackson.databind.JsonNode; import com.fasterxml.jackson.databind.SerializerProvider; import com.fasterxml.jackson.databind.jsonschema.visitors.JsonFormatVisitor; import com.fasterxml.jackson.databind.jsontype.TypeSerializer; @@ -47,6 +45,6 @@ public void serializeWithType(T value, JsonGenerator jgen, SerializerProvider pr @Override public void acceptJsonFormatVisitor(JsonFormatVisitor visitor, JavaType typeHint) { - visitor.anyFormat(); + visitor.anyFormat(typeHint); } } diff --git a/src/main/java/com/fasterxml/jackson/databind/ser/std/StdSerializer.java b/src/main/java/com/fasterxml/jackson/databind/ser/std/StdSerializer.java index 08d6f0f34e..8110b731c0 100644 --- a/src/main/java/com/fasterxml/jackson/databind/ser/std/StdSerializer.java +++ b/src/main/java/com/fasterxml/jackson/databind/ser/std/StdSerializer.java @@ -3,13 +3,16 @@ import java.io.IOException; import java.lang.reflect.InvocationTargetException; -import com.fasterxml.jackson.core.*; -import com.fasterxml.jackson.databind.*; +import com.fasterxml.jackson.core.JsonGenerationException; +import com.fasterxml.jackson.core.JsonGenerator; +import com.fasterxml.jackson.databind.JavaType; +import com.fasterxml.jackson.databind.JsonMappingException; +import com.fasterxml.jackson.databind.JsonSerializer; +import com.fasterxml.jackson.databind.SerializationFeature; +import com.fasterxml.jackson.databind.SerializerProvider; import com.fasterxml.jackson.databind.annotation.JacksonStdImpl; import com.fasterxml.jackson.databind.jsonschema.JsonFormatVisitorAware; import com.fasterxml.jackson.databind.jsonschema.visitors.JsonFormatVisitor; -import com.fasterxml.jackson.databind.node.JsonNodeFactory; -import com.fasterxml.jackson.databind.node.ObjectNode; /** * Base class used by all standard serializers, and can also @@ -81,7 +84,7 @@ public abstract void serialize(T value, JsonGenerator jgen, SerializerProvider p */ // @Override public void acceptJsonFormatVisitor(JsonFormatVisitor visitor, JavaType typeHint) { - visitor.anyFormat(); + visitor.anyFormat(typeHint); } /* diff --git a/src/main/java/com/fasterxml/jackson/databind/ser/std/StringSerializer.java b/src/main/java/com/fasterxml/jackson/databind/ser/std/StringSerializer.java index d03a05660c..1012fda1cc 100644 --- a/src/main/java/com/fasterxml/jackson/databind/ser/std/StringSerializer.java +++ b/src/main/java/com/fasterxml/jackson/databind/ser/std/StringSerializer.java @@ -2,8 +2,8 @@ import java.io.IOException; -import com.fasterxml.jackson.core.*; - +import com.fasterxml.jackson.core.JsonGenerationException; +import com.fasterxml.jackson.core.JsonGenerator; import com.fasterxml.jackson.databind.JavaType; import com.fasterxml.jackson.databind.SerializerProvider; import com.fasterxml.jackson.databind.annotation.JacksonStdImpl; @@ -39,6 +39,6 @@ public void serialize(String value, JsonGenerator jgen, SerializerProvider provi @Override public void acceptJsonFormatVisitor(JsonFormatVisitor visitor, JavaType typeHint) { - visitor.stringFormat(); + visitor.stringFormat(typeHint); } } diff --git a/src/main/java/com/fasterxml/jackson/databind/ser/std/TimeZoneSerializer.java b/src/main/java/com/fasterxml/jackson/databind/ser/std/TimeZoneSerializer.java index 71f2bf581a..17eaa67c1c 100644 --- a/src/main/java/com/fasterxml/jackson/databind/ser/std/TimeZoneSerializer.java +++ b/src/main/java/com/fasterxml/jackson/databind/ser/std/TimeZoneSerializer.java @@ -3,8 +3,8 @@ import java.io.IOException; import java.util.TimeZone; -import com.fasterxml.jackson.core.*; - +import com.fasterxml.jackson.core.JsonGenerationException; +import com.fasterxml.jackson.core.JsonGenerator; import com.fasterxml.jackson.databind.SerializerProvider; import com.fasterxml.jackson.databind.jsontype.TypeSerializer; diff --git a/src/main/java/com/fasterxml/jackson/databind/ser/std/ToStringSerializer.java b/src/main/java/com/fasterxml/jackson/databind/ser/std/ToStringSerializer.java index c664a57f52..c4eca61966 100644 --- a/src/main/java/com/fasterxml/jackson/databind/ser/std/ToStringSerializer.java +++ b/src/main/java/com/fasterxml/jackson/databind/ser/std/ToStringSerializer.java @@ -2,11 +2,9 @@ import java.io.IOException; -import com.fasterxml.jackson.core.*; - +import com.fasterxml.jackson.core.JsonGenerationException; +import com.fasterxml.jackson.core.JsonGenerator; import com.fasterxml.jackson.databind.JavaType; -import com.fasterxml.jackson.databind.JsonMappingException; -import com.fasterxml.jackson.databind.JsonNode; import com.fasterxml.jackson.databind.SerializerProvider; import com.fasterxml.jackson.databind.annotation.JacksonStdImpl; import com.fasterxml.jackson.databind.jsonschema.visitors.JsonFormatVisitor; @@ -77,7 +75,7 @@ public void serializeWithType(Object value, JsonGenerator jgen, SerializerProvid @Override public void acceptJsonFormatVisitor(JsonFormatVisitor visitor, JavaType typeHint) { - visitor.stringFormat(); + visitor.stringFormat(typeHint); } } diff --git a/src/main/java/com/fasterxml/jackson/databind/ser/std/TokenBufferSerializer.java b/src/main/java/com/fasterxml/jackson/databind/ser/std/TokenBufferSerializer.java index 55e34f4211..3bf5c8322f 100644 --- a/src/main/java/com/fasterxml/jackson/databind/ser/std/TokenBufferSerializer.java +++ b/src/main/java/com/fasterxml/jackson/databind/ser/std/TokenBufferSerializer.java @@ -2,10 +2,9 @@ import java.io.IOException; -import com.fasterxml.jackson.core.*; - +import com.fasterxml.jackson.core.JsonGenerationException; +import com.fasterxml.jackson.core.JsonGenerator; import com.fasterxml.jackson.databind.JavaType; -import com.fasterxml.jackson.databind.JsonNode; import com.fasterxml.jackson.databind.SerializerProvider; import com.fasterxml.jackson.databind.annotation.JacksonStdImpl; import com.fasterxml.jackson.databind.jsonschema.visitors.JsonFormatVisitor; @@ -60,6 +59,6 @@ public void acceptJsonFormatVisitor(JsonFormatVisitor visitor, JavaType typeHint * type is basically not known. This seems closest * approximation */ - visitor.anyFormat(); + visitor.anyFormat(typeHint); } } diff --git a/src/test/java/com/fasterxml/jackson/databind/module/TestSimpleModule.java b/src/test/java/com/fasterxml/jackson/databind/module/TestSimpleModule.java index b15e208970..2ce4f21518 100644 --- a/src/test/java/com/fasterxml/jackson/databind/module/TestSimpleModule.java +++ b/src/test/java/com/fasterxml/jackson/databind/module/TestSimpleModule.java @@ -53,7 +53,7 @@ public void serialize(CustomBean value, JsonGenerator jgen, SerializerProvider p @Override public void acceptJsonFormatVisitor(JsonFormatVisitor visitor, JavaType typeHint) { - visitor.anyFormat(); + visitor.anyFormat(typeHint); } } @@ -87,7 +87,7 @@ public void serialize(SimpleEnum value, JsonGenerator jgen, SerializerProvider p @Override public void acceptJsonFormatVisitor(JsonFormatVisitor visitor, JavaType typeHint) { - visitor.anyFormat(); + visitor.anyFormat(typeHint); } } From 8e8c6e3f7cb3b842091d78f7b9e56d9e5a6cc811 Mon Sep 17 00:00:00 2001 From: jackphel Date: Tue, 7 Aug 2012 16:25:00 -0400 Subject: [PATCH 14/19] adds new visitor wrapper, which constructs typed visitors Rather than SchemaFactory being an instantiable class, and thus mucking up its methods shared with subtypes, visitorwrapper -> factoryprovider provide access to schemafactory subtypes --- .../jackson/databind/ObjectMapper.java | 4 +- .../databind/ext/CoreXMLSerializers.java | 4 +- .../jackson/databind/ext/DOMSerializer.java | 6 +- .../jsonschema/JsonFormatVisitorAware.java | 4 +- .../jsonschema/SchemaFactoryProvider.java | 89 +++++++++++++++++++ .../factories/AnySchemaFactory.java | 10 +++ .../factories/ArraySchemaFactory.java | 13 ++- .../factories/BooleanSchemaFactory.java | 9 ++ .../factories/IntegerSchemaFactory.java | 9 ++ .../factories/NullSchemaFactory.java | 10 +++ .../factories/NumberSchemaFactory.java | 9 ++ .../factories/ObjectSchemaFactory.java | 17 +++- .../jsonschema/factories/SchemaFactory.java | 67 +------------- .../factories/StringSchemaFactory.java | 9 ++ .../factories/ValueTypeSchemaFactory.java | 9 ++ .../visitors/JsonArrayFormatVisitor.java | 2 +- .../visitors/JsonFormatVisitor.java | 20 ----- ...onFormatVisitorWithSerializerProvider.java | 16 ++++ .../visitors/JsonFormatVisitorWrapper.java | 16 ++++ .../visitors/JsonObjectFormatVisitor.java | 2 +- .../ser/DefaultSerializerProvider.java | 6 +- .../databind/ser/impl/FailingSerializer.java | 4 +- .../ser/impl/StringArraySerializer.java | 6 +- .../databind/ser/impl/UnknownSerializer.java | 6 +- .../ser/std/AsArraySerializerBase.java | 6 +- .../databind/ser/std/BeanSerializerBase.java | 7 +- .../databind/ser/std/BooleanSerializer.java | 6 +- .../ser/std/DateTimeSerializerBase.java | 8 +- .../databind/ser/std/EnumMapSerializer.java | 6 +- .../databind/ser/std/EnumSerializer.java | 8 +- .../databind/ser/std/JsonValueSerializer.java | 6 +- .../databind/ser/std/MapSerializer.java | 6 +- .../databind/ser/std/NullSerializer.java | 6 +- .../databind/ser/std/NumberSerializers.java | 26 +++--- .../ser/std/ObjectArraySerializer.java | 6 +- .../databind/ser/std/RawSerializer.java | 6 +- .../ser/std/SerializableSerializer.java | 6 +- .../databind/ser/std/SqlDateSerializer.java | 6 +- .../databind/ser/std/SqlTimeSerializer.java | 6 +- .../ser/std/StaticListSerializerBase.java | 6 +- .../databind/ser/std/StdArraySerializers.java | 34 +++---- .../databind/ser/std/StdJdkSerializers.java | 26 +++--- .../databind/ser/std/StdKeySerializer.java | 6 +- .../databind/ser/std/StdScalarSerializer.java | 6 +- .../databind/ser/std/StdSerializer.java | 6 +- .../databind/ser/std/StringSerializer.java | 6 +- .../databind/ser/std/ToStringSerializer.java | 6 +- .../ser/std/TokenBufferSerializer.java | 6 +- .../jsonschema/TestGenerateJsonSchema.java | 12 +-- .../jsonschema/TestReadJsonSchema.java | 2 +- .../databind/module/TestSimpleModule.java | 10 +-- 51 files changed, 359 insertions(+), 229 deletions(-) create mode 100644 src/main/java/com/fasterxml/jackson/databind/jsonschema/SchemaFactoryProvider.java delete mode 100644 src/main/java/com/fasterxml/jackson/databind/jsonschema/visitors/JsonFormatVisitor.java create mode 100644 src/main/java/com/fasterxml/jackson/databind/jsonschema/visitors/JsonFormatVisitorWithSerializerProvider.java create mode 100644 src/main/java/com/fasterxml/jackson/databind/jsonschema/visitors/JsonFormatVisitorWrapper.java diff --git a/src/main/java/com/fasterxml/jackson/databind/ObjectMapper.java b/src/main/java/com/fasterxml/jackson/databind/ObjectMapper.java index 1e71a1dcaa..bef21be0d8 100644 --- a/src/main/java/com/fasterxml/jackson/databind/ObjectMapper.java +++ b/src/main/java/com/fasterxml/jackson/databind/ObjectMapper.java @@ -26,7 +26,7 @@ import com.fasterxml.jackson.databind.introspect.ClassIntrospector; import com.fasterxml.jackson.databind.introspect.JacksonAnnotationIntrospector; import com.fasterxml.jackson.databind.introspect.VisibilityChecker; -import com.fasterxml.jackson.databind.jsonschema.visitors.JsonFormatVisitor; +import com.fasterxml.jackson.databind.jsonschema.visitors.JsonFormatVisitorWrapper; import com.fasterxml.jackson.databind.jsontype.*; import com.fasterxml.jackson.databind.jsontype.impl.StdSubtypeResolver; import com.fasterxml.jackson.databind.jsontype.impl.StdTypeResolverBuilder; @@ -2396,7 +2396,7 @@ protected Object _convert(Object fromValue, JavaType toValueType) * * @param t The class to generate schema for */ - public void acceptJsonFormatVisitor(Class t, JsonFormatVisitor visitor) throws JsonMappingException { + public void acceptJsonFormatVisitor(Class t, JsonFormatVisitorWrapper visitor) throws JsonMappingException { if (t == null) { throw new IllegalArgumentException("class must be provided"); } diff --git a/src/main/java/com/fasterxml/jackson/databind/ext/CoreXMLSerializers.java b/src/main/java/com/fasterxml/jackson/databind/ext/CoreXMLSerializers.java index de718ffa2f..63771c0dcd 100644 --- a/src/main/java/com/fasterxml/jackson/databind/ext/CoreXMLSerializers.java +++ b/src/main/java/com/fasterxml/jackson/databind/ext/CoreXMLSerializers.java @@ -16,7 +16,7 @@ import com.fasterxml.jackson.databind.JsonNode; import com.fasterxml.jackson.databind.JsonSerializer; import com.fasterxml.jackson.databind.SerializerProvider; -import com.fasterxml.jackson.databind.jsonschema.visitors.JsonFormatVisitor; +import com.fasterxml.jackson.databind.jsonschema.visitors.JsonFormatVisitorWrapper; import com.fasterxml.jackson.databind.ser.std.CalendarSerializer; import com.fasterxml.jackson.databind.ser.std.StdSerializer; import com.fasterxml.jackson.databind.ser.std.ToStringSerializer; @@ -63,7 +63,7 @@ public void serialize(XMLGregorianCalendar value, JsonGenerator jgen, Serializer CalendarSerializer.instance.serialize(value.toGregorianCalendar(), jgen, provider); } - public void acceptJsonFormatVisitor(JsonFormatVisitor visitor, JavaType typeHint) { + public void acceptJsonFormatVisitor(JsonFormatVisitorWrapper visitor, JavaType typeHint) { CalendarSerializer.instance.acceptJsonFormatVisitor(visitor, null); } } diff --git a/src/main/java/com/fasterxml/jackson/databind/ext/DOMSerializer.java b/src/main/java/com/fasterxml/jackson/databind/ext/DOMSerializer.java index 7f6515b710..2f37faf1c3 100644 --- a/src/main/java/com/fasterxml/jackson/databind/ext/DOMSerializer.java +++ b/src/main/java/com/fasterxml/jackson/databind/ext/DOMSerializer.java @@ -11,7 +11,7 @@ import com.fasterxml.jackson.databind.JavaType; import com.fasterxml.jackson.databind.SerializerProvider; -import com.fasterxml.jackson.databind.jsonschema.visitors.JsonFormatVisitor; +import com.fasterxml.jackson.databind.jsonschema.visitors.JsonFormatVisitorWrapper; import com.fasterxml.jackson.databind.ser.std.StdSerializer; public class DOMSerializer @@ -41,8 +41,8 @@ public void serialize(Node value, JsonGenerator jgen, SerializerProvider provide } @Override - public void acceptJsonFormatVisitor(JsonFormatVisitor visitor, JavaType typeHint) + public void acceptJsonFormatVisitor(JsonFormatVisitorWrapper visitor, JavaType typeHint) { - visitor.anyFormat(typeHint); + visitor.expectAnyFormat(typeHint); } } diff --git a/src/main/java/com/fasterxml/jackson/databind/jsonschema/JsonFormatVisitorAware.java b/src/main/java/com/fasterxml/jackson/databind/jsonschema/JsonFormatVisitorAware.java index 4380820656..b18688a1f1 100644 --- a/src/main/java/com/fasterxml/jackson/databind/jsonschema/JsonFormatVisitorAware.java +++ b/src/main/java/com/fasterxml/jackson/databind/jsonschema/JsonFormatVisitorAware.java @@ -2,7 +2,7 @@ import com.fasterxml.jackson.databind.JavaType; -import com.fasterxml.jackson.databind.jsonschema.visitors.JsonFormatVisitor; +import com.fasterxml.jackson.databind.jsonschema.visitors.JsonFormatVisitorWrapper; /** * Marker interface for schema-aware serializers. @@ -15,5 +15,5 @@ public interface JsonFormatVisitorAware * * @return Json-schema for this serializer. */ - public void acceptJsonFormatVisitor(JsonFormatVisitor visitor, JavaType typeHint); + public void acceptJsonFormatVisitor(JsonFormatVisitorWrapper visitor, JavaType typeHint); } diff --git a/src/main/java/com/fasterxml/jackson/databind/jsonschema/SchemaFactoryProvider.java b/src/main/java/com/fasterxml/jackson/databind/jsonschema/SchemaFactoryProvider.java new file mode 100644 index 0000000000..0d0a8da550 --- /dev/null +++ b/src/main/java/com/fasterxml/jackson/databind/jsonschema/SchemaFactoryProvider.java @@ -0,0 +1,89 @@ +package com.fasterxml.jackson.databind.jsonschema; + +import com.fasterxml.jackson.databind.JavaType; +import com.fasterxml.jackson.databind.SerializerProvider; +import com.fasterxml.jackson.databind.jsonschema.factories.*; +import com.fasterxml.jackson.databind.jsonschema.types.JsonSchema; +import com.fasterxml.jackson.databind.jsonschema.visitors.JsonAnyFormatVisitor; +import com.fasterxml.jackson.databind.jsonschema.visitors.JsonArrayFormatVisitor; +import com.fasterxml.jackson.databind.jsonschema.visitors.JsonBooleanFormatVisitor; +import com.fasterxml.jackson.databind.jsonschema.visitors.JsonFormatVisitorWrapper; +import com.fasterxml.jackson.databind.jsonschema.visitors.JsonIntegerFormatVisitor; +import com.fasterxml.jackson.databind.jsonschema.visitors.JsonNullFormatVisitor; +import com.fasterxml.jackson.databind.jsonschema.visitors.JsonNumberFormatVisitor; +import com.fasterxml.jackson.databind.jsonschema.visitors.JsonObjectFormatVisitor; +import com.fasterxml.jackson.databind.jsonschema.visitors.JsonStringFormatVisitor; + +/** + * @author jphelan + * + */ +public class SchemaFactoryProvider implements JsonFormatVisitorWrapper{ + + protected SerializerProvider provider; + private SchemaFactoryDelegate delegate; + + /** + * {@link SchemaFactory#provider} + * @param provider the provider to set + */ + public void setProvider(SerializerProvider provider) { + this.provider = provider; + } + + public SerializerProvider getProvider() { + return provider; + } + + + public JsonAnyFormatVisitor expectAnyFormat(JavaType convertedType) { + delegate = new AnySchemaFactory(provider); + return (JsonAnyFormatVisitor) delegate; + } + + public JsonArrayFormatVisitor expectArrayFormat(JavaType convertedType) { + delegate = new ArraySchemaFactory(provider); + return (JsonArrayFormatVisitor) delegate; + } + + public JsonBooleanFormatVisitor expectBooleanFormat(JavaType convertedType) { + delegate = new BooleanSchemaFactory(provider); + return (JsonBooleanFormatVisitor) delegate; + } + + public JsonSchema finalSchema() { + assert delegate != null : "SchemaFactory must envoke a delegate method before it can return a JsonSchema."; + if (delegate == null) { + return null; + } else { + return delegate.getSchema(); + } + + } + + public JsonIntegerFormatVisitor expectIntegerFormat(JavaType convertedType) { + delegate = new IntegerSchemaFactory(provider); + return (JsonIntegerFormatVisitor) delegate; + } + + public JsonNullFormatVisitor expectNullFormat(JavaType convertedType) { + delegate = new NullSchemaFactory(provider); + return (JsonNullFormatVisitor) delegate; + } + + public JsonNumberFormatVisitor expectNumberFormat(JavaType convertedType) { + delegate = new NumberSchemaFactory(provider); + return (JsonNumberFormatVisitor) delegate; + } + + public JsonObjectFormatVisitor expectObjectFormat(JavaType convertedType) { + delegate = new ObjectSchemaFactory(provider); + return (JsonObjectFormatVisitor) delegate; + } + + public JsonStringFormatVisitor expectStringFormat(JavaType convertedType) { + delegate = new StringSchemaFactory(provider); + return (JsonStringFormatVisitor) delegate; + } + +} diff --git a/src/main/java/com/fasterxml/jackson/databind/jsonschema/factories/AnySchemaFactory.java b/src/main/java/com/fasterxml/jackson/databind/jsonschema/factories/AnySchemaFactory.java index f9e0b089c3..a39b7ef834 100644 --- a/src/main/java/com/fasterxml/jackson/databind/jsonschema/factories/AnySchemaFactory.java +++ b/src/main/java/com/fasterxml/jackson/databind/jsonschema/factories/AnySchemaFactory.java @@ -1,5 +1,6 @@ package com.fasterxml.jackson.databind.jsonschema.factories; +import com.fasterxml.jackson.databind.SerializerProvider; import com.fasterxml.jackson.databind.jsonschema.types.AnySchema; import com.fasterxml.jackson.databind.jsonschema.types.JsonSchema; import com.fasterxml.jackson.databind.jsonschema.visitors.JsonAnyFormatVisitor; @@ -16,6 +17,15 @@ public AnySchemaFactory(SchemaFactory parent) { anySchema = new AnySchema(); } + /** + * @param provider + */ + public AnySchemaFactory(SerializerProvider provider) { + parent = null; + setProvider(provider); + anySchema = new AnySchema(); + } + public JsonSchema getSchema() { return anySchema; } diff --git a/src/main/java/com/fasterxml/jackson/databind/jsonschema/factories/ArraySchemaFactory.java b/src/main/java/com/fasterxml/jackson/databind/jsonschema/factories/ArraySchemaFactory.java index 9ef546b876..5022dee81b 100644 --- a/src/main/java/com/fasterxml/jackson/databind/jsonschema/factories/ArraySchemaFactory.java +++ b/src/main/java/com/fasterxml/jackson/databind/jsonschema/factories/ArraySchemaFactory.java @@ -4,7 +4,9 @@ import com.fasterxml.jackson.databind.JavaType; import com.fasterxml.jackson.databind.JsonMappingException; import com.fasterxml.jackson.databind.JsonSerializer; +import com.fasterxml.jackson.databind.SerializerProvider; import com.fasterxml.jackson.databind.jsonschema.JsonFormatVisitorAware; +import com.fasterxml.jackson.databind.jsonschema.SchemaFactoryProvider; import com.fasterxml.jackson.databind.jsonschema.types.ArraySchema; import com.fasterxml.jackson.databind.jsonschema.types.JsonSchema; import com.fasterxml.jackson.databind.jsonschema.types.SchemaType; @@ -26,6 +28,15 @@ public ArraySchemaFactory(SchemaFactory schemaFactory) { this(schemaFactory, null); } + /** + * @param provider + */ + public ArraySchemaFactory(SerializerProvider provider) { + parent = null; + setProvider(provider); + arraySchema = new ArraySchema(); + } + public void itemsFormat(JavaType contentType) { // An array of object matches any values, thus we leave the schema empty. if (contentType.getRawClass() != Object.class) { @@ -34,7 +45,7 @@ public void itemsFormat(JavaType contentType) { try { ser = getProvider().findValueSerializer(contentType, _property); if (ser instanceof JsonFormatVisitorAware) { - SchemaFactory visitor = new SchemaFactory(); + SchemaFactoryProvider visitor = new SchemaFactoryProvider(); visitor.setProvider(provider); ((JsonFormatVisitorAware) ser).acceptJsonFormatVisitor(visitor, contentType); arraySchema.setItemsSchema(visitor.finalSchema()); diff --git a/src/main/java/com/fasterxml/jackson/databind/jsonschema/factories/BooleanSchemaFactory.java b/src/main/java/com/fasterxml/jackson/databind/jsonschema/factories/BooleanSchemaFactory.java index 179ad28404..a27318eac9 100644 --- a/src/main/java/com/fasterxml/jackson/databind/jsonschema/factories/BooleanSchemaFactory.java +++ b/src/main/java/com/fasterxml/jackson/databind/jsonschema/factories/BooleanSchemaFactory.java @@ -1,5 +1,6 @@ package com.fasterxml.jackson.databind.jsonschema.factories; +import com.fasterxml.jackson.databind.SerializerProvider; import com.fasterxml.jackson.databind.jsonschema.types.BooleanSchema; import com.fasterxml.jackson.databind.jsonschema.types.ValueTypeSchema; import com.fasterxml.jackson.databind.jsonschema.visitors.JsonBooleanFormatVisitor; @@ -14,6 +15,14 @@ public BooleanSchemaFactory(SchemaFactory parent) { booleanSchema = new BooleanSchema(); } + /** + * @param provider + */ + public BooleanSchemaFactory(SerializerProvider provider) { + super(provider); + booleanSchema = new BooleanSchema(); + } + public ValueTypeSchema getValueSchema() { return booleanSchema; } diff --git a/src/main/java/com/fasterxml/jackson/databind/jsonschema/factories/IntegerSchemaFactory.java b/src/main/java/com/fasterxml/jackson/databind/jsonschema/factories/IntegerSchemaFactory.java index 3d821a1d6e..6ad6d5e445 100644 --- a/src/main/java/com/fasterxml/jackson/databind/jsonschema/factories/IntegerSchemaFactory.java +++ b/src/main/java/com/fasterxml/jackson/databind/jsonschema/factories/IntegerSchemaFactory.java @@ -1,5 +1,6 @@ package com.fasterxml.jackson.databind.jsonschema.factories; +import com.fasterxml.jackson.databind.SerializerProvider; import com.fasterxml.jackson.databind.jsonschema.types.IntegerSchema; import com.fasterxml.jackson.databind.jsonschema.types.ValueTypeSchema; import com.fasterxml.jackson.databind.jsonschema.visitors.JsonIntegerFormatVisitor; @@ -14,6 +15,14 @@ public IntegerSchemaFactory(SchemaFactory parent) { integerSchema = new IntegerSchema(); } + /** + * @param provider + */ + public IntegerSchemaFactory(SerializerProvider provider) { + super(provider); + integerSchema = new IntegerSchema(); + } + public ValueTypeSchema getValueSchema() { return integerSchema; } diff --git a/src/main/java/com/fasterxml/jackson/databind/jsonschema/factories/NullSchemaFactory.java b/src/main/java/com/fasterxml/jackson/databind/jsonschema/factories/NullSchemaFactory.java index 07d3630dfd..7caa64c702 100644 --- a/src/main/java/com/fasterxml/jackson/databind/jsonschema/factories/NullSchemaFactory.java +++ b/src/main/java/com/fasterxml/jackson/databind/jsonschema/factories/NullSchemaFactory.java @@ -1,5 +1,6 @@ package com.fasterxml.jackson.databind.jsonschema.factories; +import com.fasterxml.jackson.databind.SerializerProvider; import com.fasterxml.jackson.databind.jsonschema.types.JsonSchema; import com.fasterxml.jackson.databind.jsonschema.types.NullSchema; import com.fasterxml.jackson.databind.jsonschema.visitors.JsonNullFormatVisitor; @@ -16,6 +17,15 @@ public NullSchemaFactory(SchemaFactory parent) { nullSchema = new NullSchema(); } + /** + * @param provider + */ + public NullSchemaFactory(SerializerProvider provider) { + parent = null; + setProvider(provider); + nullSchema = new NullSchema(); + } + public JsonSchema getSchema() { return nullSchema; } diff --git a/src/main/java/com/fasterxml/jackson/databind/jsonschema/factories/NumberSchemaFactory.java b/src/main/java/com/fasterxml/jackson/databind/jsonschema/factories/NumberSchemaFactory.java index 05d5a28972..672d04a47e 100644 --- a/src/main/java/com/fasterxml/jackson/databind/jsonschema/factories/NumberSchemaFactory.java +++ b/src/main/java/com/fasterxml/jackson/databind/jsonschema/factories/NumberSchemaFactory.java @@ -1,5 +1,6 @@ package com.fasterxml.jackson.databind.jsonschema.factories; +import com.fasterxml.jackson.databind.SerializerProvider; import com.fasterxml.jackson.databind.jsonschema.types.NumberSchema; import com.fasterxml.jackson.databind.jsonschema.types.ValueTypeSchema; import com.fasterxml.jackson.databind.jsonschema.visitors.JsonNumberFormatVisitor; @@ -15,6 +16,14 @@ public NumberSchemaFactory(SchemaFactory parent) { numberSchema = new NumberSchema(); } + /** + * @param provider + */ + public NumberSchemaFactory(SerializerProvider provider) { + super(provider); + numberSchema = new NumberSchema(); + } + @Override protected ValueTypeSchema getValueSchema() { return numberSchema; diff --git a/src/main/java/com/fasterxml/jackson/databind/jsonschema/factories/ObjectSchemaFactory.java b/src/main/java/com/fasterxml/jackson/databind/jsonschema/factories/ObjectSchemaFactory.java index 3af3921bdd..25688b5d17 100644 --- a/src/main/java/com/fasterxml/jackson/databind/jsonschema/factories/ObjectSchemaFactory.java +++ b/src/main/java/com/fasterxml/jackson/databind/jsonschema/factories/ObjectSchemaFactory.java @@ -4,7 +4,9 @@ import com.fasterxml.jackson.databind.JavaType; import com.fasterxml.jackson.databind.JsonMappingException; import com.fasterxml.jackson.databind.JsonSerializer; +import com.fasterxml.jackson.databind.SerializerProvider; import com.fasterxml.jackson.databind.jsonschema.JsonFormatVisitorAware; +import com.fasterxml.jackson.databind.jsonschema.SchemaFactoryProvider; import com.fasterxml.jackson.databind.jsonschema.types.JsonSchema; import com.fasterxml.jackson.databind.jsonschema.types.ObjectSchema; import com.fasterxml.jackson.databind.jsonschema.types.SchemaType; @@ -22,6 +24,15 @@ public ObjectSchemaFactory(SchemaFactory parent) { objectSchema = new ObjectSchema(); } + /** + * @param provider + */ + public ObjectSchemaFactory(SerializerProvider provider) { + parent = null; + setProvider(provider); + objectSchema = new ObjectSchema(); + } + public JsonSchema getSchema() { return objectSchema; } @@ -40,19 +51,19 @@ private JsonSerializer getSer(BeanPropertyWriter writer) { } protected JsonSchema propertySchema(BeanPropertyWriter writer) { - SchemaFactory visitor = new SchemaFactory(); + SchemaFactoryProvider visitor = new SchemaFactoryProvider(); visitor.setProvider(provider); JsonSerializer ser = getSer(writer); if (ser != null && ser instanceof JsonFormatVisitorAware) { ((JsonFormatVisitorAware)ser).acceptJsonFormatVisitor(visitor, writer.getType()); } else { - visitor.anyFormat(writer.getType()); + visitor.expectAnyFormat(writer.getType()); } return visitor.finalSchema(); } protected JsonSchema propertySchema(JsonFormatVisitorAware handler, JavaType propertyTypeHint) { - SchemaFactory visitor = new SchemaFactory(); + SchemaFactoryProvider visitor = new SchemaFactoryProvider(); visitor.setProvider(provider); handler.acceptJsonFormatVisitor(visitor, propertyTypeHint); return visitor.finalSchema(); diff --git a/src/main/java/com/fasterxml/jackson/databind/jsonschema/factories/SchemaFactory.java b/src/main/java/com/fasterxml/jackson/databind/jsonschema/factories/SchemaFactory.java index 2c42699c0f..ca35f4398d 100644 --- a/src/main/java/com/fasterxml/jackson/databind/jsonschema/factories/SchemaFactory.java +++ b/src/main/java/com/fasterxml/jackson/databind/jsonschema/factories/SchemaFactory.java @@ -1,50 +1,16 @@ package com.fasterxml.jackson.databind.jsonschema.factories; -import com.fasterxml.jackson.databind.JavaType; import com.fasterxml.jackson.databind.SerializerProvider; -import com.fasterxml.jackson.databind.jsonschema.types.JsonSchema; -import com.fasterxml.jackson.databind.jsonschema.visitors.JsonAnyFormatVisitor; -import com.fasterxml.jackson.databind.jsonschema.visitors.JsonArrayFormatVisitor; -import com.fasterxml.jackson.databind.jsonschema.visitors.JsonBooleanFormatVisitor; -import com.fasterxml.jackson.databind.jsonschema.visitors.JsonFormatVisitor; -import com.fasterxml.jackson.databind.jsonschema.visitors.JsonIntegerFormatVisitor; -import com.fasterxml.jackson.databind.jsonschema.visitors.JsonNullFormatVisitor; -import com.fasterxml.jackson.databind.jsonschema.visitors.JsonNumberFormatVisitor; -import com.fasterxml.jackson.databind.jsonschema.visitors.JsonObjectFormatVisitor; -import com.fasterxml.jackson.databind.jsonschema.visitors.JsonStringFormatVisitor; -public class SchemaFactory implements JsonFormatVisitor { +public abstract class SchemaFactory { - private SchemaFactoryDelegate delegate; + protected SerializerProvider provider; public SchemaFactory() { } - public JsonAnyFormatVisitor anyFormat(JavaType convertedType) { - delegate = new AnySchemaFactory(this); - return (JsonAnyFormatVisitor) delegate; - } - - public JsonArrayFormatVisitor arrayFormat(JavaType convertedType) { - delegate = new ArraySchemaFactory(this); - return (JsonArrayFormatVisitor) delegate; - } - - public JsonBooleanFormatVisitor booleanFormat(JavaType convertedType) { - delegate = new BooleanSchemaFactory(this); - return (JsonBooleanFormatVisitor) delegate; - } - - public JsonSchema finalSchema() { - assert delegate != null : "SchemaFactory must envoke a delegate method before it can return a JsonSchema."; - if (delegate == null) { - return null; - } else { - return delegate.getSchema(); - } - - } + /** * {@link SchemaFactory#provider} @@ -58,30 +24,5 @@ public SerializerProvider getProvider() { return provider; } - public JsonIntegerFormatVisitor integerFormat(JavaType convertedType) { - delegate = new IntegerSchemaFactory(this); - return (JsonIntegerFormatVisitor) delegate; - } - - public JsonNullFormatVisitor nullFormat(JavaType convertedType) { - delegate = new NullSchemaFactory(this); - return (JsonNullFormatVisitor) delegate; - } - - public JsonNumberFormatVisitor numberFormat(JavaType convertedType) { - delegate = new NumberSchemaFactory(this); - return (JsonNumberFormatVisitor) delegate; - } - - public JsonObjectFormatVisitor objectFormat(JavaType convertedType) { - // BasicClassIntrospector.instance. - delegate = new ObjectSchemaFactory(this); - return (JsonObjectFormatVisitor) delegate; - } - - public JsonStringFormatVisitor stringFormat(JavaType convertedType) { - delegate = new StringSchemaFactory(this); - return (JsonStringFormatVisitor) delegate; - } - + } diff --git a/src/main/java/com/fasterxml/jackson/databind/jsonschema/factories/StringSchemaFactory.java b/src/main/java/com/fasterxml/jackson/databind/jsonschema/factories/StringSchemaFactory.java index c5fdf91120..3dcb84a2cb 100644 --- a/src/main/java/com/fasterxml/jackson/databind/jsonschema/factories/StringSchemaFactory.java +++ b/src/main/java/com/fasterxml/jackson/databind/jsonschema/factories/StringSchemaFactory.java @@ -1,5 +1,6 @@ package com.fasterxml.jackson.databind.jsonschema.factories; +import com.fasterxml.jackson.databind.SerializerProvider; import com.fasterxml.jackson.databind.jsonschema.types.StringSchema; import com.fasterxml.jackson.databind.jsonschema.types.ValueTypeSchema; import com.fasterxml.jackson.databind.jsonschema.visitors.JsonStringFormatVisitor; @@ -14,6 +15,14 @@ public StringSchemaFactory(SchemaFactory parent) { stringSchema = new StringSchema(); } + /** + * @param provider + */ + public StringSchemaFactory(SerializerProvider provider) { + super(provider); + stringSchema = new StringSchema(); + } + public ValueTypeSchema getValueSchema() { return stringSchema; } diff --git a/src/main/java/com/fasterxml/jackson/databind/jsonschema/factories/ValueTypeSchemaFactory.java b/src/main/java/com/fasterxml/jackson/databind/jsonschema/factories/ValueTypeSchemaFactory.java index 6efde9a903..d0543c89c3 100644 --- a/src/main/java/com/fasterxml/jackson/databind/jsonschema/factories/ValueTypeSchemaFactory.java +++ b/src/main/java/com/fasterxml/jackson/databind/jsonschema/factories/ValueTypeSchemaFactory.java @@ -2,6 +2,7 @@ import java.util.Set; +import com.fasterxml.jackson.databind.SerializerProvider; import com.fasterxml.jackson.databind.jsonschema.types.JsonSchema; import com.fasterxml.jackson.databind.jsonschema.types.JsonValueFormat; import com.fasterxml.jackson.databind.jsonschema.types.ValueTypeSchema; @@ -17,6 +18,14 @@ protected ValueTypeSchemaFactory(SchemaFactory parent) { setProvider(parent.getProvider()); } + /** + * @param provider + */ + public ValueTypeSchemaFactory(SerializerProvider provider) { + parent = null; + setProvider(provider); + } + public JsonSchema getSchema() { return getValueSchema(); } diff --git a/src/main/java/com/fasterxml/jackson/databind/jsonschema/visitors/JsonArrayFormatVisitor.java b/src/main/java/com/fasterxml/jackson/databind/jsonschema/visitors/JsonArrayFormatVisitor.java index fa0cc3d6d5..1eb06b6337 100644 --- a/src/main/java/com/fasterxml/jackson/databind/jsonschema/visitors/JsonArrayFormatVisitor.java +++ b/src/main/java/com/fasterxml/jackson/databind/jsonschema/visitors/JsonArrayFormatVisitor.java @@ -4,7 +4,7 @@ import com.fasterxml.jackson.databind.jsonschema.JsonFormatVisitorAware; import com.fasterxml.jackson.databind.jsonschema.types.SchemaType; -public interface JsonArrayFormatVisitor { +public interface JsonArrayFormatVisitor extends JsonFormatVisitorWithSerializerProvider { void itemsFormat(JavaType contentType); diff --git a/src/main/java/com/fasterxml/jackson/databind/jsonschema/visitors/JsonFormatVisitor.java b/src/main/java/com/fasterxml/jackson/databind/jsonschema/visitors/JsonFormatVisitor.java deleted file mode 100644 index ca1c3deeeb..0000000000 --- a/src/main/java/com/fasterxml/jackson/databind/jsonschema/visitors/JsonFormatVisitor.java +++ /dev/null @@ -1,20 +0,0 @@ -package com.fasterxml.jackson.databind.jsonschema.visitors; - -import com.fasterxml.jackson.databind.JavaType; -import com.fasterxml.jackson.databind.SerializerProvider; - -public interface JsonFormatVisitor { - - public JsonObjectFormatVisitor objectFormat(JavaType convertedType); - public JsonArrayFormatVisitor arrayFormat(JavaType convertedType); - public JsonStringFormatVisitor stringFormat(JavaType convertedType); - public JsonNumberFormatVisitor numberFormat(JavaType convertedType); - public JsonIntegerFormatVisitor integerFormat(JavaType convertedType); - public JsonBooleanFormatVisitor booleanFormat(JavaType convertedType); - public JsonNullFormatVisitor nullFormat(JavaType convertedType); - public JsonAnyFormatVisitor anyFormat(JavaType convertedType); - - public SerializerProvider getProvider(); - public abstract void setProvider(SerializerProvider provider); - -} diff --git a/src/main/java/com/fasterxml/jackson/databind/jsonschema/visitors/JsonFormatVisitorWithSerializerProvider.java b/src/main/java/com/fasterxml/jackson/databind/jsonschema/visitors/JsonFormatVisitorWithSerializerProvider.java new file mode 100644 index 0000000000..b29f3849b3 --- /dev/null +++ b/src/main/java/com/fasterxml/jackson/databind/jsonschema/visitors/JsonFormatVisitorWithSerializerProvider.java @@ -0,0 +1,16 @@ +/** + * + */ +package com.fasterxml.jackson.databind.jsonschema.visitors; + +import com.fasterxml.jackson.databind.SerializerProvider; + +/** + * @author jphelan + * + */ +public interface JsonFormatVisitorWithSerializerProvider { + + public SerializerProvider getProvider(); + public abstract void setProvider(SerializerProvider provider); +} diff --git a/src/main/java/com/fasterxml/jackson/databind/jsonschema/visitors/JsonFormatVisitorWrapper.java b/src/main/java/com/fasterxml/jackson/databind/jsonschema/visitors/JsonFormatVisitorWrapper.java new file mode 100644 index 0000000000..3c43fa605f --- /dev/null +++ b/src/main/java/com/fasterxml/jackson/databind/jsonschema/visitors/JsonFormatVisitorWrapper.java @@ -0,0 +1,16 @@ +package com.fasterxml.jackson.databind.jsonschema.visitors; + +import com.fasterxml.jackson.databind.JavaType; + +public interface JsonFormatVisitorWrapper extends JsonFormatVisitorWithSerializerProvider{ + + public JsonObjectFormatVisitor expectObjectFormat(JavaType convertedType); + public JsonArrayFormatVisitor expectArrayFormat(JavaType convertedType); + public JsonStringFormatVisitor expectStringFormat(JavaType convertedType); + public JsonNumberFormatVisitor expectNumberFormat(JavaType convertedType); + public JsonIntegerFormatVisitor expectIntegerFormat(JavaType convertedType); + public JsonBooleanFormatVisitor expectBooleanFormat(JavaType convertedType); + public JsonNullFormatVisitor expectNullFormat(JavaType convertedType); + public JsonAnyFormatVisitor expectAnyFormat(JavaType convertedType); + +} diff --git a/src/main/java/com/fasterxml/jackson/databind/jsonschema/visitors/JsonObjectFormatVisitor.java b/src/main/java/com/fasterxml/jackson/databind/jsonschema/visitors/JsonObjectFormatVisitor.java index 81965497f0..570af4cb15 100644 --- a/src/main/java/com/fasterxml/jackson/databind/jsonschema/visitors/JsonObjectFormatVisitor.java +++ b/src/main/java/com/fasterxml/jackson/databind/jsonschema/visitors/JsonObjectFormatVisitor.java @@ -5,7 +5,7 @@ import com.fasterxml.jackson.databind.jsonschema.JsonFormatVisitorAware; import com.fasterxml.jackson.databind.ser.BeanPropertyWriter; -public interface JsonObjectFormatVisitor extends JsonFormatVisitor { +public interface JsonObjectFormatVisitor extends JsonFormatVisitorWithSerializerProvider { public void property(BeanPropertyWriter writer); diff --git a/src/main/java/com/fasterxml/jackson/databind/ser/DefaultSerializerProvider.java b/src/main/java/com/fasterxml/jackson/databind/ser/DefaultSerializerProvider.java index c60560f016..d0ebade5ee 100644 --- a/src/main/java/com/fasterxml/jackson/databind/ser/DefaultSerializerProvider.java +++ b/src/main/java/com/fasterxml/jackson/databind/ser/DefaultSerializerProvider.java @@ -14,7 +14,7 @@ import com.fasterxml.jackson.databind.introspect.Annotated; import com.fasterxml.jackson.databind.introspect.ObjectIdInfo; import com.fasterxml.jackson.databind.jsonschema.JsonFormatVisitorAware; -import com.fasterxml.jackson.databind.jsonschema.visitors.JsonFormatVisitor; +import com.fasterxml.jackson.databind.jsonschema.visitors.JsonFormatVisitorWrapper; import com.fasterxml.jackson.databind.ser.impl.WritableObjectId; import com.fasterxml.jackson.databind.util.ClassUtil; @@ -236,7 +236,7 @@ public void serializeValue(JsonGenerator jgen, Object value, JavaType rootType, * * @param type The type for which to generate schema */ - public void acceptJsonFormatVisitor(Class type, JsonFormatVisitor visitor) + public void acceptJsonFormatVisitor(Class type, JsonFormatVisitorWrapper visitor) throws JsonMappingException { if (type == null) { @@ -249,7 +249,7 @@ public void acceptJsonFormatVisitor(Class type, JsonFormatVisitor visitor) if (ser instanceof JsonFormatVisitorAware) { ((JsonFormatVisitorAware) ser).acceptJsonFormatVisitor(visitor, constructType(type)); } else { - visitor.anyFormat(constructType(type)); + visitor.expectAnyFormat(constructType(type)); } } /** diff --git a/src/main/java/com/fasterxml/jackson/databind/ser/impl/FailingSerializer.java b/src/main/java/com/fasterxml/jackson/databind/ser/impl/FailingSerializer.java index e023f3091c..18d983b819 100644 --- a/src/main/java/com/fasterxml/jackson/databind/ser/impl/FailingSerializer.java +++ b/src/main/java/com/fasterxml/jackson/databind/ser/impl/FailingSerializer.java @@ -6,7 +6,7 @@ import com.fasterxml.jackson.databind.JavaType; import com.fasterxml.jackson.databind.SerializerProvider; -import com.fasterxml.jackson.databind.jsonschema.visitors.JsonFormatVisitor; +import com.fasterxml.jackson.databind.jsonschema.visitors.JsonFormatVisitorWrapper; import com.fasterxml.jackson.databind.ser.std.StdSerializer; /** @@ -34,7 +34,7 @@ public void serialize(Object value, JsonGenerator jgen, SerializerProvider provi } @Override - public void acceptJsonFormatVisitor(JsonFormatVisitor visitor, JavaType typeHint) + public void acceptJsonFormatVisitor(JsonFormatVisitorWrapper visitor, JavaType typeHint) { ; } diff --git a/src/main/java/com/fasterxml/jackson/databind/ser/impl/StringArraySerializer.java b/src/main/java/com/fasterxml/jackson/databind/ser/impl/StringArraySerializer.java index eb2bc77457..aa46ac202c 100644 --- a/src/main/java/com/fasterxml/jackson/databind/ser/impl/StringArraySerializer.java +++ b/src/main/java/com/fasterxml/jackson/databind/ser/impl/StringArraySerializer.java @@ -8,7 +8,7 @@ import com.fasterxml.jackson.databind.*; import com.fasterxml.jackson.databind.annotation.JacksonStdImpl; import com.fasterxml.jackson.databind.jsonschema.types.SchemaType; -import com.fasterxml.jackson.databind.jsonschema.visitors.JsonFormatVisitor; +import com.fasterxml.jackson.databind.jsonschema.visitors.JsonFormatVisitorWrapper; import com.fasterxml.jackson.databind.jsontype.TypeSerializer; import com.fasterxml.jackson.databind.node.ObjectNode; import com.fasterxml.jackson.databind.ser.ContainerSerializer; @@ -170,8 +170,8 @@ private void serializeContentsSlow(String[] value, JsonGenerator jgen, Serialize } @Override - public void acceptJsonFormatVisitor(JsonFormatVisitor visitor, JavaType typeHint) + public void acceptJsonFormatVisitor(JsonFormatVisitorWrapper visitor, JavaType typeHint) { - visitor.arrayFormat(null).itemsFormat(SchemaType.STRING); + visitor.expectArrayFormat(null).itemsFormat(SchemaType.STRING); } } diff --git a/src/main/java/com/fasterxml/jackson/databind/ser/impl/UnknownSerializer.java b/src/main/java/com/fasterxml/jackson/databind/ser/impl/UnknownSerializer.java index de231d8193..12947ca66c 100644 --- a/src/main/java/com/fasterxml/jackson/databind/ser/impl/UnknownSerializer.java +++ b/src/main/java/com/fasterxml/jackson/databind/ser/impl/UnknownSerializer.java @@ -5,7 +5,7 @@ import com.fasterxml.jackson.core.*; import com.fasterxml.jackson.databind.*; -import com.fasterxml.jackson.databind.jsonschema.visitors.JsonFormatVisitor; +import com.fasterxml.jackson.databind.jsonschema.visitors.JsonFormatVisitorWrapper; import com.fasterxml.jackson.databind.jsontype.TypeSerializer; import com.fasterxml.jackson.databind.ser.std.StdSerializer; @@ -42,8 +42,8 @@ public final void serializeWithType(Object value, JsonGenerator jgen, Serializer } @Override - public void acceptJsonFormatVisitor(JsonFormatVisitor visitor, JavaType typeHint) { - visitor.anyFormat(typeHint); + public void acceptJsonFormatVisitor(JsonFormatVisitorWrapper visitor, JavaType typeHint) { + visitor.expectAnyFormat(typeHint); } protected void failForEmpty(Object value) throws JsonMappingException diff --git a/src/main/java/com/fasterxml/jackson/databind/ser/std/AsArraySerializerBase.java b/src/main/java/com/fasterxml/jackson/databind/ser/std/AsArraySerializerBase.java index 36ac786416..658458461f 100644 --- a/src/main/java/com/fasterxml/jackson/databind/ser/std/AsArraySerializerBase.java +++ b/src/main/java/com/fasterxml/jackson/databind/ser/std/AsArraySerializerBase.java @@ -14,7 +14,7 @@ import com.fasterxml.jackson.databind.SerializationFeature; import com.fasterxml.jackson.databind.SerializerProvider; import com.fasterxml.jackson.databind.jsonschema.visitors.JsonArrayFormatVisitor; -import com.fasterxml.jackson.databind.jsonschema.visitors.JsonFormatVisitor; +import com.fasterxml.jackson.databind.jsonschema.visitors.JsonFormatVisitorWrapper; import com.fasterxml.jackson.databind.jsontype.TypeSerializer; import com.fasterxml.jackson.databind.ser.ContainerSerializer; import com.fasterxml.jackson.databind.ser.ContextualSerializer; @@ -171,7 +171,7 @@ protected abstract void serializeContents(T value, JsonGenerator jgen, Serialize throws IOException, JsonGenerationException; @Override - public void acceptJsonFormatVisitor(JsonFormatVisitor visitor, JavaType typeHint) + public void acceptJsonFormatVisitor(JsonFormatVisitorWrapper visitor, JavaType typeHint) { /* 15-Jan-2010, tatu: This should probably be rewritten, given that * more information about content type is actually being explicitly @@ -180,7 +180,7 @@ public void acceptJsonFormatVisitor(JsonFormatVisitor visitor, JavaType typeHint */ //ObjectNode o = createSchemaNode("array", true); JsonArrayFormatVisitor arrayVisitor = - visitor.arrayFormat(typeHint); + visitor.expectArrayFormat(typeHint); JavaType contentType = null; if (typeHint != null) { contentType = typeHint.getContentType(); diff --git a/src/main/java/com/fasterxml/jackson/databind/ser/std/BeanSerializerBase.java b/src/main/java/com/fasterxml/jackson/databind/ser/std/BeanSerializerBase.java index 3163555828..b1a9e45fe5 100644 --- a/src/main/java/com/fasterxml/jackson/databind/ser/std/BeanSerializerBase.java +++ b/src/main/java/com/fasterxml/jackson/databind/ser/std/BeanSerializerBase.java @@ -21,7 +21,7 @@ import com.fasterxml.jackson.databind.introspect.AnnotatedMember; import com.fasterxml.jackson.databind.introspect.ObjectIdInfo; import com.fasterxml.jackson.databind.jsonschema.JsonFormatVisitorAware; -import com.fasterxml.jackson.databind.jsonschema.visitors.JsonFormatVisitor; +import com.fasterxml.jackson.databind.jsonschema.visitors.JsonFormatVisitorWrapper; import com.fasterxml.jackson.databind.jsonschema.visitors.JsonObjectFormatVisitor; import com.fasterxml.jackson.databind.jsontype.TypeSerializer; import com.fasterxml.jackson.databind.node.ObjectNode; @@ -638,9 +638,10 @@ protected BeanPropertyFilter findFilter(SerializerProvider provider) return filter; } - public void acceptJsonFormatVisitor(JsonFormatVisitor visitor, JavaType typeHint) + public void acceptJsonFormatVisitor(JsonFormatVisitorWrapper visitor, JavaType typeHint) { - JsonObjectFormatVisitor objectVisitor = visitor.objectFormat(typeHint); + //deposit your output format + JsonObjectFormatVisitor objectVisitor = visitor.expectObjectFormat(typeHint); if (_propertyFilterId != null) { try { diff --git a/src/main/java/com/fasterxml/jackson/databind/ser/std/BooleanSerializer.java b/src/main/java/com/fasterxml/jackson/databind/ser/std/BooleanSerializer.java index e603a2a72e..7e48e0461d 100644 --- a/src/main/java/com/fasterxml/jackson/databind/ser/std/BooleanSerializer.java +++ b/src/main/java/com/fasterxml/jackson/databind/ser/std/BooleanSerializer.java @@ -7,7 +7,7 @@ import com.fasterxml.jackson.databind.JavaType; import com.fasterxml.jackson.databind.SerializerProvider; import com.fasterxml.jackson.databind.annotation.JacksonStdImpl; -import com.fasterxml.jackson.databind.jsonschema.visitors.JsonFormatVisitor; +import com.fasterxml.jackson.databind.jsonschema.visitors.JsonFormatVisitorWrapper; /** * Serializer used for primitive boolean, as well as java.util.Boolean @@ -40,8 +40,8 @@ public void serialize(Boolean value, JsonGenerator jgen, SerializerProvider prov } @Override - public void acceptJsonFormatVisitor(JsonFormatVisitor visitor, JavaType typeHint) + public void acceptJsonFormatVisitor(JsonFormatVisitorWrapper visitor, JavaType typeHint) { - visitor.booleanFormat(typeHint); + visitor.expectBooleanFormat(typeHint); } } \ No newline at end of file diff --git a/src/main/java/com/fasterxml/jackson/databind/ser/std/DateTimeSerializerBase.java b/src/main/java/com/fasterxml/jackson/databind/ser/std/DateTimeSerializerBase.java index 634d5982fa..66fb97fa2d 100644 --- a/src/main/java/com/fasterxml/jackson/databind/ser/std/DateTimeSerializerBase.java +++ b/src/main/java/com/fasterxml/jackson/databind/ser/std/DateTimeSerializerBase.java @@ -17,7 +17,7 @@ import com.fasterxml.jackson.databind.SerializerProvider; import com.fasterxml.jackson.databind.introspect.Annotated; import com.fasterxml.jackson.databind.jsonschema.types.JsonValueFormat; -import com.fasterxml.jackson.databind.jsonschema.visitors.JsonFormatVisitor; +import com.fasterxml.jackson.databind.jsonschema.visitors.JsonFormatVisitorWrapper; import com.fasterxml.jackson.databind.ser.ContextualSerializer; import com.fasterxml.jackson.databind.util.StdDateFormat; @@ -106,7 +106,7 @@ public boolean isEmpty(T value) { protected abstract long _timestamp(T value); - public void acceptJsonFormatVisitor(JsonFormatVisitor visitor, JavaType typeHint) + public void acceptJsonFormatVisitor(JsonFormatVisitorWrapper visitor, JavaType typeHint) { //todo: (ryan) add a format for the date in the schema? boolean asNumber = _useTimestamp; @@ -116,9 +116,9 @@ public void acceptJsonFormatVisitor(JsonFormatVisitor visitor, JavaType typeHint } } if (asNumber) { - visitor.numberFormat(typeHint).format(JsonValueFormat.UTC_MILLISEC); + visitor.expectNumberFormat(typeHint).format(JsonValueFormat.UTC_MILLISEC); } else { - visitor.stringFormat(typeHint).format(JsonValueFormat.DATE_TIME); + visitor.expectStringFormat(typeHint).format(JsonValueFormat.DATE_TIME); } } diff --git a/src/main/java/com/fasterxml/jackson/databind/ser/std/EnumMapSerializer.java b/src/main/java/com/fasterxml/jackson/databind/ser/std/EnumMapSerializer.java index 2e761b94af..5b9b7f1884 100644 --- a/src/main/java/com/fasterxml/jackson/databind/ser/std/EnumMapSerializer.java +++ b/src/main/java/com/fasterxml/jackson/databind/ser/std/EnumMapSerializer.java @@ -15,7 +15,7 @@ import com.fasterxml.jackson.databind.SerializerProvider; import com.fasterxml.jackson.databind.annotation.JacksonStdImpl; import com.fasterxml.jackson.databind.jsonschema.JsonFormatVisitorAware; -import com.fasterxml.jackson.databind.jsonschema.visitors.JsonFormatVisitor; +import com.fasterxml.jackson.databind.jsonschema.visitors.JsonFormatVisitorWrapper; import com.fasterxml.jackson.databind.jsonschema.visitors.JsonObjectFormatVisitor; import com.fasterxml.jackson.databind.jsontype.TypeSerializer; import com.fasterxml.jackson.databind.node.JsonNodeFactory; @@ -255,9 +255,9 @@ protected void serializeContentsUsing(EnumMap,?> value, JsonGe @SuppressWarnings("unchecked") @Override - public void acceptJsonFormatVisitor(JsonFormatVisitor visitor, JavaType typeHint) + public void acceptJsonFormatVisitor(JsonFormatVisitorWrapper visitor, JavaType typeHint) { - JsonObjectFormatVisitor objectVisitor = visitor.objectFormat(typeHint); + JsonObjectFormatVisitor objectVisitor = visitor.expectObjectFormat(typeHint); if (typeHint instanceof ParameterizedType) { Type[] typeArgs = ((ParameterizedType) typeHint).getActualTypeArguments(); if (typeArgs.length == 2) { diff --git a/src/main/java/com/fasterxml/jackson/databind/ser/std/EnumSerializer.java b/src/main/java/com/fasterxml/jackson/databind/ser/std/EnumSerializer.java index ecbd02168d..565f57857b 100644 --- a/src/main/java/com/fasterxml/jackson/databind/ser/std/EnumSerializer.java +++ b/src/main/java/com/fasterxml/jackson/databind/ser/std/EnumSerializer.java @@ -14,7 +14,7 @@ import com.fasterxml.jackson.databind.SerializationFeature; import com.fasterxml.jackson.databind.SerializerProvider; import com.fasterxml.jackson.databind.annotation.JacksonStdImpl; -import com.fasterxml.jackson.databind.jsonschema.visitors.JsonFormatVisitor; +import com.fasterxml.jackson.databind.jsonschema.visitors.JsonFormatVisitorWrapper; import com.fasterxml.jackson.databind.jsonschema.visitors.JsonStringFormatVisitor; import com.fasterxml.jackson.databind.util.EnumValues; @@ -65,13 +65,13 @@ public final void serialize(Enum en, JsonGenerator jgen, SerializerProvider p } @Override - public void acceptJsonFormatVisitor(JsonFormatVisitor visitor, JavaType typeHint) + public void acceptJsonFormatVisitor(JsonFormatVisitorWrapper visitor, JavaType typeHint) { // [JACKSON-684]: serialize as index? if (visitor.getProvider().isEnabled(SerializationFeature.WRITE_ENUMS_USING_INDEX)) { - visitor.integerFormat(typeHint); + visitor.expectIntegerFormat(typeHint); } else { - JsonStringFormatVisitor stringVisitor = visitor.stringFormat(typeHint); + JsonStringFormatVisitor stringVisitor = visitor.expectStringFormat(typeHint); if (typeHint != null) { if (typeHint.isEnumType()) { Set enums = new HashSet(); diff --git a/src/main/java/com/fasterxml/jackson/databind/ser/std/JsonValueSerializer.java b/src/main/java/com/fasterxml/jackson/databind/ser/std/JsonValueSerializer.java index e3c66c918f..6715ecc887 100644 --- a/src/main/java/com/fasterxml/jackson/databind/ser/std/JsonValueSerializer.java +++ b/src/main/java/com/fasterxml/jackson/databind/ser/std/JsonValueSerializer.java @@ -16,7 +16,7 @@ import com.fasterxml.jackson.databind.SerializerProvider; import com.fasterxml.jackson.databind.annotation.JacksonStdImpl; import com.fasterxml.jackson.databind.jsonschema.JsonFormatVisitorAware; -import com.fasterxml.jackson.databind.jsonschema.visitors.JsonFormatVisitor; +import com.fasterxml.jackson.databind.jsonschema.visitors.JsonFormatVisitorWrapper; import com.fasterxml.jackson.databind.jsontype.TypeSerializer; import com.fasterxml.jackson.databind.ser.BeanSerializer; import com.fasterxml.jackson.databind.ser.ContextualSerializer; @@ -235,12 +235,12 @@ public void serializeWithType(Object bean, JsonGenerator jgen, SerializerProvide } @Override - public void acceptJsonFormatVisitor(JsonFormatVisitor visitor, JavaType typeHint) + public void acceptJsonFormatVisitor(JsonFormatVisitorWrapper visitor, JavaType typeHint) { if (_valueSerializer instanceof JsonFormatVisitorAware) { ((JsonFormatVisitorAware) _valueSerializer).acceptJsonFormatVisitor(visitor, null); } else { - visitor.anyFormat(typeHint); + visitor.expectAnyFormat(typeHint); } } diff --git a/src/main/java/com/fasterxml/jackson/databind/ser/std/MapSerializer.java b/src/main/java/com/fasterxml/jackson/databind/ser/std/MapSerializer.java index 6a749ea42c..c33e4dce95 100644 --- a/src/main/java/com/fasterxml/jackson/databind/ser/std/MapSerializer.java +++ b/src/main/java/com/fasterxml/jackson/databind/ser/std/MapSerializer.java @@ -16,7 +16,7 @@ import com.fasterxml.jackson.databind.SerializationFeature; import com.fasterxml.jackson.databind.SerializerProvider; import com.fasterxml.jackson.databind.annotation.JacksonStdImpl; -import com.fasterxml.jackson.databind.jsonschema.visitors.JsonFormatVisitor; +import com.fasterxml.jackson.databind.jsonschema.visitors.JsonFormatVisitorWrapper; import com.fasterxml.jackson.databind.jsontype.TypeSerializer; import com.fasterxml.jackson.databind.ser.ContainerSerializer; import com.fasterxml.jackson.databind.ser.ContextualSerializer; @@ -473,9 +473,9 @@ protected void serializeTypedFields(Map value, JsonGenerator jgen, Serializ } @Override - public void acceptJsonFormatVisitor(JsonFormatVisitor visitor, JavaType typeHint) + public void acceptJsonFormatVisitor(JsonFormatVisitorWrapper visitor, JavaType typeHint) { - visitor.objectFormat(null); + visitor.expectObjectFormat(null); } /* diff --git a/src/main/java/com/fasterxml/jackson/databind/ser/std/NullSerializer.java b/src/main/java/com/fasterxml/jackson/databind/ser/std/NullSerializer.java index 046ddf2147..dcb4e8b482 100644 --- a/src/main/java/com/fasterxml/jackson/databind/ser/std/NullSerializer.java +++ b/src/main/java/com/fasterxml/jackson/databind/ser/std/NullSerializer.java @@ -7,7 +7,7 @@ import com.fasterxml.jackson.databind.JavaType; import com.fasterxml.jackson.databind.SerializerProvider; import com.fasterxml.jackson.databind.annotation.JacksonStdImpl; -import com.fasterxml.jackson.databind.jsonschema.visitors.JsonFormatVisitor; +import com.fasterxml.jackson.databind.jsonschema.visitors.JsonFormatVisitorWrapper; /** * This is a simple dummy serializer that will just output literal @@ -32,8 +32,8 @@ public void serialize(Object value, JsonGenerator jgen, SerializerProvider provi } @Override - public void acceptJsonFormatVisitor(JsonFormatVisitor visitor, JavaType typeHint) + public void acceptJsonFormatVisitor(JsonFormatVisitorWrapper visitor, JavaType typeHint) { - visitor.nullFormat(typeHint); + visitor.expectNullFormat(typeHint); } } diff --git a/src/main/java/com/fasterxml/jackson/databind/ser/std/NumberSerializers.java b/src/main/java/com/fasterxml/jackson/databind/ser/std/NumberSerializers.java index de3583cb4b..2d6eb9cade 100644 --- a/src/main/java/com/fasterxml/jackson/databind/ser/std/NumberSerializers.java +++ b/src/main/java/com/fasterxml/jackson/databind/ser/std/NumberSerializers.java @@ -11,7 +11,7 @@ import com.fasterxml.jackson.databind.JsonSerializer; import com.fasterxml.jackson.databind.SerializerProvider; import com.fasterxml.jackson.databind.annotation.JacksonStdImpl; -import com.fasterxml.jackson.databind.jsonschema.visitors.JsonFormatVisitor; +import com.fasterxml.jackson.databind.jsonschema.visitors.JsonFormatVisitorWrapper; /** * Container class for serializers used for handling standard JDK-provided types. @@ -74,9 +74,9 @@ public void serialize(Integer value, JsonGenerator jgen, SerializerProvider prov } @Override - public void acceptJsonFormatVisitor(JsonFormatVisitor visitor, JavaType typeHint) + public void acceptJsonFormatVisitor(JsonFormatVisitorWrapper visitor, JavaType typeHint) { - visitor.integerFormat(typeHint); + visitor.expectIntegerFormat(typeHint); } } @@ -101,9 +101,9 @@ public void serialize(Number value, JsonGenerator jgen, SerializerProvider provi } @Override - public void acceptJsonFormatVisitor(JsonFormatVisitor visitor, JavaType typeHint) + public void acceptJsonFormatVisitor(JsonFormatVisitorWrapper visitor, JavaType typeHint) { - visitor.integerFormat(typeHint); + visitor.expectIntegerFormat(typeHint); } } @@ -123,9 +123,9 @@ public void serialize(Long value, JsonGenerator jgen, SerializerProvider provide } @Override - public void acceptJsonFormatVisitor(JsonFormatVisitor visitor, JavaType typeHint) + public void acceptJsonFormatVisitor(JsonFormatVisitorWrapper visitor, JavaType typeHint) { - visitor.numberFormat(typeHint); + visitor.expectNumberFormat(typeHint); } } @@ -145,9 +145,9 @@ public void serialize(Float value, JsonGenerator jgen, SerializerProvider provid } @Override - public void acceptJsonFormatVisitor(JsonFormatVisitor visitor, JavaType typeHint) + public void acceptJsonFormatVisitor(JsonFormatVisitorWrapper visitor, JavaType typeHint) { - visitor.numberFormat(typeHint); + visitor.expectNumberFormat(typeHint); } } @@ -174,9 +174,9 @@ public void serialize(Double value, JsonGenerator jgen, SerializerProvider provi } @Override - public void acceptJsonFormatVisitor(JsonFormatVisitor visitor, JavaType typeHint) + public void acceptJsonFormatVisitor(JsonFormatVisitorWrapper visitor, JavaType typeHint) { - visitor.numberFormat(typeHint); + visitor.expectNumberFormat(typeHint); } } @@ -222,9 +222,9 @@ public void serialize(Number value, JsonGenerator jgen, SerializerProvider provi } @Override - public void acceptJsonFormatVisitor(JsonFormatVisitor visitor, JavaType typeHint) + public void acceptJsonFormatVisitor(JsonFormatVisitorWrapper visitor, JavaType typeHint) { - visitor.numberFormat(typeHint); + visitor.expectNumberFormat(typeHint); } } } diff --git a/src/main/java/com/fasterxml/jackson/databind/ser/std/ObjectArraySerializer.java b/src/main/java/com/fasterxml/jackson/databind/ser/std/ObjectArraySerializer.java index 8be2b55502..f0de918877 100644 --- a/src/main/java/com/fasterxml/jackson/databind/ser/std/ObjectArraySerializer.java +++ b/src/main/java/com/fasterxml/jackson/databind/ser/std/ObjectArraySerializer.java @@ -11,7 +11,7 @@ import com.fasterxml.jackson.databind.JsonSerializer; import com.fasterxml.jackson.databind.SerializerProvider; import com.fasterxml.jackson.databind.annotation.JacksonStdImpl; -import com.fasterxml.jackson.databind.jsonschema.visitors.JsonFormatVisitor; +import com.fasterxml.jackson.databind.jsonschema.visitors.JsonFormatVisitorWrapper; import com.fasterxml.jackson.databind.jsontype.TypeSerializer; import com.fasterxml.jackson.databind.ser.ContainerSerializer; import com.fasterxml.jackson.databind.ser.ContextualSerializer; @@ -295,9 +295,9 @@ public void serializeTypedContents(Object[] value, JsonGenerator jgen, Serialize } @Override - public void acceptJsonFormatVisitor(JsonFormatVisitor visitor, JavaType typeHint) + public void acceptJsonFormatVisitor(JsonFormatVisitorWrapper visitor, JavaType typeHint) { - visitor.arrayFormat(typeHint).itemsFormat(_elementType); + visitor.expectArrayFormat(typeHint).itemsFormat(_elementType); } protected final JsonSerializer _findAndAddDynamic(PropertySerializerMap map, diff --git a/src/main/java/com/fasterxml/jackson/databind/ser/std/RawSerializer.java b/src/main/java/com/fasterxml/jackson/databind/ser/std/RawSerializer.java index a3ab1aed29..ad98504079 100644 --- a/src/main/java/com/fasterxml/jackson/databind/ser/std/RawSerializer.java +++ b/src/main/java/com/fasterxml/jackson/databind/ser/std/RawSerializer.java @@ -8,7 +8,7 @@ import com.fasterxml.jackson.databind.JavaType; import com.fasterxml.jackson.databind.SerializerProvider; import com.fasterxml.jackson.databind.annotation.JacksonStdImpl; -import com.fasterxml.jackson.databind.jsonschema.visitors.JsonFormatVisitor; +import com.fasterxml.jackson.databind.jsonschema.visitors.JsonFormatVisitorWrapper; import com.fasterxml.jackson.databind.jsontype.TypeSerializer; /** @@ -46,8 +46,8 @@ public void serializeWithType(T value, JsonGenerator jgen, SerializerProvider pr } @Override - public void acceptJsonFormatVisitor(JsonFormatVisitor visitor, JavaType typeHint) + public void acceptJsonFormatVisitor(JsonFormatVisitorWrapper visitor, JavaType typeHint) { - visitor.stringFormat(typeHint); + visitor.expectStringFormat(typeHint); } } diff --git a/src/main/java/com/fasterxml/jackson/databind/ser/std/SerializableSerializer.java b/src/main/java/com/fasterxml/jackson/databind/ser/std/SerializableSerializer.java index b53191c64a..65adb3d0b9 100644 --- a/src/main/java/com/fasterxml/jackson/databind/ser/std/SerializableSerializer.java +++ b/src/main/java/com/fasterxml/jackson/databind/ser/std/SerializableSerializer.java @@ -10,7 +10,7 @@ import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.databind.SerializerProvider; import com.fasterxml.jackson.databind.annotation.JacksonStdImpl; -import com.fasterxml.jackson.databind.jsonschema.visitors.JsonFormatVisitor; +import com.fasterxml.jackson.databind.jsonschema.visitors.JsonFormatVisitorWrapper; import com.fasterxml.jackson.databind.jsontype.TypeSerializer; /** @@ -46,8 +46,8 @@ public final void serializeWithType(JsonSerializable value, JsonGenerator jgen, } @Override - public void acceptJsonFormatVisitor(JsonFormatVisitor visitor, JavaType typeHint) + public void acceptJsonFormatVisitor(JsonFormatVisitorWrapper visitor, JavaType typeHint) { - visitor.anyFormat(typeHint); + visitor.expectAnyFormat(typeHint); } } diff --git a/src/main/java/com/fasterxml/jackson/databind/ser/std/SqlDateSerializer.java b/src/main/java/com/fasterxml/jackson/databind/ser/std/SqlDateSerializer.java index 2f7db424d6..d295c2c997 100644 --- a/src/main/java/com/fasterxml/jackson/databind/ser/std/SqlDateSerializer.java +++ b/src/main/java/com/fasterxml/jackson/databind/ser/std/SqlDateSerializer.java @@ -8,7 +8,7 @@ import com.fasterxml.jackson.databind.SerializerProvider; import com.fasterxml.jackson.databind.annotation.JacksonStdImpl; import com.fasterxml.jackson.databind.jsonschema.types.JsonValueFormat; -import com.fasterxml.jackson.databind.jsonschema.visitors.JsonFormatVisitor; +import com.fasterxml.jackson.databind.jsonschema.visitors.JsonFormatVisitorWrapper; /** * Compared to regular {@link java.util.Date} serialization, we do use String @@ -29,8 +29,8 @@ public void serialize(java.sql.Date value, JsonGenerator jgen, SerializerProvide } @Override - public void acceptJsonFormatVisitor(JsonFormatVisitor visitor, JavaType typeHint) + public void acceptJsonFormatVisitor(JsonFormatVisitorWrapper visitor, JavaType typeHint) { - visitor.stringFormat(typeHint).format(JsonValueFormat.DATE_TIME); + visitor.expectStringFormat(typeHint).format(JsonValueFormat.DATE_TIME); } } \ No newline at end of file diff --git a/src/main/java/com/fasterxml/jackson/databind/ser/std/SqlTimeSerializer.java b/src/main/java/com/fasterxml/jackson/databind/ser/std/SqlTimeSerializer.java index 7726f241ce..a4ae64bcc2 100644 --- a/src/main/java/com/fasterxml/jackson/databind/ser/std/SqlTimeSerializer.java +++ b/src/main/java/com/fasterxml/jackson/databind/ser/std/SqlTimeSerializer.java @@ -8,7 +8,7 @@ import com.fasterxml.jackson.databind.SerializerProvider; import com.fasterxml.jackson.databind.annotation.JacksonStdImpl; import com.fasterxml.jackson.databind.jsonschema.types.JsonValueFormat; -import com.fasterxml.jackson.databind.jsonschema.visitors.JsonFormatVisitor; +import com.fasterxml.jackson.databind.jsonschema.visitors.JsonFormatVisitorWrapper; @JacksonStdImpl public class SqlTimeSerializer @@ -24,8 +24,8 @@ public void serialize(java.sql.Time value, JsonGenerator jgen, SerializerProvide } @Override - public void acceptJsonFormatVisitor(JsonFormatVisitor visitor, JavaType typeHint) + public void acceptJsonFormatVisitor(JsonFormatVisitorWrapper visitor, JavaType typeHint) { - visitor.stringFormat(typeHint).format(JsonValueFormat.DATE_TIME); + visitor.expectStringFormat(typeHint).format(JsonValueFormat.DATE_TIME); } } \ No newline at end of file diff --git a/src/main/java/com/fasterxml/jackson/databind/ser/std/StaticListSerializerBase.java b/src/main/java/com/fasterxml/jackson/databind/ser/std/StaticListSerializerBase.java index f7f5957308..88aa71b302 100644 --- a/src/main/java/com/fasterxml/jackson/databind/ser/std/StaticListSerializerBase.java +++ b/src/main/java/com/fasterxml/jackson/databind/ser/std/StaticListSerializerBase.java @@ -4,7 +4,7 @@ import com.fasterxml.jackson.databind.JavaType; import com.fasterxml.jackson.databind.jsonschema.visitors.JsonArrayFormatVisitor; -import com.fasterxml.jackson.databind.jsonschema.visitors.JsonFormatVisitor; +import com.fasterxml.jackson.databind.jsonschema.visitors.JsonFormatVisitorWrapper; /** * Intermediate base class for Lists, Collections and Arrays @@ -23,9 +23,9 @@ public boolean isEmpty(T value) { } @Override - public void acceptJsonFormatVisitor(JsonFormatVisitor visitor, JavaType typeHint) + public void acceptJsonFormatVisitor(JsonFormatVisitorWrapper visitor, JavaType typeHint) { - acceptContentVisitor(visitor.arrayFormat(typeHint)); + acceptContentVisitor(visitor.expectArrayFormat(typeHint)); } /* diff --git a/src/main/java/com/fasterxml/jackson/databind/ser/std/StdArraySerializers.java b/src/main/java/com/fasterxml/jackson/databind/ser/std/StdArraySerializers.java index 0e5c133ccc..28394c27b2 100644 --- a/src/main/java/com/fasterxml/jackson/databind/ser/std/StdArraySerializers.java +++ b/src/main/java/com/fasterxml/jackson/databind/ser/std/StdArraySerializers.java @@ -12,7 +12,7 @@ import com.fasterxml.jackson.databind.SerializerProvider; import com.fasterxml.jackson.databind.annotation.JacksonStdImpl; import com.fasterxml.jackson.databind.jsonschema.types.SchemaType; -import com.fasterxml.jackson.databind.jsonschema.visitors.JsonFormatVisitor; +import com.fasterxml.jackson.databind.jsonschema.visitors.JsonFormatVisitorWrapper; import com.fasterxml.jackson.databind.jsontype.TypeSerializer; import com.fasterxml.jackson.databind.ser.ContainerSerializer; import com.fasterxml.jackson.databind.type.TypeFactory; @@ -133,9 +133,9 @@ public void serializeContents(boolean[] value, JsonGenerator jgen, SerializerPro } @Override - public void acceptJsonFormatVisitor(JsonFormatVisitor visitor, JavaType typeHint) + public void acceptJsonFormatVisitor(JsonFormatVisitorWrapper visitor, JavaType typeHint) { - visitor.arrayFormat(typeHint).itemsFormat(SchemaType.BOOLEAN); + visitor.expectArrayFormat(typeHint).itemsFormat(SchemaType.BOOLEAN); } } @@ -177,9 +177,9 @@ public void serializeWithType(byte[] value, JsonGenerator jgen, SerializerProvid } @Override - public void acceptJsonFormatVisitor(JsonFormatVisitor visitor, JavaType typeHint) + public void acceptJsonFormatVisitor(JsonFormatVisitorWrapper visitor, JavaType typeHint) { - visitor.arrayFormat(typeHint).itemsFormat(SchemaType.STRING); + visitor.expectArrayFormat(typeHint).itemsFormat(SchemaType.STRING); } } @@ -240,9 +240,9 @@ public void serializeContents(short[] value, JsonGenerator jgen, SerializerProvi } @Override - public void acceptJsonFormatVisitor(JsonFormatVisitor visitor, JavaType typeHint) + public void acceptJsonFormatVisitor(JsonFormatVisitorWrapper visitor, JavaType typeHint) { - visitor.arrayFormat(typeHint).itemsFormat(SchemaType.INTEGER); + visitor.expectArrayFormat(typeHint).itemsFormat(SchemaType.INTEGER); } } @@ -304,9 +304,9 @@ private final void _writeArrayContents(JsonGenerator jgen, char[] value) } @Override - public void acceptJsonFormatVisitor(JsonFormatVisitor visitor, JavaType typeHint) + public void acceptJsonFormatVisitor(JsonFormatVisitorWrapper visitor, JavaType typeHint) { - visitor.arrayFormat(typeHint).itemsFormat(SchemaType.STRING); + visitor.expectArrayFormat(typeHint).itemsFormat(SchemaType.STRING); } } @@ -359,9 +359,9 @@ public void serializeContents(int[] value, JsonGenerator jgen, SerializerProvide } @Override - public void acceptJsonFormatVisitor(JsonFormatVisitor visitor, JavaType typeHint) + public void acceptJsonFormatVisitor(JsonFormatVisitorWrapper visitor, JavaType typeHint) { - visitor.arrayFormat(typeHint).itemsFormat(SchemaType.INTEGER); + visitor.expectArrayFormat(typeHint).itemsFormat(SchemaType.INTEGER); } } @@ -423,9 +423,9 @@ public void serializeContents(long[] value, JsonGenerator jgen, SerializerProvid } @Override - public void acceptJsonFormatVisitor(JsonFormatVisitor visitor, JavaType typeHint) + public void acceptJsonFormatVisitor(JsonFormatVisitorWrapper visitor, JavaType typeHint) { - visitor.arrayFormat(typeHint).itemsFormat(SchemaType.NUMBER); + visitor.expectArrayFormat(typeHint).itemsFormat(SchemaType.NUMBER); } } @@ -488,9 +488,9 @@ public void serializeContents(float[] value, JsonGenerator jgen, SerializerProvi } @Override - public void acceptJsonFormatVisitor(JsonFormatVisitor visitor, JavaType typeHint) + public void acceptJsonFormatVisitor(JsonFormatVisitorWrapper visitor, JavaType typeHint) { - visitor.arrayFormat(typeHint).itemsFormat(SchemaType.NUMBER); + visitor.expectArrayFormat(typeHint).itemsFormat(SchemaType.NUMBER); } } @@ -543,9 +543,9 @@ public void serializeContents(double[] value, JsonGenerator jgen, SerializerProv } @Override - public void acceptJsonFormatVisitor(JsonFormatVisitor visitor, JavaType typeHint) + public void acceptJsonFormatVisitor(JsonFormatVisitorWrapper visitor, JavaType typeHint) { - visitor.arrayFormat(typeHint).itemsFormat(SchemaType.NUMBER); + visitor.expectArrayFormat(typeHint).itemsFormat(SchemaType.NUMBER); } } } diff --git a/src/main/java/com/fasterxml/jackson/databind/ser/std/StdJdkSerializers.java b/src/main/java/com/fasterxml/jackson/databind/ser/std/StdJdkSerializers.java index ad1d4c8751..9fb931f871 100644 --- a/src/main/java/com/fasterxml/jackson/databind/ser/std/StdJdkSerializers.java +++ b/src/main/java/com/fasterxml/jackson/databind/ser/std/StdJdkSerializers.java @@ -17,7 +17,7 @@ import com.fasterxml.jackson.core.JsonGenerator; import com.fasterxml.jackson.databind.JavaType; import com.fasterxml.jackson.databind.SerializerProvider; -import com.fasterxml.jackson.databind.jsonschema.visitors.JsonFormatVisitor; +import com.fasterxml.jackson.databind.jsonschema.visitors.JsonFormatVisitorWrapper; import com.fasterxml.jackson.databind.ser.BasicSerializerFactory; import com.fasterxml.jackson.databind.util.Provider; @@ -87,9 +87,9 @@ public void serialize(AtomicBoolean value, JsonGenerator jgen, SerializerProvide } @Override - public void acceptJsonFormatVisitor(JsonFormatVisitor visitor, JavaType typeHint) + public void acceptJsonFormatVisitor(JsonFormatVisitorWrapper visitor, JavaType typeHint) { - visitor.booleanFormat(typeHint); + visitor.expectBooleanFormat(typeHint); } } @@ -106,9 +106,9 @@ public void serialize(AtomicInteger value, JsonGenerator jgen, SerializerProvide } @Override - public void acceptJsonFormatVisitor(JsonFormatVisitor visitor, JavaType typeHint) + public void acceptJsonFormatVisitor(JsonFormatVisitorWrapper visitor, JavaType typeHint) { - visitor.integerFormat(typeHint); + visitor.expectIntegerFormat(typeHint); } } @@ -125,9 +125,9 @@ public void serialize(AtomicLong value, JsonGenerator jgen, SerializerProvider p } @Override - public void acceptJsonFormatVisitor(JsonFormatVisitor visitor, JavaType typeHint) + public void acceptJsonFormatVisitor(JsonFormatVisitorWrapper visitor, JavaType typeHint) { - visitor.integerFormat(typeHint); + visitor.expectIntegerFormat(typeHint); } } @@ -144,9 +144,9 @@ public void serialize(AtomicReference value, JsonGenerator jgen, SerializerPr } @Override - public void acceptJsonFormatVisitor(JsonFormatVisitor visitor, JavaType typeHint) + public void acceptJsonFormatVisitor(JsonFormatVisitorWrapper visitor, JavaType typeHint) { - visitor.anyFormat(typeHint); + visitor.expectAnyFormat(typeHint); } } @@ -173,9 +173,9 @@ public void serialize(File value, JsonGenerator jgen, SerializerProvider provide } @Override - public void acceptJsonFormatVisitor(JsonFormatVisitor visitor, JavaType typeHint) + public void acceptJsonFormatVisitor(JsonFormatVisitorWrapper visitor, JavaType typeHint) { - visitor.stringFormat(typeHint); + visitor.expectStringFormat(typeHint); } } @@ -196,9 +196,9 @@ public void serialize(Class value, JsonGenerator jgen, SerializerProvider pro } @Override - public void acceptJsonFormatVisitor(JsonFormatVisitor visitor, JavaType typeHint) + public void acceptJsonFormatVisitor(JsonFormatVisitorWrapper visitor, JavaType typeHint) { - visitor.stringFormat(typeHint); + visitor.expectStringFormat(typeHint); } } } diff --git a/src/main/java/com/fasterxml/jackson/databind/ser/std/StdKeySerializer.java b/src/main/java/com/fasterxml/jackson/databind/ser/std/StdKeySerializer.java index 506de40139..319565f17f 100644 --- a/src/main/java/com/fasterxml/jackson/databind/ser/std/StdKeySerializer.java +++ b/src/main/java/com/fasterxml/jackson/databind/ser/std/StdKeySerializer.java @@ -7,7 +7,7 @@ import com.fasterxml.jackson.core.JsonGenerator; import com.fasterxml.jackson.databind.JavaType; import com.fasterxml.jackson.databind.SerializerProvider; -import com.fasterxml.jackson.databind.jsonschema.visitors.JsonFormatVisitor; +import com.fasterxml.jackson.databind.jsonschema.visitors.JsonFormatVisitorWrapper; /** * Specialized serializer that can be used as the generic key @@ -33,8 +33,8 @@ public void serialize(Object value, JsonGenerator jgen, SerializerProvider provi } @Override - public void acceptJsonFormatVisitor(JsonFormatVisitor visitor, JavaType typeHint) + public void acceptJsonFormatVisitor(JsonFormatVisitorWrapper visitor, JavaType typeHint) { - visitor.stringFormat(typeHint); + visitor.expectStringFormat(typeHint); } } diff --git a/src/main/java/com/fasterxml/jackson/databind/ser/std/StdScalarSerializer.java b/src/main/java/com/fasterxml/jackson/databind/ser/std/StdScalarSerializer.java index a51149857f..659c5ea958 100644 --- a/src/main/java/com/fasterxml/jackson/databind/ser/std/StdScalarSerializer.java +++ b/src/main/java/com/fasterxml/jackson/databind/ser/std/StdScalarSerializer.java @@ -6,7 +6,7 @@ import com.fasterxml.jackson.core.JsonGenerator; import com.fasterxml.jackson.databind.JavaType; import com.fasterxml.jackson.databind.SerializerProvider; -import com.fasterxml.jackson.databind.jsonschema.visitors.JsonFormatVisitor; +import com.fasterxml.jackson.databind.jsonschema.visitors.JsonFormatVisitorWrapper; import com.fasterxml.jackson.databind.jsontype.TypeSerializer; public abstract class StdScalarSerializer @@ -43,8 +43,8 @@ public void serializeWithType(T value, JsonGenerator jgen, SerializerProvider pr } @Override - public void acceptJsonFormatVisitor(JsonFormatVisitor visitor, JavaType typeHint) + public void acceptJsonFormatVisitor(JsonFormatVisitorWrapper visitor, JavaType typeHint) { - visitor.anyFormat(typeHint); + visitor.expectAnyFormat(typeHint); } } diff --git a/src/main/java/com/fasterxml/jackson/databind/ser/std/StdSerializer.java b/src/main/java/com/fasterxml/jackson/databind/ser/std/StdSerializer.java index 8110b731c0..152db6767a 100644 --- a/src/main/java/com/fasterxml/jackson/databind/ser/std/StdSerializer.java +++ b/src/main/java/com/fasterxml/jackson/databind/ser/std/StdSerializer.java @@ -12,7 +12,7 @@ import com.fasterxml.jackson.databind.SerializerProvider; import com.fasterxml.jackson.databind.annotation.JacksonStdImpl; import com.fasterxml.jackson.databind.jsonschema.JsonFormatVisitorAware; -import com.fasterxml.jackson.databind.jsonschema.visitors.JsonFormatVisitor; +import com.fasterxml.jackson.databind.jsonschema.visitors.JsonFormatVisitorWrapper; /** * Base class used by all standard serializers, and can also @@ -83,8 +83,8 @@ public abstract void serialize(T value, JsonGenerator jgen, SerializerProvider p * overriden by custom serializers. */ // @Override - public void acceptJsonFormatVisitor(JsonFormatVisitor visitor, JavaType typeHint) { - visitor.anyFormat(typeHint); + public void acceptJsonFormatVisitor(JsonFormatVisitorWrapper visitor, JavaType typeHint) { + visitor.expectAnyFormat(typeHint); } /* diff --git a/src/main/java/com/fasterxml/jackson/databind/ser/std/StringSerializer.java b/src/main/java/com/fasterxml/jackson/databind/ser/std/StringSerializer.java index 1012fda1cc..0dea68672f 100644 --- a/src/main/java/com/fasterxml/jackson/databind/ser/std/StringSerializer.java +++ b/src/main/java/com/fasterxml/jackson/databind/ser/std/StringSerializer.java @@ -7,7 +7,7 @@ import com.fasterxml.jackson.databind.JavaType; import com.fasterxml.jackson.databind.SerializerProvider; import com.fasterxml.jackson.databind.annotation.JacksonStdImpl; -import com.fasterxml.jackson.databind.jsonschema.visitors.JsonFormatVisitor; +import com.fasterxml.jackson.databind.jsonschema.visitors.JsonFormatVisitorWrapper; /** * This is the special serializer for regular {@link java.lang.String}s. @@ -37,8 +37,8 @@ public void serialize(String value, JsonGenerator jgen, SerializerProvider provi } @Override - public void acceptJsonFormatVisitor(JsonFormatVisitor visitor, JavaType typeHint) + public void acceptJsonFormatVisitor(JsonFormatVisitorWrapper visitor, JavaType typeHint) { - visitor.stringFormat(typeHint); + visitor.expectStringFormat(typeHint); } } diff --git a/src/main/java/com/fasterxml/jackson/databind/ser/std/ToStringSerializer.java b/src/main/java/com/fasterxml/jackson/databind/ser/std/ToStringSerializer.java index c4eca61966..54f30d9ab4 100644 --- a/src/main/java/com/fasterxml/jackson/databind/ser/std/ToStringSerializer.java +++ b/src/main/java/com/fasterxml/jackson/databind/ser/std/ToStringSerializer.java @@ -7,7 +7,7 @@ import com.fasterxml.jackson.databind.JavaType; import com.fasterxml.jackson.databind.SerializerProvider; import com.fasterxml.jackson.databind.annotation.JacksonStdImpl; -import com.fasterxml.jackson.databind.jsonschema.visitors.JsonFormatVisitor; +import com.fasterxml.jackson.databind.jsonschema.visitors.JsonFormatVisitorWrapper; import com.fasterxml.jackson.databind.jsontype.TypeSerializer; /** @@ -73,9 +73,9 @@ public void serializeWithType(Object value, JsonGenerator jgen, SerializerProvid } @Override - public void acceptJsonFormatVisitor(JsonFormatVisitor visitor, JavaType typeHint) + public void acceptJsonFormatVisitor(JsonFormatVisitorWrapper visitor, JavaType typeHint) { - visitor.stringFormat(typeHint); + visitor.expectStringFormat(typeHint); } } diff --git a/src/main/java/com/fasterxml/jackson/databind/ser/std/TokenBufferSerializer.java b/src/main/java/com/fasterxml/jackson/databind/ser/std/TokenBufferSerializer.java index 3bf5c8322f..9d8032321a 100644 --- a/src/main/java/com/fasterxml/jackson/databind/ser/std/TokenBufferSerializer.java +++ b/src/main/java/com/fasterxml/jackson/databind/ser/std/TokenBufferSerializer.java @@ -7,7 +7,7 @@ import com.fasterxml.jackson.databind.JavaType; import com.fasterxml.jackson.databind.SerializerProvider; import com.fasterxml.jackson.databind.annotation.JacksonStdImpl; -import com.fasterxml.jackson.databind.jsonschema.visitors.JsonFormatVisitor; +import com.fasterxml.jackson.databind.jsonschema.visitors.JsonFormatVisitorWrapper; import com.fasterxml.jackson.databind.jsontype.TypeSerializer; import com.fasterxml.jackson.databind.util.TokenBuffer; @@ -53,12 +53,12 @@ public final void serializeWithType(TokenBuffer value, JsonGenerator jgen, Seria } @Override - public void acceptJsonFormatVisitor(JsonFormatVisitor visitor, JavaType typeHint) + public void acceptJsonFormatVisitor(JsonFormatVisitorWrapper visitor, JavaType typeHint) { /* 01-Jan-2010, tatu: Not 100% sure what we should say here: * type is basically not known. This seems closest * approximation */ - visitor.anyFormat(typeHint); + visitor.expectAnyFormat(typeHint); } } diff --git a/src/test/java/com/fasterxml/jackson/databind/jsonschema/TestGenerateJsonSchema.java b/src/test/java/com/fasterxml/jackson/databind/jsonschema/TestGenerateJsonSchema.java index f22943f8fc..0b255e4d33 100644 --- a/src/test/java/com/fasterxml/jackson/databind/jsonschema/TestGenerateJsonSchema.java +++ b/src/test/java/com/fasterxml/jackson/databind/jsonschema/TestGenerateJsonSchema.java @@ -111,7 +111,7 @@ public void testGeneratingJsonSchema() throws Exception { ObjectMapper m = new ObjectMapper(); - SchemaFactory visitor = new SchemaFactory(); + SchemaFactoryProvider visitor = new SchemaFactoryProvider(); m.acceptJsonFormatVisitor(SimpleBean.class, visitor); JsonSchema jsonSchema = visitor.finalSchema(); @@ -185,7 +185,7 @@ private static class FilteredBean { public void testGeneratingJsonSchemaWithFilters() throws Exception { ObjectMapper mapper = new ObjectMapper(); mapper.setFilters(secretFilterProvider); - SchemaFactory visitor = new SchemaFactory(); + SchemaFactoryProvider visitor = new SchemaFactoryProvider(); mapper.acceptJsonFormatVisitor(FilteredBean.class, visitor); JsonSchema jsonSchema = visitor.finalSchema(); assertNotNull(jsonSchema); @@ -207,7 +207,7 @@ public void testGeneratingJsonSchemaWithFilters() throws Exception { public void testSchemaSerialization() throws Exception { - SchemaFactory visitor = new SchemaFactory(); + SchemaFactoryProvider visitor = new SchemaFactoryProvider(); MAPPER.acceptJsonFormatVisitor(SimpleBean.class, visitor); JsonSchema jsonSchema = visitor.finalSchema(); Map result = writeAndMap(MAPPER, jsonSchema); @@ -224,7 +224,7 @@ public void testInvalidCall() { // not ok to pass null try { - SchemaFactory visitor = new SchemaFactory(); + SchemaFactoryProvider visitor = new SchemaFactoryProvider(); MAPPER.acceptJsonFormatVisitor(null, visitor); JsonSchema jsonSchema = visitor.finalSchema(); fail("Should have failed"); @@ -238,7 +238,7 @@ public void testInvalidCall() */ public void testThatObjectsHaveNoItems() throws Exception { - SchemaFactory visitor = new SchemaFactory(); + SchemaFactoryProvider visitor = new SchemaFactoryProvider(); MAPPER.acceptJsonFormatVisitor(TrivialBean.class, visitor); JsonSchema jsonSchema = visitor.finalSchema(); Map result = writeAndMap(MAPPER, jsonSchema); @@ -251,7 +251,7 @@ public void testThatObjectsHaveNoItems() throws Exception @SuppressWarnings({ "unchecked", "rawtypes", "serial" }) public void testSchemaId() throws Exception { - SchemaFactory visitor = new SchemaFactory(); + SchemaFactoryProvider visitor = new SchemaFactoryProvider(); MAPPER.acceptJsonFormatVisitor(BeanWithId.class, visitor); JsonSchema jsonSchema = visitor.finalSchema(); Map result = writeAndMap(MAPPER, jsonSchema); diff --git a/src/test/java/com/fasterxml/jackson/databind/jsonschema/TestReadJsonSchema.java b/src/test/java/com/fasterxml/jackson/databind/jsonschema/TestReadJsonSchema.java index 4865cbb76f..0e779a6027 100644 --- a/src/test/java/com/fasterxml/jackson/databind/jsonschema/TestReadJsonSchema.java +++ b/src/test/java/com/fasterxml/jackson/databind/jsonschema/TestReadJsonSchema.java @@ -51,7 +51,7 @@ static class Schemable { public void testDeserializeSimple() throws Exception { ObjectMapper mapper = new ObjectMapper(); - SchemaFactory visitor = new SchemaFactory(); + SchemaFactoryProvider visitor = new SchemaFactoryProvider(); mapper.acceptJsonFormatVisitor(Schemable.class, visitor); JsonSchema jsonSchema = visitor.finalSchema(); assertNotNull(jsonSchema); diff --git a/src/test/java/com/fasterxml/jackson/databind/module/TestSimpleModule.java b/src/test/java/com/fasterxml/jackson/databind/module/TestSimpleModule.java index 2ce4f21518..3381a2d683 100644 --- a/src/test/java/com/fasterxml/jackson/databind/module/TestSimpleModule.java +++ b/src/test/java/com/fasterxml/jackson/databind/module/TestSimpleModule.java @@ -7,7 +7,7 @@ import com.fasterxml.jackson.core.*; import com.fasterxml.jackson.annotation.JsonPropertyOrder; import com.fasterxml.jackson.databind.*; -import com.fasterxml.jackson.databind.jsonschema.visitors.JsonFormatVisitor; +import com.fasterxml.jackson.databind.jsonschema.visitors.JsonFormatVisitorWrapper; import com.fasterxml.jackson.databind.module.SimpleDeserializers; import com.fasterxml.jackson.databind.module.SimpleModule; import com.fasterxml.jackson.databind.module.SimpleSerializers; @@ -52,8 +52,8 @@ public void serialize(CustomBean value, JsonGenerator jgen, SerializerProvider p } @Override - public void acceptJsonFormatVisitor(JsonFormatVisitor visitor, JavaType typeHint) { - visitor.anyFormat(typeHint); + public void acceptJsonFormatVisitor(JsonFormatVisitorWrapper visitor, JavaType typeHint) { + visitor.expectAnyFormat(typeHint); } } @@ -86,8 +86,8 @@ public void serialize(SimpleEnum value, JsonGenerator jgen, SerializerProvider p } @Override - public void acceptJsonFormatVisitor(JsonFormatVisitor visitor, JavaType typeHint) { - visitor.anyFormat(typeHint); + public void acceptJsonFormatVisitor(JsonFormatVisitorWrapper visitor, JavaType typeHint) { + visitor.expectAnyFormat(typeHint); } } From c11852f2f3f0ea1ddc2a1e379d47c6bae23620f6 Mon Sep 17 00:00:00 2001 From: jackphel Date: Tue, 7 Aug 2012 16:51:27 -0400 Subject: [PATCH 15/19] factored getSchema into SchemaFactory --- .../databind/jsonschema/SchemaFactoryProvider.java | 2 +- .../databind/jsonschema/factories/AnySchemaFactory.java | 2 +- .../databind/jsonschema/factories/ArraySchemaFactory.java | 3 ++- .../jsonschema/factories/BooleanSchemaFactory.java | 2 +- .../jsonschema/factories/IntegerSchemaFactory.java | 2 +- .../databind/jsonschema/factories/NullSchemaFactory.java | 2 +- .../jsonschema/factories/NumberSchemaFactory.java | 2 +- .../jsonschema/factories/ObjectSchemaFactory.java | 3 ++- .../databind/jsonschema/factories/SchemaFactory.java | 6 ++---- .../jsonschema/factories/SchemaFactoryDelegate.java | 8 -------- .../jsonschema/factories/StringSchemaFactory.java | 4 ++-- .../jsonschema/factories/ValueTypeSchemaFactory.java | 2 +- 12 files changed, 15 insertions(+), 23 deletions(-) delete mode 100644 src/main/java/com/fasterxml/jackson/databind/jsonschema/factories/SchemaFactoryDelegate.java diff --git a/src/main/java/com/fasterxml/jackson/databind/jsonschema/SchemaFactoryProvider.java b/src/main/java/com/fasterxml/jackson/databind/jsonschema/SchemaFactoryProvider.java index 0d0a8da550..eeaee53142 100644 --- a/src/main/java/com/fasterxml/jackson/databind/jsonschema/SchemaFactoryProvider.java +++ b/src/main/java/com/fasterxml/jackson/databind/jsonschema/SchemaFactoryProvider.java @@ -21,7 +21,7 @@ public class SchemaFactoryProvider implements JsonFormatVisitorWrapper{ protected SerializerProvider provider; - private SchemaFactoryDelegate delegate; + private SchemaFactory delegate; /** * {@link SchemaFactory#provider} diff --git a/src/main/java/com/fasterxml/jackson/databind/jsonschema/factories/AnySchemaFactory.java b/src/main/java/com/fasterxml/jackson/databind/jsonschema/factories/AnySchemaFactory.java index a39b7ef834..a0fd061de8 100644 --- a/src/main/java/com/fasterxml/jackson/databind/jsonschema/factories/AnySchemaFactory.java +++ b/src/main/java/com/fasterxml/jackson/databind/jsonschema/factories/AnySchemaFactory.java @@ -6,7 +6,7 @@ import com.fasterxml.jackson.databind.jsonschema.visitors.JsonAnyFormatVisitor; public class AnySchemaFactory extends SchemaFactory implements - JsonAnyFormatVisitor, SchemaFactoryDelegate { + JsonAnyFormatVisitor { protected SchemaFactory parent; protected AnySchema anySchema; diff --git a/src/main/java/com/fasterxml/jackson/databind/jsonschema/factories/ArraySchemaFactory.java b/src/main/java/com/fasterxml/jackson/databind/jsonschema/factories/ArraySchemaFactory.java index 5022dee81b..3bd464920b 100644 --- a/src/main/java/com/fasterxml/jackson/databind/jsonschema/factories/ArraySchemaFactory.java +++ b/src/main/java/com/fasterxml/jackson/databind/jsonschema/factories/ArraySchemaFactory.java @@ -12,7 +12,8 @@ import com.fasterxml.jackson.databind.jsonschema.types.SchemaType; import com.fasterxml.jackson.databind.jsonschema.visitors.JsonArrayFormatVisitor; -public class ArraySchemaFactory extends SchemaFactory implements JsonArrayFormatVisitor, SchemaFactoryDelegate { +public class ArraySchemaFactory extends SchemaFactory + implements JsonArrayFormatVisitor { protected SchemaFactory parent; protected ArraySchema arraySchema; diff --git a/src/main/java/com/fasterxml/jackson/databind/jsonschema/factories/BooleanSchemaFactory.java b/src/main/java/com/fasterxml/jackson/databind/jsonschema/factories/BooleanSchemaFactory.java index a27318eac9..f793c414dd 100644 --- a/src/main/java/com/fasterxml/jackson/databind/jsonschema/factories/BooleanSchemaFactory.java +++ b/src/main/java/com/fasterxml/jackson/databind/jsonschema/factories/BooleanSchemaFactory.java @@ -6,7 +6,7 @@ import com.fasterxml.jackson.databind.jsonschema.visitors.JsonBooleanFormatVisitor; public class BooleanSchemaFactory extends ValueTypeSchemaFactory implements - SchemaFactoryDelegate, JsonBooleanFormatVisitor { + JsonBooleanFormatVisitor { protected BooleanSchema booleanSchema; diff --git a/src/main/java/com/fasterxml/jackson/databind/jsonschema/factories/IntegerSchemaFactory.java b/src/main/java/com/fasterxml/jackson/databind/jsonschema/factories/IntegerSchemaFactory.java index 6ad6d5e445..483755bef7 100644 --- a/src/main/java/com/fasterxml/jackson/databind/jsonschema/factories/IntegerSchemaFactory.java +++ b/src/main/java/com/fasterxml/jackson/databind/jsonschema/factories/IntegerSchemaFactory.java @@ -6,7 +6,7 @@ import com.fasterxml.jackson.databind.jsonschema.visitors.JsonIntegerFormatVisitor; public class IntegerSchemaFactory extends ValueTypeSchemaFactory implements - JsonIntegerFormatVisitor, SchemaFactoryDelegate { + JsonIntegerFormatVisitor { protected IntegerSchema integerSchema; diff --git a/src/main/java/com/fasterxml/jackson/databind/jsonschema/factories/NullSchemaFactory.java b/src/main/java/com/fasterxml/jackson/databind/jsonschema/factories/NullSchemaFactory.java index 7caa64c702..b27738f587 100644 --- a/src/main/java/com/fasterxml/jackson/databind/jsonschema/factories/NullSchemaFactory.java +++ b/src/main/java/com/fasterxml/jackson/databind/jsonschema/factories/NullSchemaFactory.java @@ -6,7 +6,7 @@ import com.fasterxml.jackson.databind.jsonschema.visitors.JsonNullFormatVisitor; public class NullSchemaFactory extends SchemaFactory implements - JsonNullFormatVisitor, SchemaFactoryDelegate { + JsonNullFormatVisitor { protected SchemaFactory parent; protected NullSchema nullSchema; diff --git a/src/main/java/com/fasterxml/jackson/databind/jsonschema/factories/NumberSchemaFactory.java b/src/main/java/com/fasterxml/jackson/databind/jsonschema/factories/NumberSchemaFactory.java index 672d04a47e..e0d6e74f55 100644 --- a/src/main/java/com/fasterxml/jackson/databind/jsonschema/factories/NumberSchemaFactory.java +++ b/src/main/java/com/fasterxml/jackson/databind/jsonschema/factories/NumberSchemaFactory.java @@ -6,7 +6,7 @@ import com.fasterxml.jackson.databind.jsonschema.visitors.JsonNumberFormatVisitor; public class NumberSchemaFactory extends ValueTypeSchemaFactory implements - JsonNumberFormatVisitor, SchemaFactoryDelegate { + JsonNumberFormatVisitor { protected NumberSchema numberSchema; diff --git a/src/main/java/com/fasterxml/jackson/databind/jsonschema/factories/ObjectSchemaFactory.java b/src/main/java/com/fasterxml/jackson/databind/jsonschema/factories/ObjectSchemaFactory.java index 25688b5d17..540e6095ae 100644 --- a/src/main/java/com/fasterxml/jackson/databind/jsonschema/factories/ObjectSchemaFactory.java +++ b/src/main/java/com/fasterxml/jackson/databind/jsonschema/factories/ObjectSchemaFactory.java @@ -13,7 +13,8 @@ import com.fasterxml.jackson.databind.jsonschema.visitors.JsonObjectFormatVisitor; import com.fasterxml.jackson.databind.ser.BeanPropertyWriter; -public class ObjectSchemaFactory extends SchemaFactory implements JsonObjectFormatVisitor, SchemaFactoryDelegate { +public class ObjectSchemaFactory extends SchemaFactory + implements JsonObjectFormatVisitor { protected SchemaFactory parent; protected ObjectSchema objectSchema; diff --git a/src/main/java/com/fasterxml/jackson/databind/jsonschema/factories/SchemaFactory.java b/src/main/java/com/fasterxml/jackson/databind/jsonschema/factories/SchemaFactory.java index ca35f4398d..e7b6e3af62 100644 --- a/src/main/java/com/fasterxml/jackson/databind/jsonschema/factories/SchemaFactory.java +++ b/src/main/java/com/fasterxml/jackson/databind/jsonschema/factories/SchemaFactory.java @@ -1,15 +1,12 @@ package com.fasterxml.jackson.databind.jsonschema.factories; import com.fasterxml.jackson.databind.SerializerProvider; +import com.fasterxml.jackson.databind.jsonschema.types.JsonSchema; public abstract class SchemaFactory { protected SerializerProvider provider; - - public SchemaFactory() { - } - /** @@ -24,5 +21,6 @@ public SerializerProvider getProvider() { return provider; } + public abstract JsonSchema getSchema(); } diff --git a/src/main/java/com/fasterxml/jackson/databind/jsonschema/factories/SchemaFactoryDelegate.java b/src/main/java/com/fasterxml/jackson/databind/jsonschema/factories/SchemaFactoryDelegate.java deleted file mode 100644 index 21af14cdff..0000000000 --- a/src/main/java/com/fasterxml/jackson/databind/jsonschema/factories/SchemaFactoryDelegate.java +++ /dev/null @@ -1,8 +0,0 @@ -package com.fasterxml.jackson.databind.jsonschema.factories; - -import com.fasterxml.jackson.databind.jsonschema.types.JsonSchema; - -public interface SchemaFactoryDelegate { - - public JsonSchema getSchema(); -} diff --git a/src/main/java/com/fasterxml/jackson/databind/jsonschema/factories/StringSchemaFactory.java b/src/main/java/com/fasterxml/jackson/databind/jsonschema/factories/StringSchemaFactory.java index 3dcb84a2cb..3b4497b53a 100644 --- a/src/main/java/com/fasterxml/jackson/databind/jsonschema/factories/StringSchemaFactory.java +++ b/src/main/java/com/fasterxml/jackson/databind/jsonschema/factories/StringSchemaFactory.java @@ -5,8 +5,8 @@ import com.fasterxml.jackson.databind.jsonschema.types.ValueTypeSchema; import com.fasterxml.jackson.databind.jsonschema.visitors.JsonStringFormatVisitor; -public class StringSchemaFactory extends ValueTypeSchemaFactory implements JsonStringFormatVisitor, - SchemaFactoryDelegate { +public class StringSchemaFactory extends ValueTypeSchemaFactory + implements JsonStringFormatVisitor{ protected StringSchema stringSchema; diff --git a/src/main/java/com/fasterxml/jackson/databind/jsonschema/factories/ValueTypeSchemaFactory.java b/src/main/java/com/fasterxml/jackson/databind/jsonschema/factories/ValueTypeSchemaFactory.java index d0543c89c3..51516fb539 100644 --- a/src/main/java/com/fasterxml/jackson/databind/jsonschema/factories/ValueTypeSchemaFactory.java +++ b/src/main/java/com/fasterxml/jackson/databind/jsonschema/factories/ValueTypeSchemaFactory.java @@ -9,7 +9,7 @@ import com.fasterxml.jackson.databind.jsonschema.visitors.JsonValueFormatVisitor; public abstract class ValueTypeSchemaFactory extends SchemaFactory implements - SchemaFactoryDelegate, JsonValueFormatVisitor { + JsonValueFormatVisitor { protected SchemaFactory parent; From 6288e8b07209d53e097f76548871b645f1d83aa9 Mon Sep 17 00:00:00 2001 From: jackphel Date: Tue, 7 Aug 2012 16:53:46 -0400 Subject: [PATCH 16/19] schema here does NOT refer to JSON Schema (but rather to thing like what CSV module needs -- unfortunate overload for sure). --- src/main/java/com/fasterxml/jackson/databind/ObjectMapper.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/com/fasterxml/jackson/databind/ObjectMapper.java b/src/main/java/com/fasterxml/jackson/databind/ObjectMapper.java index bef21be0d8..9f6e023e6e 100644 --- a/src/main/java/com/fasterxml/jackson/databind/ObjectMapper.java +++ b/src/main/java/com/fasterxml/jackson/databind/ObjectMapper.java @@ -2148,7 +2148,7 @@ public ObjectWriter writer(FilterProvider filterProvider) { * pass specific schema object to {@link JsonGenerator} used for * writing content. * - * @param schema JsonSchema to pass to generator + * @param schema Schema to pass to generator */ public ObjectWriter writer(FormatSchema schema) { return new ObjectWriter(this, getSerializationConfig(), schema); From 248ab7eab8e41375acacfe55731188a5a280cd8a Mon Sep 17 00:00:00 2001 From: jackphel Date: Tue, 7 Aug 2012 18:48:27 -0400 Subject: [PATCH 17/19] removed unused constructor in arrayschemafactory --- .../databind/jsonschema/factories/ArraySchemaFactory.java | 2 -- .../databind/jsonschema/visitors/JsonArrayFormatVisitor.java | 3 --- 2 files changed, 5 deletions(-) diff --git a/src/main/java/com/fasterxml/jackson/databind/jsonschema/factories/ArraySchemaFactory.java b/src/main/java/com/fasterxml/jackson/databind/jsonschema/factories/ArraySchemaFactory.java index 3bd464920b..527840e95c 100644 --- a/src/main/java/com/fasterxml/jackson/databind/jsonschema/factories/ArraySchemaFactory.java +++ b/src/main/java/com/fasterxml/jackson/databind/jsonschema/factories/ArraySchemaFactory.java @@ -57,8 +57,6 @@ public void itemsFormat(JavaType contentType) { } } - public void itemsFormat(JsonFormatVisitorAware toVisit) {} - public void itemsFormat(SchemaType format) { arraySchema.setItemsSchema(JsonSchema.minimalForFormat(format)); } diff --git a/src/main/java/com/fasterxml/jackson/databind/jsonschema/visitors/JsonArrayFormatVisitor.java b/src/main/java/com/fasterxml/jackson/databind/jsonschema/visitors/JsonArrayFormatVisitor.java index 1eb06b6337..cb35982649 100644 --- a/src/main/java/com/fasterxml/jackson/databind/jsonschema/visitors/JsonArrayFormatVisitor.java +++ b/src/main/java/com/fasterxml/jackson/databind/jsonschema/visitors/JsonArrayFormatVisitor.java @@ -1,7 +1,6 @@ package com.fasterxml.jackson.databind.jsonschema.visitors; import com.fasterxml.jackson.databind.JavaType; -import com.fasterxml.jackson.databind.jsonschema.JsonFormatVisitorAware; import com.fasterxml.jackson.databind.jsonschema.types.SchemaType; public interface JsonArrayFormatVisitor extends JsonFormatVisitorWithSerializerProvider { @@ -10,6 +9,4 @@ public interface JsonArrayFormatVisitor extends JsonFormatVisitorWithSerializerP void itemsFormat(SchemaType format); - void itemsFormat(JsonFormatVisitorAware toVisit); - } From 8f665dd08ef273683363eeab62c77104160089b9 Mon Sep 17 00:00:00 2001 From: jackphel Date: Fri, 10 Aug 2012 12:49:55 -0400 Subject: [PATCH 18/19] refactored packages for separation moved jsonschema.visitors to jsonFormatVisitors removed jsonSchema as a terminal package auto changed imports for all interested parties --- pom.xml | 3 +++ .../jackson/databind/ObjectMapper.java | 2 +- .../databind/ext/CoreXMLSerializers.java | 2 +- .../jackson/databind/ext/DOMSerializer.java | 2 +- .../JsonAnyFormatVisitor.java | 5 +++++ .../JsonArrayFormatVisitor.java | 2 +- .../JsonBooleanFormatVisitor.java | 2 +- .../JsonFormatVisitorAware.java | 3 +-- ...onFormatVisitorWithSerializerProvider.java | 2 +- .../JsonFormatVisitorWrapper.java | 2 +- .../JsonIntegerFormatVisitor.java | 2 +- .../JsonNullFormatVisitor.java | 5 +++++ .../JsonNumberFormatVisitor.java | 2 +- .../JsonObjectFormatVisitor.java | 3 +-- .../JsonStringFormatVisitor.java | 2 +- .../JsonValueFormatVisitor.java | 2 +- .../factories/AnySchemaFactory.java | 2 +- .../factories/ArraySchemaFactory.java | 5 ++--- .../factories/BooleanSchemaFactory.java | 2 +- .../factories/IntegerSchemaFactory.java | 2 +- .../factories/NullSchemaFactory.java | 2 +- .../factories/NumberSchemaFactory.java | 2 +- .../factories/ObjectSchemaFactory.java | 5 ++--- .../SchemaFactoryProvider.java | 20 +++++++++---------- .../factories/StringSchemaFactory.java | 2 +- .../factories/ValueTypeSchemaFactory.java | 2 +- .../databind/jsonschema/package-info.java | 5 ----- .../visitors/JsonAnyFormatVisitor.java | 5 ----- .../visitors/JsonNullFormatVisitor.java | 5 ----- .../databind/ser/BeanPropertyFilter.java | 2 +- .../ser/DefaultSerializerProvider.java | 4 ++-- .../databind/ser/impl/FailingSerializer.java | 2 +- .../ser/impl/IndexedStringListSerializer.java | 2 +- .../ser/impl/SimpleBeanPropertyFilter.java | 2 +- .../ser/impl/StringArraySerializer.java | 2 +- .../ser/impl/StringCollectionSerializer.java | 2 +- .../databind/ser/impl/UnknownSerializer.java | 2 +- .../ser/std/AsArraySerializerBase.java | 4 ++-- .../databind/ser/std/BeanSerializerBase.java | 6 +++--- .../databind/ser/std/BooleanSerializer.java | 2 +- .../ser/std/DateTimeSerializerBase.java | 2 +- .../databind/ser/std/EnumMapSerializer.java | 6 +++--- .../databind/ser/std/EnumSerializer.java | 4 ++-- .../databind/ser/std/JsonValueSerializer.java | 4 ++-- .../databind/ser/std/MapSerializer.java | 2 +- .../databind/ser/std/NullSerializer.java | 2 +- .../databind/ser/std/NumberSerializers.java | 2 +- .../ser/std/ObjectArraySerializer.java | 2 +- .../databind/ser/std/RawSerializer.java | 2 +- .../ser/std/SerializableSerializer.java | 2 +- .../databind/ser/std/SqlDateSerializer.java | 2 +- .../databind/ser/std/SqlTimeSerializer.java | 2 +- .../ser/std/StaticListSerializerBase.java | 4 ++-- .../databind/ser/std/StdArraySerializers.java | 2 +- .../databind/ser/std/StdJdkSerializers.java | 2 +- .../databind/ser/std/StdKeySerializer.java | 2 +- .../databind/ser/std/StdScalarSerializer.java | 2 +- .../databind/ser/std/StdSerializer.java | 4 ++-- .../databind/ser/std/StringSerializer.java | 2 +- .../databind/ser/std/ToStringSerializer.java | 2 +- .../ser/std/TokenBufferSerializer.java | 2 +- .../jsonschema/TestGenerateJsonSchema.java | 1 + .../jsonschema/TestReadJsonSchema.java | 1 + .../databind/module/TestSimpleModule.java | 2 +- 64 files changed, 92 insertions(+), 96 deletions(-) create mode 100644 src/main/java/com/fasterxml/jackson/databind/jsonFormatVisitors/JsonAnyFormatVisitor.java rename src/main/java/com/fasterxml/jackson/databind/{jsonschema/visitors => jsonFormatVisitors}/JsonArrayFormatVisitor.java (82%) rename src/main/java/com/fasterxml/jackson/databind/{jsonschema/visitors => jsonFormatVisitors}/JsonBooleanFormatVisitor.java (56%) rename src/main/java/com/fasterxml/jackson/databind/{jsonschema => jsonFormatVisitors}/JsonFormatVisitorAware.java (77%) rename src/main/java/com/fasterxml/jackson/databind/{jsonschema/visitors => jsonFormatVisitors}/JsonFormatVisitorWithSerializerProvider.java (81%) rename src/main/java/com/fasterxml/jackson/databind/{jsonschema/visitors => jsonFormatVisitors}/JsonFormatVisitorWrapper.java (92%) rename src/main/java/com/fasterxml/jackson/databind/{jsonschema/visitors => jsonFormatVisitors}/JsonIntegerFormatVisitor.java (56%) create mode 100644 src/main/java/com/fasterxml/jackson/databind/jsonFormatVisitors/JsonNullFormatVisitor.java rename src/main/java/com/fasterxml/jackson/databind/{jsonschema/visitors => jsonFormatVisitors}/JsonNumberFormatVisitor.java (56%) rename src/main/java/com/fasterxml/jackson/databind/{jsonschema/visitors => jsonFormatVisitors}/JsonObjectFormatVisitor.java (81%) rename src/main/java/com/fasterxml/jackson/databind/{jsonschema/visitors => jsonFormatVisitors}/JsonStringFormatVisitor.java (56%) rename src/main/java/com/fasterxml/jackson/databind/{jsonschema/visitors => jsonFormatVisitors}/JsonValueFormatVisitor.java (78%) rename src/main/java/com/fasterxml/jackson/databind/jsonschema/{ => factories}/SchemaFactoryProvider.java (74%) delete mode 100644 src/main/java/com/fasterxml/jackson/databind/jsonschema/package-info.java delete mode 100644 src/main/java/com/fasterxml/jackson/databind/jsonschema/visitors/JsonAnyFormatVisitor.java delete mode 100644 src/main/java/com/fasterxml/jackson/databind/jsonschema/visitors/JsonNullFormatVisitor.java diff --git a/pom.xml b/pom.xml index 47f047f892..55ee434ba1 100644 --- a/pom.xml +++ b/pom.xml @@ -225,6 +225,9 @@ com.fasterxml.jackson.databind.exc, com.fasterxml.jackson.databind.ext, com.fasterxml.jackson.databind.introspect, com.fasterxml.jackson.databind.jsonschema, +com.fasterxml.jackson.databind.jsonschema.factories, +com.fasterxml.jackson.databind.jsonschema.types, +com.fasterxml.jackson.databind.jsonschema.visitors, com.fasterxml.jackson.databind.jsontype, com.fasterxml.jackson.databind.jsontype.impl, com.fasterxml.jackson.databind.module, diff --git a/src/main/java/com/fasterxml/jackson/databind/ObjectMapper.java b/src/main/java/com/fasterxml/jackson/databind/ObjectMapper.java index 9f6e023e6e..d4064294ce 100644 --- a/src/main/java/com/fasterxml/jackson/databind/ObjectMapper.java +++ b/src/main/java/com/fasterxml/jackson/databind/ObjectMapper.java @@ -26,7 +26,7 @@ import com.fasterxml.jackson.databind.introspect.ClassIntrospector; import com.fasterxml.jackson.databind.introspect.JacksonAnnotationIntrospector; import com.fasterxml.jackson.databind.introspect.VisibilityChecker; -import com.fasterxml.jackson.databind.jsonschema.visitors.JsonFormatVisitorWrapper; +import com.fasterxml.jackson.databind.jsonFormatVisitors.JsonFormatVisitorWrapper; import com.fasterxml.jackson.databind.jsontype.*; import com.fasterxml.jackson.databind.jsontype.impl.StdSubtypeResolver; import com.fasterxml.jackson.databind.jsontype.impl.StdTypeResolverBuilder; diff --git a/src/main/java/com/fasterxml/jackson/databind/ext/CoreXMLSerializers.java b/src/main/java/com/fasterxml/jackson/databind/ext/CoreXMLSerializers.java index 63771c0dcd..04f881e2f1 100644 --- a/src/main/java/com/fasterxml/jackson/databind/ext/CoreXMLSerializers.java +++ b/src/main/java/com/fasterxml/jackson/databind/ext/CoreXMLSerializers.java @@ -16,7 +16,7 @@ import com.fasterxml.jackson.databind.JsonNode; import com.fasterxml.jackson.databind.JsonSerializer; import com.fasterxml.jackson.databind.SerializerProvider; -import com.fasterxml.jackson.databind.jsonschema.visitors.JsonFormatVisitorWrapper; +import com.fasterxml.jackson.databind.jsonFormatVisitors.JsonFormatVisitorWrapper; import com.fasterxml.jackson.databind.ser.std.CalendarSerializer; import com.fasterxml.jackson.databind.ser.std.StdSerializer; import com.fasterxml.jackson.databind.ser.std.ToStringSerializer; diff --git a/src/main/java/com/fasterxml/jackson/databind/ext/DOMSerializer.java b/src/main/java/com/fasterxml/jackson/databind/ext/DOMSerializer.java index 2f37faf1c3..7824b334ac 100644 --- a/src/main/java/com/fasterxml/jackson/databind/ext/DOMSerializer.java +++ b/src/main/java/com/fasterxml/jackson/databind/ext/DOMSerializer.java @@ -11,7 +11,7 @@ import com.fasterxml.jackson.databind.JavaType; import com.fasterxml.jackson.databind.SerializerProvider; -import com.fasterxml.jackson.databind.jsonschema.visitors.JsonFormatVisitorWrapper; +import com.fasterxml.jackson.databind.jsonFormatVisitors.JsonFormatVisitorWrapper; import com.fasterxml.jackson.databind.ser.std.StdSerializer; public class DOMSerializer diff --git a/src/main/java/com/fasterxml/jackson/databind/jsonFormatVisitors/JsonAnyFormatVisitor.java b/src/main/java/com/fasterxml/jackson/databind/jsonFormatVisitors/JsonAnyFormatVisitor.java new file mode 100644 index 0000000000..612b2d39cf --- /dev/null +++ b/src/main/java/com/fasterxml/jackson/databind/jsonFormatVisitors/JsonAnyFormatVisitor.java @@ -0,0 +1,5 @@ +package com.fasterxml.jackson.databind.jsonFormatVisitors; + +public interface JsonAnyFormatVisitor { + +} diff --git a/src/main/java/com/fasterxml/jackson/databind/jsonschema/visitors/JsonArrayFormatVisitor.java b/src/main/java/com/fasterxml/jackson/databind/jsonFormatVisitors/JsonArrayFormatVisitor.java similarity index 82% rename from src/main/java/com/fasterxml/jackson/databind/jsonschema/visitors/JsonArrayFormatVisitor.java rename to src/main/java/com/fasterxml/jackson/databind/jsonFormatVisitors/JsonArrayFormatVisitor.java index cb35982649..02e42268a4 100644 --- a/src/main/java/com/fasterxml/jackson/databind/jsonschema/visitors/JsonArrayFormatVisitor.java +++ b/src/main/java/com/fasterxml/jackson/databind/jsonFormatVisitors/JsonArrayFormatVisitor.java @@ -1,4 +1,4 @@ -package com.fasterxml.jackson.databind.jsonschema.visitors; +package com.fasterxml.jackson.databind.jsonFormatVisitors; import com.fasterxml.jackson.databind.JavaType; import com.fasterxml.jackson.databind.jsonschema.types.SchemaType; diff --git a/src/main/java/com/fasterxml/jackson/databind/jsonschema/visitors/JsonBooleanFormatVisitor.java b/src/main/java/com/fasterxml/jackson/databind/jsonFormatVisitors/JsonBooleanFormatVisitor.java similarity index 56% rename from src/main/java/com/fasterxml/jackson/databind/jsonschema/visitors/JsonBooleanFormatVisitor.java rename to src/main/java/com/fasterxml/jackson/databind/jsonFormatVisitors/JsonBooleanFormatVisitor.java index 1b200ed61a..5002eb13db 100644 --- a/src/main/java/com/fasterxml/jackson/databind/jsonschema/visitors/JsonBooleanFormatVisitor.java +++ b/src/main/java/com/fasterxml/jackson/databind/jsonFormatVisitors/JsonBooleanFormatVisitor.java @@ -1,4 +1,4 @@ -package com.fasterxml.jackson.databind.jsonschema.visitors; +package com.fasterxml.jackson.databind.jsonFormatVisitors; public interface JsonBooleanFormatVisitor extends JsonValueFormatVisitor { diff --git a/src/main/java/com/fasterxml/jackson/databind/jsonschema/JsonFormatVisitorAware.java b/src/main/java/com/fasterxml/jackson/databind/jsonFormatVisitors/JsonFormatVisitorAware.java similarity index 77% rename from src/main/java/com/fasterxml/jackson/databind/jsonschema/JsonFormatVisitorAware.java rename to src/main/java/com/fasterxml/jackson/databind/jsonFormatVisitors/JsonFormatVisitorAware.java index b18688a1f1..7397651842 100644 --- a/src/main/java/com/fasterxml/jackson/databind/jsonschema/JsonFormatVisitorAware.java +++ b/src/main/java/com/fasterxml/jackson/databind/jsonFormatVisitors/JsonFormatVisitorAware.java @@ -1,8 +1,7 @@ -package com.fasterxml.jackson.databind.jsonschema; +package com.fasterxml.jackson.databind.jsonFormatVisitors; import com.fasterxml.jackson.databind.JavaType; -import com.fasterxml.jackson.databind.jsonschema.visitors.JsonFormatVisitorWrapper; /** * Marker interface for schema-aware serializers. diff --git a/src/main/java/com/fasterxml/jackson/databind/jsonschema/visitors/JsonFormatVisitorWithSerializerProvider.java b/src/main/java/com/fasterxml/jackson/databind/jsonFormatVisitors/JsonFormatVisitorWithSerializerProvider.java similarity index 81% rename from src/main/java/com/fasterxml/jackson/databind/jsonschema/visitors/JsonFormatVisitorWithSerializerProvider.java rename to src/main/java/com/fasterxml/jackson/databind/jsonFormatVisitors/JsonFormatVisitorWithSerializerProvider.java index b29f3849b3..0e495e9182 100644 --- a/src/main/java/com/fasterxml/jackson/databind/jsonschema/visitors/JsonFormatVisitorWithSerializerProvider.java +++ b/src/main/java/com/fasterxml/jackson/databind/jsonFormatVisitors/JsonFormatVisitorWithSerializerProvider.java @@ -1,7 +1,7 @@ /** * */ -package com.fasterxml.jackson.databind.jsonschema.visitors; +package com.fasterxml.jackson.databind.jsonFormatVisitors; import com.fasterxml.jackson.databind.SerializerProvider; diff --git a/src/main/java/com/fasterxml/jackson/databind/jsonschema/visitors/JsonFormatVisitorWrapper.java b/src/main/java/com/fasterxml/jackson/databind/jsonFormatVisitors/JsonFormatVisitorWrapper.java similarity index 92% rename from src/main/java/com/fasterxml/jackson/databind/jsonschema/visitors/JsonFormatVisitorWrapper.java rename to src/main/java/com/fasterxml/jackson/databind/jsonFormatVisitors/JsonFormatVisitorWrapper.java index 3c43fa605f..4e37d1df59 100644 --- a/src/main/java/com/fasterxml/jackson/databind/jsonschema/visitors/JsonFormatVisitorWrapper.java +++ b/src/main/java/com/fasterxml/jackson/databind/jsonFormatVisitors/JsonFormatVisitorWrapper.java @@ -1,4 +1,4 @@ -package com.fasterxml.jackson.databind.jsonschema.visitors; +package com.fasterxml.jackson.databind.jsonFormatVisitors; import com.fasterxml.jackson.databind.JavaType; diff --git a/src/main/java/com/fasterxml/jackson/databind/jsonschema/visitors/JsonIntegerFormatVisitor.java b/src/main/java/com/fasterxml/jackson/databind/jsonFormatVisitors/JsonIntegerFormatVisitor.java similarity index 56% rename from src/main/java/com/fasterxml/jackson/databind/jsonschema/visitors/JsonIntegerFormatVisitor.java rename to src/main/java/com/fasterxml/jackson/databind/jsonFormatVisitors/JsonIntegerFormatVisitor.java index 8bc066a2bc..cc5781e830 100644 --- a/src/main/java/com/fasterxml/jackson/databind/jsonschema/visitors/JsonIntegerFormatVisitor.java +++ b/src/main/java/com/fasterxml/jackson/databind/jsonFormatVisitors/JsonIntegerFormatVisitor.java @@ -1,4 +1,4 @@ -package com.fasterxml.jackson.databind.jsonschema.visitors; +package com.fasterxml.jackson.databind.jsonFormatVisitors; public interface JsonIntegerFormatVisitor extends JsonValueFormatVisitor { diff --git a/src/main/java/com/fasterxml/jackson/databind/jsonFormatVisitors/JsonNullFormatVisitor.java b/src/main/java/com/fasterxml/jackson/databind/jsonFormatVisitors/JsonNullFormatVisitor.java new file mode 100644 index 0000000000..8df98d811f --- /dev/null +++ b/src/main/java/com/fasterxml/jackson/databind/jsonFormatVisitors/JsonNullFormatVisitor.java @@ -0,0 +1,5 @@ +package com.fasterxml.jackson.databind.jsonFormatVisitors; + +public interface JsonNullFormatVisitor { + +} diff --git a/src/main/java/com/fasterxml/jackson/databind/jsonschema/visitors/JsonNumberFormatVisitor.java b/src/main/java/com/fasterxml/jackson/databind/jsonFormatVisitors/JsonNumberFormatVisitor.java similarity index 56% rename from src/main/java/com/fasterxml/jackson/databind/jsonschema/visitors/JsonNumberFormatVisitor.java rename to src/main/java/com/fasterxml/jackson/databind/jsonFormatVisitors/JsonNumberFormatVisitor.java index a06e19f6de..77f25c898e 100644 --- a/src/main/java/com/fasterxml/jackson/databind/jsonschema/visitors/JsonNumberFormatVisitor.java +++ b/src/main/java/com/fasterxml/jackson/databind/jsonFormatVisitors/JsonNumberFormatVisitor.java @@ -1,4 +1,4 @@ -package com.fasterxml.jackson.databind.jsonschema.visitors; +package com.fasterxml.jackson.databind.jsonFormatVisitors; public interface JsonNumberFormatVisitor extends JsonValueFormatVisitor{ diff --git a/src/main/java/com/fasterxml/jackson/databind/jsonschema/visitors/JsonObjectFormatVisitor.java b/src/main/java/com/fasterxml/jackson/databind/jsonFormatVisitors/JsonObjectFormatVisitor.java similarity index 81% rename from src/main/java/com/fasterxml/jackson/databind/jsonschema/visitors/JsonObjectFormatVisitor.java rename to src/main/java/com/fasterxml/jackson/databind/jsonFormatVisitors/JsonObjectFormatVisitor.java index 570af4cb15..54b295f0a6 100644 --- a/src/main/java/com/fasterxml/jackson/databind/jsonschema/visitors/JsonObjectFormatVisitor.java +++ b/src/main/java/com/fasterxml/jackson/databind/jsonFormatVisitors/JsonObjectFormatVisitor.java @@ -1,8 +1,7 @@ -package com.fasterxml.jackson.databind.jsonschema.visitors; +package com.fasterxml.jackson.databind.jsonFormatVisitors; import com.fasterxml.jackson.databind.JavaType; -import com.fasterxml.jackson.databind.jsonschema.JsonFormatVisitorAware; import com.fasterxml.jackson.databind.ser.BeanPropertyWriter; public interface JsonObjectFormatVisitor extends JsonFormatVisitorWithSerializerProvider { diff --git a/src/main/java/com/fasterxml/jackson/databind/jsonschema/visitors/JsonStringFormatVisitor.java b/src/main/java/com/fasterxml/jackson/databind/jsonFormatVisitors/JsonStringFormatVisitor.java similarity index 56% rename from src/main/java/com/fasterxml/jackson/databind/jsonschema/visitors/JsonStringFormatVisitor.java rename to src/main/java/com/fasterxml/jackson/databind/jsonFormatVisitors/JsonStringFormatVisitor.java index e2d6ae85ce..3fea32d52b 100644 --- a/src/main/java/com/fasterxml/jackson/databind/jsonschema/visitors/JsonStringFormatVisitor.java +++ b/src/main/java/com/fasterxml/jackson/databind/jsonFormatVisitors/JsonStringFormatVisitor.java @@ -1,4 +1,4 @@ -package com.fasterxml.jackson.databind.jsonschema.visitors; +package com.fasterxml.jackson.databind.jsonFormatVisitors; public interface JsonStringFormatVisitor extends JsonValueFormatVisitor { diff --git a/src/main/java/com/fasterxml/jackson/databind/jsonschema/visitors/JsonValueFormatVisitor.java b/src/main/java/com/fasterxml/jackson/databind/jsonFormatVisitors/JsonValueFormatVisitor.java similarity index 78% rename from src/main/java/com/fasterxml/jackson/databind/jsonschema/visitors/JsonValueFormatVisitor.java rename to src/main/java/com/fasterxml/jackson/databind/jsonFormatVisitors/JsonValueFormatVisitor.java index 0f7558699d..069f613507 100644 --- a/src/main/java/com/fasterxml/jackson/databind/jsonschema/visitors/JsonValueFormatVisitor.java +++ b/src/main/java/com/fasterxml/jackson/databind/jsonFormatVisitors/JsonValueFormatVisitor.java @@ -1,4 +1,4 @@ -package com.fasterxml.jackson.databind.jsonschema.visitors; +package com.fasterxml.jackson.databind.jsonFormatVisitors; import java.util.Set; diff --git a/src/main/java/com/fasterxml/jackson/databind/jsonschema/factories/AnySchemaFactory.java b/src/main/java/com/fasterxml/jackson/databind/jsonschema/factories/AnySchemaFactory.java index a0fd061de8..36143fa453 100644 --- a/src/main/java/com/fasterxml/jackson/databind/jsonschema/factories/AnySchemaFactory.java +++ b/src/main/java/com/fasterxml/jackson/databind/jsonschema/factories/AnySchemaFactory.java @@ -1,9 +1,9 @@ package com.fasterxml.jackson.databind.jsonschema.factories; import com.fasterxml.jackson.databind.SerializerProvider; +import com.fasterxml.jackson.databind.jsonFormatVisitors.JsonAnyFormatVisitor; import com.fasterxml.jackson.databind.jsonschema.types.AnySchema; import com.fasterxml.jackson.databind.jsonschema.types.JsonSchema; -import com.fasterxml.jackson.databind.jsonschema.visitors.JsonAnyFormatVisitor; public class AnySchemaFactory extends SchemaFactory implements JsonAnyFormatVisitor { diff --git a/src/main/java/com/fasterxml/jackson/databind/jsonschema/factories/ArraySchemaFactory.java b/src/main/java/com/fasterxml/jackson/databind/jsonschema/factories/ArraySchemaFactory.java index 527840e95c..8303d1e144 100644 --- a/src/main/java/com/fasterxml/jackson/databind/jsonschema/factories/ArraySchemaFactory.java +++ b/src/main/java/com/fasterxml/jackson/databind/jsonschema/factories/ArraySchemaFactory.java @@ -5,12 +5,11 @@ import com.fasterxml.jackson.databind.JsonMappingException; import com.fasterxml.jackson.databind.JsonSerializer; import com.fasterxml.jackson.databind.SerializerProvider; -import com.fasterxml.jackson.databind.jsonschema.JsonFormatVisitorAware; -import com.fasterxml.jackson.databind.jsonschema.SchemaFactoryProvider; +import com.fasterxml.jackson.databind.jsonFormatVisitors.JsonArrayFormatVisitor; +import com.fasterxml.jackson.databind.jsonFormatVisitors.JsonFormatVisitorAware; import com.fasterxml.jackson.databind.jsonschema.types.ArraySchema; import com.fasterxml.jackson.databind.jsonschema.types.JsonSchema; import com.fasterxml.jackson.databind.jsonschema.types.SchemaType; -import com.fasterxml.jackson.databind.jsonschema.visitors.JsonArrayFormatVisitor; public class ArraySchemaFactory extends SchemaFactory implements JsonArrayFormatVisitor { diff --git a/src/main/java/com/fasterxml/jackson/databind/jsonschema/factories/BooleanSchemaFactory.java b/src/main/java/com/fasterxml/jackson/databind/jsonschema/factories/BooleanSchemaFactory.java index f793c414dd..b084a3699d 100644 --- a/src/main/java/com/fasterxml/jackson/databind/jsonschema/factories/BooleanSchemaFactory.java +++ b/src/main/java/com/fasterxml/jackson/databind/jsonschema/factories/BooleanSchemaFactory.java @@ -1,9 +1,9 @@ package com.fasterxml.jackson.databind.jsonschema.factories; import com.fasterxml.jackson.databind.SerializerProvider; +import com.fasterxml.jackson.databind.jsonFormatVisitors.JsonBooleanFormatVisitor; import com.fasterxml.jackson.databind.jsonschema.types.BooleanSchema; import com.fasterxml.jackson.databind.jsonschema.types.ValueTypeSchema; -import com.fasterxml.jackson.databind.jsonschema.visitors.JsonBooleanFormatVisitor; public class BooleanSchemaFactory extends ValueTypeSchemaFactory implements JsonBooleanFormatVisitor { diff --git a/src/main/java/com/fasterxml/jackson/databind/jsonschema/factories/IntegerSchemaFactory.java b/src/main/java/com/fasterxml/jackson/databind/jsonschema/factories/IntegerSchemaFactory.java index 483755bef7..93d308b3d1 100644 --- a/src/main/java/com/fasterxml/jackson/databind/jsonschema/factories/IntegerSchemaFactory.java +++ b/src/main/java/com/fasterxml/jackson/databind/jsonschema/factories/IntegerSchemaFactory.java @@ -1,9 +1,9 @@ package com.fasterxml.jackson.databind.jsonschema.factories; import com.fasterxml.jackson.databind.SerializerProvider; +import com.fasterxml.jackson.databind.jsonFormatVisitors.JsonIntegerFormatVisitor; import com.fasterxml.jackson.databind.jsonschema.types.IntegerSchema; import com.fasterxml.jackson.databind.jsonschema.types.ValueTypeSchema; -import com.fasterxml.jackson.databind.jsonschema.visitors.JsonIntegerFormatVisitor; public class IntegerSchemaFactory extends ValueTypeSchemaFactory implements JsonIntegerFormatVisitor { diff --git a/src/main/java/com/fasterxml/jackson/databind/jsonschema/factories/NullSchemaFactory.java b/src/main/java/com/fasterxml/jackson/databind/jsonschema/factories/NullSchemaFactory.java index b27738f587..8963fd11d4 100644 --- a/src/main/java/com/fasterxml/jackson/databind/jsonschema/factories/NullSchemaFactory.java +++ b/src/main/java/com/fasterxml/jackson/databind/jsonschema/factories/NullSchemaFactory.java @@ -1,9 +1,9 @@ package com.fasterxml.jackson.databind.jsonschema.factories; import com.fasterxml.jackson.databind.SerializerProvider; +import com.fasterxml.jackson.databind.jsonFormatVisitors.JsonNullFormatVisitor; import com.fasterxml.jackson.databind.jsonschema.types.JsonSchema; import com.fasterxml.jackson.databind.jsonschema.types.NullSchema; -import com.fasterxml.jackson.databind.jsonschema.visitors.JsonNullFormatVisitor; public class NullSchemaFactory extends SchemaFactory implements JsonNullFormatVisitor { diff --git a/src/main/java/com/fasterxml/jackson/databind/jsonschema/factories/NumberSchemaFactory.java b/src/main/java/com/fasterxml/jackson/databind/jsonschema/factories/NumberSchemaFactory.java index e0d6e74f55..a0cabeb5eb 100644 --- a/src/main/java/com/fasterxml/jackson/databind/jsonschema/factories/NumberSchemaFactory.java +++ b/src/main/java/com/fasterxml/jackson/databind/jsonschema/factories/NumberSchemaFactory.java @@ -1,9 +1,9 @@ package com.fasterxml.jackson.databind.jsonschema.factories; import com.fasterxml.jackson.databind.SerializerProvider; +import com.fasterxml.jackson.databind.jsonFormatVisitors.JsonNumberFormatVisitor; import com.fasterxml.jackson.databind.jsonschema.types.NumberSchema; import com.fasterxml.jackson.databind.jsonschema.types.ValueTypeSchema; -import com.fasterxml.jackson.databind.jsonschema.visitors.JsonNumberFormatVisitor; public class NumberSchemaFactory extends ValueTypeSchemaFactory implements JsonNumberFormatVisitor { diff --git a/src/main/java/com/fasterxml/jackson/databind/jsonschema/factories/ObjectSchemaFactory.java b/src/main/java/com/fasterxml/jackson/databind/jsonschema/factories/ObjectSchemaFactory.java index 540e6095ae..0ada476b38 100644 --- a/src/main/java/com/fasterxml/jackson/databind/jsonschema/factories/ObjectSchemaFactory.java +++ b/src/main/java/com/fasterxml/jackson/databind/jsonschema/factories/ObjectSchemaFactory.java @@ -5,12 +5,11 @@ import com.fasterxml.jackson.databind.JsonMappingException; import com.fasterxml.jackson.databind.JsonSerializer; import com.fasterxml.jackson.databind.SerializerProvider; -import com.fasterxml.jackson.databind.jsonschema.JsonFormatVisitorAware; -import com.fasterxml.jackson.databind.jsonschema.SchemaFactoryProvider; +import com.fasterxml.jackson.databind.jsonFormatVisitors.JsonFormatVisitorAware; +import com.fasterxml.jackson.databind.jsonFormatVisitors.JsonObjectFormatVisitor; import com.fasterxml.jackson.databind.jsonschema.types.JsonSchema; import com.fasterxml.jackson.databind.jsonschema.types.ObjectSchema; import com.fasterxml.jackson.databind.jsonschema.types.SchemaType; -import com.fasterxml.jackson.databind.jsonschema.visitors.JsonObjectFormatVisitor; import com.fasterxml.jackson.databind.ser.BeanPropertyWriter; public class ObjectSchemaFactory extends SchemaFactory diff --git a/src/main/java/com/fasterxml/jackson/databind/jsonschema/SchemaFactoryProvider.java b/src/main/java/com/fasterxml/jackson/databind/jsonschema/factories/SchemaFactoryProvider.java similarity index 74% rename from src/main/java/com/fasterxml/jackson/databind/jsonschema/SchemaFactoryProvider.java rename to src/main/java/com/fasterxml/jackson/databind/jsonschema/factories/SchemaFactoryProvider.java index eeaee53142..d1b5e184e4 100644 --- a/src/main/java/com/fasterxml/jackson/databind/jsonschema/SchemaFactoryProvider.java +++ b/src/main/java/com/fasterxml/jackson/databind/jsonschema/factories/SchemaFactoryProvider.java @@ -1,18 +1,18 @@ -package com.fasterxml.jackson.databind.jsonschema; +package com.fasterxml.jackson.databind.jsonschema.factories; import com.fasterxml.jackson.databind.JavaType; import com.fasterxml.jackson.databind.SerializerProvider; +import com.fasterxml.jackson.databind.jsonFormatVisitors.JsonAnyFormatVisitor; +import com.fasterxml.jackson.databind.jsonFormatVisitors.JsonArrayFormatVisitor; +import com.fasterxml.jackson.databind.jsonFormatVisitors.JsonBooleanFormatVisitor; +import com.fasterxml.jackson.databind.jsonFormatVisitors.JsonFormatVisitorWrapper; +import com.fasterxml.jackson.databind.jsonFormatVisitors.JsonIntegerFormatVisitor; +import com.fasterxml.jackson.databind.jsonFormatVisitors.JsonNullFormatVisitor; +import com.fasterxml.jackson.databind.jsonFormatVisitors.JsonNumberFormatVisitor; +import com.fasterxml.jackson.databind.jsonFormatVisitors.JsonObjectFormatVisitor; +import com.fasterxml.jackson.databind.jsonFormatVisitors.JsonStringFormatVisitor; import com.fasterxml.jackson.databind.jsonschema.factories.*; import com.fasterxml.jackson.databind.jsonschema.types.JsonSchema; -import com.fasterxml.jackson.databind.jsonschema.visitors.JsonAnyFormatVisitor; -import com.fasterxml.jackson.databind.jsonschema.visitors.JsonArrayFormatVisitor; -import com.fasterxml.jackson.databind.jsonschema.visitors.JsonBooleanFormatVisitor; -import com.fasterxml.jackson.databind.jsonschema.visitors.JsonFormatVisitorWrapper; -import com.fasterxml.jackson.databind.jsonschema.visitors.JsonIntegerFormatVisitor; -import com.fasterxml.jackson.databind.jsonschema.visitors.JsonNullFormatVisitor; -import com.fasterxml.jackson.databind.jsonschema.visitors.JsonNumberFormatVisitor; -import com.fasterxml.jackson.databind.jsonschema.visitors.JsonObjectFormatVisitor; -import com.fasterxml.jackson.databind.jsonschema.visitors.JsonStringFormatVisitor; /** * @author jphelan diff --git a/src/main/java/com/fasterxml/jackson/databind/jsonschema/factories/StringSchemaFactory.java b/src/main/java/com/fasterxml/jackson/databind/jsonschema/factories/StringSchemaFactory.java index 3b4497b53a..c1bca67e60 100644 --- a/src/main/java/com/fasterxml/jackson/databind/jsonschema/factories/StringSchemaFactory.java +++ b/src/main/java/com/fasterxml/jackson/databind/jsonschema/factories/StringSchemaFactory.java @@ -1,9 +1,9 @@ package com.fasterxml.jackson.databind.jsonschema.factories; import com.fasterxml.jackson.databind.SerializerProvider; +import com.fasterxml.jackson.databind.jsonFormatVisitors.JsonStringFormatVisitor; import com.fasterxml.jackson.databind.jsonschema.types.StringSchema; import com.fasterxml.jackson.databind.jsonschema.types.ValueTypeSchema; -import com.fasterxml.jackson.databind.jsonschema.visitors.JsonStringFormatVisitor; public class StringSchemaFactory extends ValueTypeSchemaFactory implements JsonStringFormatVisitor{ diff --git a/src/main/java/com/fasterxml/jackson/databind/jsonschema/factories/ValueTypeSchemaFactory.java b/src/main/java/com/fasterxml/jackson/databind/jsonschema/factories/ValueTypeSchemaFactory.java index 51516fb539..9a052704d1 100644 --- a/src/main/java/com/fasterxml/jackson/databind/jsonschema/factories/ValueTypeSchemaFactory.java +++ b/src/main/java/com/fasterxml/jackson/databind/jsonschema/factories/ValueTypeSchemaFactory.java @@ -3,10 +3,10 @@ import java.util.Set; import com.fasterxml.jackson.databind.SerializerProvider; +import com.fasterxml.jackson.databind.jsonFormatVisitors.JsonValueFormatVisitor; import com.fasterxml.jackson.databind.jsonschema.types.JsonSchema; import com.fasterxml.jackson.databind.jsonschema.types.JsonValueFormat; import com.fasterxml.jackson.databind.jsonschema.types.ValueTypeSchema; -import com.fasterxml.jackson.databind.jsonschema.visitors.JsonValueFormatVisitor; public abstract class ValueTypeSchemaFactory extends SchemaFactory implements JsonValueFormatVisitor { diff --git a/src/main/java/com/fasterxml/jackson/databind/jsonschema/package-info.java b/src/main/java/com/fasterxml/jackson/databind/jsonschema/package-info.java deleted file mode 100644 index 443dcf48f9..0000000000 --- a/src/main/java/com/fasterxml/jackson/databind/jsonschema/package-info.java +++ /dev/null @@ -1,5 +0,0 @@ -/** - * Classes needed for JSON schema support (currently just ability - * to generate schemas using serialization part of data mapping) - */ -package com.fasterxml.jackson.databind.jsonschema; diff --git a/src/main/java/com/fasterxml/jackson/databind/jsonschema/visitors/JsonAnyFormatVisitor.java b/src/main/java/com/fasterxml/jackson/databind/jsonschema/visitors/JsonAnyFormatVisitor.java deleted file mode 100644 index 1a1b7a2abf..0000000000 --- a/src/main/java/com/fasterxml/jackson/databind/jsonschema/visitors/JsonAnyFormatVisitor.java +++ /dev/null @@ -1,5 +0,0 @@ -package com.fasterxml.jackson.databind.jsonschema.visitors; - -public interface JsonAnyFormatVisitor { - -} diff --git a/src/main/java/com/fasterxml/jackson/databind/jsonschema/visitors/JsonNullFormatVisitor.java b/src/main/java/com/fasterxml/jackson/databind/jsonschema/visitors/JsonNullFormatVisitor.java deleted file mode 100644 index e220f775f2..0000000000 --- a/src/main/java/com/fasterxml/jackson/databind/jsonschema/visitors/JsonNullFormatVisitor.java +++ /dev/null @@ -1,5 +0,0 @@ -package com.fasterxml.jackson.databind.jsonschema.visitors; - -public interface JsonNullFormatVisitor { - -} diff --git a/src/main/java/com/fasterxml/jackson/databind/ser/BeanPropertyFilter.java b/src/main/java/com/fasterxml/jackson/databind/ser/BeanPropertyFilter.java index babae23128..938aaa1c25 100644 --- a/src/main/java/com/fasterxml/jackson/databind/ser/BeanPropertyFilter.java +++ b/src/main/java/com/fasterxml/jackson/databind/ser/BeanPropertyFilter.java @@ -2,7 +2,7 @@ import com.fasterxml.jackson.core.JsonGenerator; import com.fasterxml.jackson.databind.SerializerProvider; -import com.fasterxml.jackson.databind.jsonschema.visitors.JsonObjectFormatVisitor; +import com.fasterxml.jackson.databind.jsonFormatVisitors.JsonObjectFormatVisitor; import com.fasterxml.jackson.databind.node.ObjectNode; /** diff --git a/src/main/java/com/fasterxml/jackson/databind/ser/DefaultSerializerProvider.java b/src/main/java/com/fasterxml/jackson/databind/ser/DefaultSerializerProvider.java index d0ebade5ee..81af6124ac 100644 --- a/src/main/java/com/fasterxml/jackson/databind/ser/DefaultSerializerProvider.java +++ b/src/main/java/com/fasterxml/jackson/databind/ser/DefaultSerializerProvider.java @@ -13,8 +13,8 @@ import com.fasterxml.jackson.databind.cfg.HandlerInstantiator; import com.fasterxml.jackson.databind.introspect.Annotated; import com.fasterxml.jackson.databind.introspect.ObjectIdInfo; -import com.fasterxml.jackson.databind.jsonschema.JsonFormatVisitorAware; -import com.fasterxml.jackson.databind.jsonschema.visitors.JsonFormatVisitorWrapper; +import com.fasterxml.jackson.databind.jsonFormatVisitors.JsonFormatVisitorAware; +import com.fasterxml.jackson.databind.jsonFormatVisitors.JsonFormatVisitorWrapper; import com.fasterxml.jackson.databind.ser.impl.WritableObjectId; import com.fasterxml.jackson.databind.util.ClassUtil; diff --git a/src/main/java/com/fasterxml/jackson/databind/ser/impl/FailingSerializer.java b/src/main/java/com/fasterxml/jackson/databind/ser/impl/FailingSerializer.java index 18d983b819..1ce8bd889f 100644 --- a/src/main/java/com/fasterxml/jackson/databind/ser/impl/FailingSerializer.java +++ b/src/main/java/com/fasterxml/jackson/databind/ser/impl/FailingSerializer.java @@ -6,7 +6,7 @@ import com.fasterxml.jackson.databind.JavaType; import com.fasterxml.jackson.databind.SerializerProvider; -import com.fasterxml.jackson.databind.jsonschema.visitors.JsonFormatVisitorWrapper; +import com.fasterxml.jackson.databind.jsonFormatVisitors.JsonFormatVisitorWrapper; import com.fasterxml.jackson.databind.ser.std.StdSerializer; /** diff --git a/src/main/java/com/fasterxml/jackson/databind/ser/impl/IndexedStringListSerializer.java b/src/main/java/com/fasterxml/jackson/databind/ser/impl/IndexedStringListSerializer.java index 09293cdf07..6311e0278f 100644 --- a/src/main/java/com/fasterxml/jackson/databind/ser/impl/IndexedStringListSerializer.java +++ b/src/main/java/com/fasterxml/jackson/databind/ser/impl/IndexedStringListSerializer.java @@ -7,8 +7,8 @@ import com.fasterxml.jackson.databind.*; import com.fasterxml.jackson.databind.annotation.JacksonStdImpl; +import com.fasterxml.jackson.databind.jsonFormatVisitors.JsonArrayFormatVisitor; import com.fasterxml.jackson.databind.jsonschema.types.SchemaType; -import com.fasterxml.jackson.databind.jsonschema.visitors.JsonArrayFormatVisitor; import com.fasterxml.jackson.databind.jsontype.TypeSerializer; import com.fasterxml.jackson.databind.ser.ContextualSerializer; import com.fasterxml.jackson.databind.ser.std.StaticListSerializerBase; diff --git a/src/main/java/com/fasterxml/jackson/databind/ser/impl/SimpleBeanPropertyFilter.java b/src/main/java/com/fasterxml/jackson/databind/ser/impl/SimpleBeanPropertyFilter.java index d516e3214e..e6f9cd873f 100644 --- a/src/main/java/com/fasterxml/jackson/databind/ser/impl/SimpleBeanPropertyFilter.java +++ b/src/main/java/com/fasterxml/jackson/databind/ser/impl/SimpleBeanPropertyFilter.java @@ -5,7 +5,7 @@ import com.fasterxml.jackson.core.JsonGenerator; import com.fasterxml.jackson.databind.*; -import com.fasterxml.jackson.databind.jsonschema.visitors.JsonObjectFormatVisitor; +import com.fasterxml.jackson.databind.jsonFormatVisitors.JsonObjectFormatVisitor; import com.fasterxml.jackson.databind.ser.BeanPropertyFilter; import com.fasterxml.jackson.databind.ser.BeanPropertyWriter; import com.fasterxml.jackson.databind.ser.std.BeanSerializerBase; diff --git a/src/main/java/com/fasterxml/jackson/databind/ser/impl/StringArraySerializer.java b/src/main/java/com/fasterxml/jackson/databind/ser/impl/StringArraySerializer.java index aa46ac202c..aa559275e5 100644 --- a/src/main/java/com/fasterxml/jackson/databind/ser/impl/StringArraySerializer.java +++ b/src/main/java/com/fasterxml/jackson/databind/ser/impl/StringArraySerializer.java @@ -7,8 +7,8 @@ import com.fasterxml.jackson.databind.*; import com.fasterxml.jackson.databind.annotation.JacksonStdImpl; +import com.fasterxml.jackson.databind.jsonFormatVisitors.JsonFormatVisitorWrapper; import com.fasterxml.jackson.databind.jsonschema.types.SchemaType; -import com.fasterxml.jackson.databind.jsonschema.visitors.JsonFormatVisitorWrapper; import com.fasterxml.jackson.databind.jsontype.TypeSerializer; import com.fasterxml.jackson.databind.node.ObjectNode; import com.fasterxml.jackson.databind.ser.ContainerSerializer; diff --git a/src/main/java/com/fasterxml/jackson/databind/ser/impl/StringCollectionSerializer.java b/src/main/java/com/fasterxml/jackson/databind/ser/impl/StringCollectionSerializer.java index b99f41e269..3fbf7d4395 100644 --- a/src/main/java/com/fasterxml/jackson/databind/ser/impl/StringCollectionSerializer.java +++ b/src/main/java/com/fasterxml/jackson/databind/ser/impl/StringCollectionSerializer.java @@ -7,8 +7,8 @@ import com.fasterxml.jackson.databind.*; import com.fasterxml.jackson.databind.annotation.JacksonStdImpl; +import com.fasterxml.jackson.databind.jsonFormatVisitors.JsonArrayFormatVisitor; import com.fasterxml.jackson.databind.jsonschema.types.SchemaType; -import com.fasterxml.jackson.databind.jsonschema.visitors.JsonArrayFormatVisitor; import com.fasterxml.jackson.databind.jsontype.TypeSerializer; import com.fasterxml.jackson.databind.ser.ContextualSerializer; import com.fasterxml.jackson.databind.ser.std.StaticListSerializerBase; diff --git a/src/main/java/com/fasterxml/jackson/databind/ser/impl/UnknownSerializer.java b/src/main/java/com/fasterxml/jackson/databind/ser/impl/UnknownSerializer.java index 12947ca66c..d434bc74e4 100644 --- a/src/main/java/com/fasterxml/jackson/databind/ser/impl/UnknownSerializer.java +++ b/src/main/java/com/fasterxml/jackson/databind/ser/impl/UnknownSerializer.java @@ -5,7 +5,7 @@ import com.fasterxml.jackson.core.*; import com.fasterxml.jackson.databind.*; -import com.fasterxml.jackson.databind.jsonschema.visitors.JsonFormatVisitorWrapper; +import com.fasterxml.jackson.databind.jsonFormatVisitors.JsonFormatVisitorWrapper; import com.fasterxml.jackson.databind.jsontype.TypeSerializer; import com.fasterxml.jackson.databind.ser.std.StdSerializer; diff --git a/src/main/java/com/fasterxml/jackson/databind/ser/std/AsArraySerializerBase.java b/src/main/java/com/fasterxml/jackson/databind/ser/std/AsArraySerializerBase.java index 658458461f..335dbe4f71 100644 --- a/src/main/java/com/fasterxml/jackson/databind/ser/std/AsArraySerializerBase.java +++ b/src/main/java/com/fasterxml/jackson/databind/ser/std/AsArraySerializerBase.java @@ -13,8 +13,8 @@ import com.fasterxml.jackson.databind.JsonSerializer; import com.fasterxml.jackson.databind.SerializationFeature; import com.fasterxml.jackson.databind.SerializerProvider; -import com.fasterxml.jackson.databind.jsonschema.visitors.JsonArrayFormatVisitor; -import com.fasterxml.jackson.databind.jsonschema.visitors.JsonFormatVisitorWrapper; +import com.fasterxml.jackson.databind.jsonFormatVisitors.JsonArrayFormatVisitor; +import com.fasterxml.jackson.databind.jsonFormatVisitors.JsonFormatVisitorWrapper; import com.fasterxml.jackson.databind.jsontype.TypeSerializer; import com.fasterxml.jackson.databind.ser.ContainerSerializer; import com.fasterxml.jackson.databind.ser.ContextualSerializer; diff --git a/src/main/java/com/fasterxml/jackson/databind/ser/std/BeanSerializerBase.java b/src/main/java/com/fasterxml/jackson/databind/ser/std/BeanSerializerBase.java index b1a9e45fe5..3620b08210 100644 --- a/src/main/java/com/fasterxml/jackson/databind/ser/std/BeanSerializerBase.java +++ b/src/main/java/com/fasterxml/jackson/databind/ser/std/BeanSerializerBase.java @@ -20,9 +20,9 @@ import com.fasterxml.jackson.databind.introspect.Annotated; import com.fasterxml.jackson.databind.introspect.AnnotatedMember; import com.fasterxml.jackson.databind.introspect.ObjectIdInfo; -import com.fasterxml.jackson.databind.jsonschema.JsonFormatVisitorAware; -import com.fasterxml.jackson.databind.jsonschema.visitors.JsonFormatVisitorWrapper; -import com.fasterxml.jackson.databind.jsonschema.visitors.JsonObjectFormatVisitor; +import com.fasterxml.jackson.databind.jsonFormatVisitors.JsonFormatVisitorAware; +import com.fasterxml.jackson.databind.jsonFormatVisitors.JsonFormatVisitorWrapper; +import com.fasterxml.jackson.databind.jsonFormatVisitors.JsonObjectFormatVisitor; import com.fasterxml.jackson.databind.jsontype.TypeSerializer; import com.fasterxml.jackson.databind.node.ObjectNode; import com.fasterxml.jackson.databind.ser.AnyGetterWriter; diff --git a/src/main/java/com/fasterxml/jackson/databind/ser/std/BooleanSerializer.java b/src/main/java/com/fasterxml/jackson/databind/ser/std/BooleanSerializer.java index 7e48e0461d..3d87cc4118 100644 --- a/src/main/java/com/fasterxml/jackson/databind/ser/std/BooleanSerializer.java +++ b/src/main/java/com/fasterxml/jackson/databind/ser/std/BooleanSerializer.java @@ -7,7 +7,7 @@ import com.fasterxml.jackson.databind.JavaType; import com.fasterxml.jackson.databind.SerializerProvider; import com.fasterxml.jackson.databind.annotation.JacksonStdImpl; -import com.fasterxml.jackson.databind.jsonschema.visitors.JsonFormatVisitorWrapper; +import com.fasterxml.jackson.databind.jsonFormatVisitors.JsonFormatVisitorWrapper; /** * Serializer used for primitive boolean, as well as java.util.Boolean diff --git a/src/main/java/com/fasterxml/jackson/databind/ser/std/DateTimeSerializerBase.java b/src/main/java/com/fasterxml/jackson/databind/ser/std/DateTimeSerializerBase.java index 66fb97fa2d..424cebed8a 100644 --- a/src/main/java/com/fasterxml/jackson/databind/ser/std/DateTimeSerializerBase.java +++ b/src/main/java/com/fasterxml/jackson/databind/ser/std/DateTimeSerializerBase.java @@ -16,8 +16,8 @@ import com.fasterxml.jackson.databind.SerializationFeature; import com.fasterxml.jackson.databind.SerializerProvider; import com.fasterxml.jackson.databind.introspect.Annotated; +import com.fasterxml.jackson.databind.jsonFormatVisitors.JsonFormatVisitorWrapper; import com.fasterxml.jackson.databind.jsonschema.types.JsonValueFormat; -import com.fasterxml.jackson.databind.jsonschema.visitors.JsonFormatVisitorWrapper; import com.fasterxml.jackson.databind.ser.ContextualSerializer; import com.fasterxml.jackson.databind.util.StdDateFormat; diff --git a/src/main/java/com/fasterxml/jackson/databind/ser/std/EnumMapSerializer.java b/src/main/java/com/fasterxml/jackson/databind/ser/std/EnumMapSerializer.java index 5b9b7f1884..92fdbb6913 100644 --- a/src/main/java/com/fasterxml/jackson/databind/ser/std/EnumMapSerializer.java +++ b/src/main/java/com/fasterxml/jackson/databind/ser/std/EnumMapSerializer.java @@ -14,9 +14,9 @@ import com.fasterxml.jackson.databind.JsonSerializer; import com.fasterxml.jackson.databind.SerializerProvider; import com.fasterxml.jackson.databind.annotation.JacksonStdImpl; -import com.fasterxml.jackson.databind.jsonschema.JsonFormatVisitorAware; -import com.fasterxml.jackson.databind.jsonschema.visitors.JsonFormatVisitorWrapper; -import com.fasterxml.jackson.databind.jsonschema.visitors.JsonObjectFormatVisitor; +import com.fasterxml.jackson.databind.jsonFormatVisitors.JsonFormatVisitorAware; +import com.fasterxml.jackson.databind.jsonFormatVisitors.JsonFormatVisitorWrapper; +import com.fasterxml.jackson.databind.jsonFormatVisitors.JsonObjectFormatVisitor; import com.fasterxml.jackson.databind.jsontype.TypeSerializer; import com.fasterxml.jackson.databind.node.JsonNodeFactory; import com.fasterxml.jackson.databind.node.ObjectNode; diff --git a/src/main/java/com/fasterxml/jackson/databind/ser/std/EnumSerializer.java b/src/main/java/com/fasterxml/jackson/databind/ser/std/EnumSerializer.java index 565f57857b..c824e76842 100644 --- a/src/main/java/com/fasterxml/jackson/databind/ser/std/EnumSerializer.java +++ b/src/main/java/com/fasterxml/jackson/databind/ser/std/EnumSerializer.java @@ -14,8 +14,8 @@ import com.fasterxml.jackson.databind.SerializationFeature; import com.fasterxml.jackson.databind.SerializerProvider; import com.fasterxml.jackson.databind.annotation.JacksonStdImpl; -import com.fasterxml.jackson.databind.jsonschema.visitors.JsonFormatVisitorWrapper; -import com.fasterxml.jackson.databind.jsonschema.visitors.JsonStringFormatVisitor; +import com.fasterxml.jackson.databind.jsonFormatVisitors.JsonFormatVisitorWrapper; +import com.fasterxml.jackson.databind.jsonFormatVisitors.JsonStringFormatVisitor; import com.fasterxml.jackson.databind.util.EnumValues; /** diff --git a/src/main/java/com/fasterxml/jackson/databind/ser/std/JsonValueSerializer.java b/src/main/java/com/fasterxml/jackson/databind/ser/std/JsonValueSerializer.java index 6715ecc887..4557b8543c 100644 --- a/src/main/java/com/fasterxml/jackson/databind/ser/std/JsonValueSerializer.java +++ b/src/main/java/com/fasterxml/jackson/databind/ser/std/JsonValueSerializer.java @@ -15,8 +15,8 @@ import com.fasterxml.jackson.databind.MapperFeature; import com.fasterxml.jackson.databind.SerializerProvider; import com.fasterxml.jackson.databind.annotation.JacksonStdImpl; -import com.fasterxml.jackson.databind.jsonschema.JsonFormatVisitorAware; -import com.fasterxml.jackson.databind.jsonschema.visitors.JsonFormatVisitorWrapper; +import com.fasterxml.jackson.databind.jsonFormatVisitors.JsonFormatVisitorAware; +import com.fasterxml.jackson.databind.jsonFormatVisitors.JsonFormatVisitorWrapper; import com.fasterxml.jackson.databind.jsontype.TypeSerializer; import com.fasterxml.jackson.databind.ser.BeanSerializer; import com.fasterxml.jackson.databind.ser.ContextualSerializer; diff --git a/src/main/java/com/fasterxml/jackson/databind/ser/std/MapSerializer.java b/src/main/java/com/fasterxml/jackson/databind/ser/std/MapSerializer.java index c33e4dce95..95e8cadf9b 100644 --- a/src/main/java/com/fasterxml/jackson/databind/ser/std/MapSerializer.java +++ b/src/main/java/com/fasterxml/jackson/databind/ser/std/MapSerializer.java @@ -16,7 +16,7 @@ import com.fasterxml.jackson.databind.SerializationFeature; import com.fasterxml.jackson.databind.SerializerProvider; import com.fasterxml.jackson.databind.annotation.JacksonStdImpl; -import com.fasterxml.jackson.databind.jsonschema.visitors.JsonFormatVisitorWrapper; +import com.fasterxml.jackson.databind.jsonFormatVisitors.JsonFormatVisitorWrapper; import com.fasterxml.jackson.databind.jsontype.TypeSerializer; import com.fasterxml.jackson.databind.ser.ContainerSerializer; import com.fasterxml.jackson.databind.ser.ContextualSerializer; diff --git a/src/main/java/com/fasterxml/jackson/databind/ser/std/NullSerializer.java b/src/main/java/com/fasterxml/jackson/databind/ser/std/NullSerializer.java index dcb4e8b482..ec127f4b5b 100644 --- a/src/main/java/com/fasterxml/jackson/databind/ser/std/NullSerializer.java +++ b/src/main/java/com/fasterxml/jackson/databind/ser/std/NullSerializer.java @@ -7,7 +7,7 @@ import com.fasterxml.jackson.databind.JavaType; import com.fasterxml.jackson.databind.SerializerProvider; import com.fasterxml.jackson.databind.annotation.JacksonStdImpl; -import com.fasterxml.jackson.databind.jsonschema.visitors.JsonFormatVisitorWrapper; +import com.fasterxml.jackson.databind.jsonFormatVisitors.JsonFormatVisitorWrapper; /** * This is a simple dummy serializer that will just output literal diff --git a/src/main/java/com/fasterxml/jackson/databind/ser/std/NumberSerializers.java b/src/main/java/com/fasterxml/jackson/databind/ser/std/NumberSerializers.java index 2d6eb9cade..d33e01a5c8 100644 --- a/src/main/java/com/fasterxml/jackson/databind/ser/std/NumberSerializers.java +++ b/src/main/java/com/fasterxml/jackson/databind/ser/std/NumberSerializers.java @@ -11,7 +11,7 @@ import com.fasterxml.jackson.databind.JsonSerializer; import com.fasterxml.jackson.databind.SerializerProvider; import com.fasterxml.jackson.databind.annotation.JacksonStdImpl; -import com.fasterxml.jackson.databind.jsonschema.visitors.JsonFormatVisitorWrapper; +import com.fasterxml.jackson.databind.jsonFormatVisitors.JsonFormatVisitorWrapper; /** * Container class for serializers used for handling standard JDK-provided types. diff --git a/src/main/java/com/fasterxml/jackson/databind/ser/std/ObjectArraySerializer.java b/src/main/java/com/fasterxml/jackson/databind/ser/std/ObjectArraySerializer.java index f0de918877..7733aede29 100644 --- a/src/main/java/com/fasterxml/jackson/databind/ser/std/ObjectArraySerializer.java +++ b/src/main/java/com/fasterxml/jackson/databind/ser/std/ObjectArraySerializer.java @@ -11,7 +11,7 @@ import com.fasterxml.jackson.databind.JsonSerializer; import com.fasterxml.jackson.databind.SerializerProvider; import com.fasterxml.jackson.databind.annotation.JacksonStdImpl; -import com.fasterxml.jackson.databind.jsonschema.visitors.JsonFormatVisitorWrapper; +import com.fasterxml.jackson.databind.jsonFormatVisitors.JsonFormatVisitorWrapper; import com.fasterxml.jackson.databind.jsontype.TypeSerializer; import com.fasterxml.jackson.databind.ser.ContainerSerializer; import com.fasterxml.jackson.databind.ser.ContextualSerializer; diff --git a/src/main/java/com/fasterxml/jackson/databind/ser/std/RawSerializer.java b/src/main/java/com/fasterxml/jackson/databind/ser/std/RawSerializer.java index ad98504079..99850927c1 100644 --- a/src/main/java/com/fasterxml/jackson/databind/ser/std/RawSerializer.java +++ b/src/main/java/com/fasterxml/jackson/databind/ser/std/RawSerializer.java @@ -8,7 +8,7 @@ import com.fasterxml.jackson.databind.JavaType; import com.fasterxml.jackson.databind.SerializerProvider; import com.fasterxml.jackson.databind.annotation.JacksonStdImpl; -import com.fasterxml.jackson.databind.jsonschema.visitors.JsonFormatVisitorWrapper; +import com.fasterxml.jackson.databind.jsonFormatVisitors.JsonFormatVisitorWrapper; import com.fasterxml.jackson.databind.jsontype.TypeSerializer; /** diff --git a/src/main/java/com/fasterxml/jackson/databind/ser/std/SerializableSerializer.java b/src/main/java/com/fasterxml/jackson/databind/ser/std/SerializableSerializer.java index 65adb3d0b9..98011dd66c 100644 --- a/src/main/java/com/fasterxml/jackson/databind/ser/std/SerializableSerializer.java +++ b/src/main/java/com/fasterxml/jackson/databind/ser/std/SerializableSerializer.java @@ -10,7 +10,7 @@ import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.databind.SerializerProvider; import com.fasterxml.jackson.databind.annotation.JacksonStdImpl; -import com.fasterxml.jackson.databind.jsonschema.visitors.JsonFormatVisitorWrapper; +import com.fasterxml.jackson.databind.jsonFormatVisitors.JsonFormatVisitorWrapper; import com.fasterxml.jackson.databind.jsontype.TypeSerializer; /** diff --git a/src/main/java/com/fasterxml/jackson/databind/ser/std/SqlDateSerializer.java b/src/main/java/com/fasterxml/jackson/databind/ser/std/SqlDateSerializer.java index d295c2c997..fdbd2a0759 100644 --- a/src/main/java/com/fasterxml/jackson/databind/ser/std/SqlDateSerializer.java +++ b/src/main/java/com/fasterxml/jackson/databind/ser/std/SqlDateSerializer.java @@ -7,8 +7,8 @@ import com.fasterxml.jackson.databind.JavaType; 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.jsonschema.types.JsonValueFormat; -import com.fasterxml.jackson.databind.jsonschema.visitors.JsonFormatVisitorWrapper; /** * Compared to regular {@link java.util.Date} serialization, we do use String diff --git a/src/main/java/com/fasterxml/jackson/databind/ser/std/SqlTimeSerializer.java b/src/main/java/com/fasterxml/jackson/databind/ser/std/SqlTimeSerializer.java index a4ae64bcc2..2800bcc679 100644 --- a/src/main/java/com/fasterxml/jackson/databind/ser/std/SqlTimeSerializer.java +++ b/src/main/java/com/fasterxml/jackson/databind/ser/std/SqlTimeSerializer.java @@ -7,8 +7,8 @@ import com.fasterxml.jackson.databind.JavaType; 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.jsonschema.types.JsonValueFormat; -import com.fasterxml.jackson.databind.jsonschema.visitors.JsonFormatVisitorWrapper; @JacksonStdImpl public class SqlTimeSerializer diff --git a/src/main/java/com/fasterxml/jackson/databind/ser/std/StaticListSerializerBase.java b/src/main/java/com/fasterxml/jackson/databind/ser/std/StaticListSerializerBase.java index 88aa71b302..1aff32344f 100644 --- a/src/main/java/com/fasterxml/jackson/databind/ser/std/StaticListSerializerBase.java +++ b/src/main/java/com/fasterxml/jackson/databind/ser/std/StaticListSerializerBase.java @@ -3,8 +3,8 @@ import java.util.Collection; import com.fasterxml.jackson.databind.JavaType; -import com.fasterxml.jackson.databind.jsonschema.visitors.JsonArrayFormatVisitor; -import com.fasterxml.jackson.databind.jsonschema.visitors.JsonFormatVisitorWrapper; +import com.fasterxml.jackson.databind.jsonFormatVisitors.JsonArrayFormatVisitor; +import com.fasterxml.jackson.databind.jsonFormatVisitors.JsonFormatVisitorWrapper; /** * Intermediate base class for Lists, Collections and Arrays diff --git a/src/main/java/com/fasterxml/jackson/databind/ser/std/StdArraySerializers.java b/src/main/java/com/fasterxml/jackson/databind/ser/std/StdArraySerializers.java index 28394c27b2..beac71ed3e 100644 --- a/src/main/java/com/fasterxml/jackson/databind/ser/std/StdArraySerializers.java +++ b/src/main/java/com/fasterxml/jackson/databind/ser/std/StdArraySerializers.java @@ -11,8 +11,8 @@ import com.fasterxml.jackson.databind.SerializationFeature; 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.jsonschema.types.SchemaType; -import com.fasterxml.jackson.databind.jsonschema.visitors.JsonFormatVisitorWrapper; import com.fasterxml.jackson.databind.jsontype.TypeSerializer; import com.fasterxml.jackson.databind.ser.ContainerSerializer; import com.fasterxml.jackson.databind.type.TypeFactory; diff --git a/src/main/java/com/fasterxml/jackson/databind/ser/std/StdJdkSerializers.java b/src/main/java/com/fasterxml/jackson/databind/ser/std/StdJdkSerializers.java index 9fb931f871..0270ae8c28 100644 --- a/src/main/java/com/fasterxml/jackson/databind/ser/std/StdJdkSerializers.java +++ b/src/main/java/com/fasterxml/jackson/databind/ser/std/StdJdkSerializers.java @@ -17,7 +17,7 @@ import com.fasterxml.jackson.core.JsonGenerator; import com.fasterxml.jackson.databind.JavaType; import com.fasterxml.jackson.databind.SerializerProvider; -import com.fasterxml.jackson.databind.jsonschema.visitors.JsonFormatVisitorWrapper; +import com.fasterxml.jackson.databind.jsonFormatVisitors.JsonFormatVisitorWrapper; import com.fasterxml.jackson.databind.ser.BasicSerializerFactory; import com.fasterxml.jackson.databind.util.Provider; diff --git a/src/main/java/com/fasterxml/jackson/databind/ser/std/StdKeySerializer.java b/src/main/java/com/fasterxml/jackson/databind/ser/std/StdKeySerializer.java index 319565f17f..1d64986d84 100644 --- a/src/main/java/com/fasterxml/jackson/databind/ser/std/StdKeySerializer.java +++ b/src/main/java/com/fasterxml/jackson/databind/ser/std/StdKeySerializer.java @@ -7,7 +7,7 @@ import com.fasterxml.jackson.core.JsonGenerator; import com.fasterxml.jackson.databind.JavaType; import com.fasterxml.jackson.databind.SerializerProvider; -import com.fasterxml.jackson.databind.jsonschema.visitors.JsonFormatVisitorWrapper; +import com.fasterxml.jackson.databind.jsonFormatVisitors.JsonFormatVisitorWrapper; /** * Specialized serializer that can be used as the generic key diff --git a/src/main/java/com/fasterxml/jackson/databind/ser/std/StdScalarSerializer.java b/src/main/java/com/fasterxml/jackson/databind/ser/std/StdScalarSerializer.java index 659c5ea958..1387e3d813 100644 --- a/src/main/java/com/fasterxml/jackson/databind/ser/std/StdScalarSerializer.java +++ b/src/main/java/com/fasterxml/jackson/databind/ser/std/StdScalarSerializer.java @@ -6,7 +6,7 @@ import com.fasterxml.jackson.core.JsonGenerator; import com.fasterxml.jackson.databind.JavaType; import com.fasterxml.jackson.databind.SerializerProvider; -import com.fasterxml.jackson.databind.jsonschema.visitors.JsonFormatVisitorWrapper; +import com.fasterxml.jackson.databind.jsonFormatVisitors.JsonFormatVisitorWrapper; import com.fasterxml.jackson.databind.jsontype.TypeSerializer; public abstract class StdScalarSerializer diff --git a/src/main/java/com/fasterxml/jackson/databind/ser/std/StdSerializer.java b/src/main/java/com/fasterxml/jackson/databind/ser/std/StdSerializer.java index 152db6767a..abd487dc21 100644 --- a/src/main/java/com/fasterxml/jackson/databind/ser/std/StdSerializer.java +++ b/src/main/java/com/fasterxml/jackson/databind/ser/std/StdSerializer.java @@ -11,8 +11,8 @@ import com.fasterxml.jackson.databind.SerializationFeature; import com.fasterxml.jackson.databind.SerializerProvider; import com.fasterxml.jackson.databind.annotation.JacksonStdImpl; -import com.fasterxml.jackson.databind.jsonschema.JsonFormatVisitorAware; -import com.fasterxml.jackson.databind.jsonschema.visitors.JsonFormatVisitorWrapper; +import com.fasterxml.jackson.databind.jsonFormatVisitors.JsonFormatVisitorAware; +import com.fasterxml.jackson.databind.jsonFormatVisitors.JsonFormatVisitorWrapper; /** * Base class used by all standard serializers, and can also diff --git a/src/main/java/com/fasterxml/jackson/databind/ser/std/StringSerializer.java b/src/main/java/com/fasterxml/jackson/databind/ser/std/StringSerializer.java index 0dea68672f..ec2911e0be 100644 --- a/src/main/java/com/fasterxml/jackson/databind/ser/std/StringSerializer.java +++ b/src/main/java/com/fasterxml/jackson/databind/ser/std/StringSerializer.java @@ -7,7 +7,7 @@ import com.fasterxml.jackson.databind.JavaType; import com.fasterxml.jackson.databind.SerializerProvider; import com.fasterxml.jackson.databind.annotation.JacksonStdImpl; -import com.fasterxml.jackson.databind.jsonschema.visitors.JsonFormatVisitorWrapper; +import com.fasterxml.jackson.databind.jsonFormatVisitors.JsonFormatVisitorWrapper; /** * This is the special serializer for regular {@link java.lang.String}s. diff --git a/src/main/java/com/fasterxml/jackson/databind/ser/std/ToStringSerializer.java b/src/main/java/com/fasterxml/jackson/databind/ser/std/ToStringSerializer.java index 54f30d9ab4..1b5acabc65 100644 --- a/src/main/java/com/fasterxml/jackson/databind/ser/std/ToStringSerializer.java +++ b/src/main/java/com/fasterxml/jackson/databind/ser/std/ToStringSerializer.java @@ -7,7 +7,7 @@ import com.fasterxml.jackson.databind.JavaType; import com.fasterxml.jackson.databind.SerializerProvider; import com.fasterxml.jackson.databind.annotation.JacksonStdImpl; -import com.fasterxml.jackson.databind.jsonschema.visitors.JsonFormatVisitorWrapper; +import com.fasterxml.jackson.databind.jsonFormatVisitors.JsonFormatVisitorWrapper; import com.fasterxml.jackson.databind.jsontype.TypeSerializer; /** diff --git a/src/main/java/com/fasterxml/jackson/databind/ser/std/TokenBufferSerializer.java b/src/main/java/com/fasterxml/jackson/databind/ser/std/TokenBufferSerializer.java index 9d8032321a..07a8f2edfd 100644 --- a/src/main/java/com/fasterxml/jackson/databind/ser/std/TokenBufferSerializer.java +++ b/src/main/java/com/fasterxml/jackson/databind/ser/std/TokenBufferSerializer.java @@ -7,7 +7,7 @@ import com.fasterxml.jackson.databind.JavaType; import com.fasterxml.jackson.databind.SerializerProvider; import com.fasterxml.jackson.databind.annotation.JacksonStdImpl; -import com.fasterxml.jackson.databind.jsonschema.visitors.JsonFormatVisitorWrapper; +import com.fasterxml.jackson.databind.jsonFormatVisitors.JsonFormatVisitorWrapper; import com.fasterxml.jackson.databind.jsontype.TypeSerializer; import com.fasterxml.jackson.databind.util.TokenBuffer; diff --git a/src/test/java/com/fasterxml/jackson/databind/jsonschema/TestGenerateJsonSchema.java b/src/test/java/com/fasterxml/jackson/databind/jsonschema/TestGenerateJsonSchema.java index 0b255e4d33..1be3dc74fb 100644 --- a/src/test/java/com/fasterxml/jackson/databind/jsonschema/TestGenerateJsonSchema.java +++ b/src/test/java/com/fasterxml/jackson/databind/jsonschema/TestGenerateJsonSchema.java @@ -8,6 +8,7 @@ import com.fasterxml.jackson.annotation.JsonProperty; import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.databind.jsonschema.factories.SchemaFactory; +import com.fasterxml.jackson.databind.jsonschema.factories.SchemaFactoryProvider; import com.fasterxml.jackson.databind.jsonschema.types.ObjectSchema; import com.fasterxml.jackson.databind.jsonschema.types.JsonSchema; import com.fasterxml.jackson.databind.jsonschema.types.ArraySchema.Items; diff --git a/src/test/java/com/fasterxml/jackson/databind/jsonschema/TestReadJsonSchema.java b/src/test/java/com/fasterxml/jackson/databind/jsonschema/TestReadJsonSchema.java index 0e779a6027..e05e887912 100644 --- a/src/test/java/com/fasterxml/jackson/databind/jsonschema/TestReadJsonSchema.java +++ b/src/test/java/com/fasterxml/jackson/databind/jsonschema/TestReadJsonSchema.java @@ -4,6 +4,7 @@ import com.fasterxml.jackson.databind.*; import com.fasterxml.jackson.databind.jsonschema.factories.SchemaFactory; +import com.fasterxml.jackson.databind.jsonschema.factories.SchemaFactoryProvider; import com.fasterxml.jackson.databind.jsonschema.types.JsonSchema; /** diff --git a/src/test/java/com/fasterxml/jackson/databind/module/TestSimpleModule.java b/src/test/java/com/fasterxml/jackson/databind/module/TestSimpleModule.java index 3381a2d683..a92ccd5d71 100644 --- a/src/test/java/com/fasterxml/jackson/databind/module/TestSimpleModule.java +++ b/src/test/java/com/fasterxml/jackson/databind/module/TestSimpleModule.java @@ -7,7 +7,7 @@ import com.fasterxml.jackson.core.*; import com.fasterxml.jackson.annotation.JsonPropertyOrder; import com.fasterxml.jackson.databind.*; -import com.fasterxml.jackson.databind.jsonschema.visitors.JsonFormatVisitorWrapper; +import com.fasterxml.jackson.databind.jsonFormatVisitors.JsonFormatVisitorWrapper; import com.fasterxml.jackson.databind.module.SimpleDeserializers; import com.fasterxml.jackson.databind.module.SimpleModule; import com.fasterxml.jackson.databind.module.SimpleSerializers; From f46d555432ac94e3ff60567f87d24483f5471785 Mon Sep 17 00:00:00 2001 From: jackphel Date: Fri, 10 Aug 2012 13:00:43 -0400 Subject: [PATCH 19/19] Needed to change packages in pom to run maven install --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 55ee434ba1..ed111343cf 100644 --- a/pom.xml +++ b/pom.xml @@ -227,7 +227,7 @@ com.fasterxml.jackson.databind.introspect, com.fasterxml.jackson.databind.jsonschema, com.fasterxml.jackson.databind.jsonschema.factories, com.fasterxml.jackson.databind.jsonschema.types, -com.fasterxml.jackson.databind.jsonschema.visitors, +com.fasterxml.jackson.databind.jsonFormatVisitors, com.fasterxml.jackson.databind.jsontype, com.fasterxml.jackson.databind.jsontype.impl, com.fasterxml.jackson.databind.module,