1 package com.fasterxml.jackson.databind.jsonschema;
2 
3 import com.fasterxml.jackson.annotation.JsonCreator;
4 import com.fasterxml.jackson.annotation.JsonValue;
5 
6 import com.fasterxml.jackson.databind.JsonNode;
7 import com.fasterxml.jackson.databind.node.JsonNodeFactory;
8 import com.fasterxml.jackson.databind.node.ObjectNode;
9 
10 /**
11  * Container for a logical JSON Schema instance.
12  * Internally schema data is stored as a JSON Tree
13  * (instance of {@link JsonNode} is the root
14  * of schema document)
15  *
16  * @author Ryan Heaton
17  * @see <a href="http://json-schema.org/">JSON Schema</a>
18  *
19  * @deprecated Since 2.2, we recommend use of external
20  *   <a href="https://github.com/FasterXML/jackson-module-jsonSchema">JSON Schema generator module</a>
21  */
22 @Deprecated
23 public class JsonSchema
24 {
25     private final ObjectNode schema;
26 
27     /**
28      * Main constructor for schema instances.
29      *<p>
30      * This is the creator constructor used by Jackson itself when
31      * deserializing instances. It is so-called delegating creator,
32      * meaning that its argument will be bound by Jackson before
33      * constructor gets called.
34      */
35     @JsonCreator
JsonSchema(ObjectNode schema)36     public JsonSchema(ObjectNode schema)
37     {
38         this.schema = schema;
39     }
40 
41     /**
42      * Method for accessing root JSON object of the contained schema.
43      *<p>
44      * Note: this method is specified with {@link JsonValue} annotation
45      * to represent serialization to use; same as if explicitly
46      * serializing returned object.
47      *
48      * @return Root node of the schema tree
49      */
50     @JsonValue
getSchemaNode()51     public ObjectNode getSchemaNode()
52     {
53         return schema;
54     }
55 
56     @Override
toString()57     public String toString()
58     {
59         return this.schema.toString();
60     }
61 
62     @Override
hashCode()63     public int hashCode()
64     {
65         return schema.hashCode();
66     }
67 
68     @Override
equals(Object o)69     public boolean equals(Object o)
70     {
71         if (o == this) return true;
72         if (o == null) return false;
73         if (!(o instanceof JsonSchema)) return false;
74 
75         JsonSchema other = (JsonSchema) o;
76         if (schema == null) {
77             return other.schema == null;
78         }
79         return schema.equals(other.schema);
80     }
81 
82     /**
83      * Get the default schema node.
84      *
85      * @return The default schema node.
86      */
getDefaultSchemaNode()87     public static JsonNode getDefaultSchemaNode()
88     {
89         ObjectNode objectNode = JsonNodeFactory.instance.objectNode();
90         objectNode.put("type", "any");
91         // "required" is false by default, no need to include
92         //objectNode.put("required", false);
93         return objectNode;
94     }
95 
96 }
97