aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/com/fasterxml/jackson/databind/jsonschema/JsonSchema.java
blob: f442be42a32c73d512d8ef140d8be7e4da53f3fc (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
package com.fasterxml.jackson.databind.jsonschema;

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 <a href="http://json-schema.org/">JSON Schema</a>
 * 
 * @deprecated Since 2.2, we recommend use of external
 *   <a href="https://github.com/FasterXML/jackson-module-jsonSchema">JSON Schema generator module</a>
 */
@Deprecated
public class JsonSchema
{
    private final ObjectNode schema;

    /**
     * Main constructor for schema instances.
     *<p>
     * 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.
     *<p>
     * 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 int hashCode()
    {
        return schema.hashCode();
    }

    @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;
    }

}