11package com .fasterxml .jackson .module .jsonSchema .types ;
22
3- import com .fasterxml .jackson .annotation .JsonCreator ;
4- import com .fasterxml .jackson .annotation .JsonIgnore ;
5- import com .fasterxml .jackson .annotation .JsonProperty ;
6- import com .fasterxml .jackson .annotation .JsonValue ;
7- import com .fasterxml .jackson .core .JsonParser ;
8- import com .fasterxml .jackson .core .JsonProcessingException ;
9- import com .fasterxml .jackson .core .ObjectCodec ;
10- import com .fasterxml .jackson .databind .DeserializationContext ;
11- import com .fasterxml .jackson .databind .JsonDeserializer ;
12- import com .fasterxml .jackson .databind .JsonNode ;
3+ import java .io .IOException ;
4+ import java .util .Map ;
5+
6+ import com .fasterxml .jackson .annotation .*;
7+
8+ import com .fasterxml .jackson .core .*;
9+
10+ import com .fasterxml .jackson .databind .*;
1311import com .fasterxml .jackson .databind .annotation .JsonDeserialize ;
12+ import com .fasterxml .jackson .databind .deser .std .StdDeserializer ;
1413import com .fasterxml .jackson .databind .jsonFormatVisitors .JsonFormatTypes ;
15- import com .fasterxml .jackson .module .jsonSchema .JsonSchema ;
1614
17- import java .io .IOException ;
18- import java .util .Map ;
15+ import com .fasterxml .jackson .module .jsonSchema .JsonSchema ;
1916
2017/*
2118 * This attribute defines the allowed items in an instance array, and
@@ -29,22 +26,22 @@ public class ArraySchema extends ContainerTypeSchema
2926 */
3027 @ JsonProperty
3128 protected ArraySchema .AdditionalItems additionalItems ;
32-
29+
3330 /**
3431 * see {@link Items}
3532 */
3633 @ JsonProperty
3734 @ JsonDeserialize (using = ItemsDeserializer .class )
3835 protected ArraySchema .Items items ;
39-
36+
4037 /**This attribute defines the maximum number of values in an array*/
4138 @ JsonProperty
4239 protected Integer maxItems ;
43-
40+
4441 /**This attribute defines the minimum number of values in an array*/
4542 @ JsonProperty
4643 protected Integer minItems ;
47-
44+
4845 /**
4946 * This attribute indicates that all items in an array instance MUST be
5047 unique (contains no two identical values).
@@ -172,15 +169,9 @@ public ArrayItems(JsonSchema[] jsonSchemas) {
172169 this .jsonSchemas = jsonSchemas ;
173170 }
174171
175- /* (non-Javadoc)
176- * @see com.fasterxml.jackson.databind.jsonSchema.types.ArraySchema.Items#asArrayItems()
177- */
178172 @ Override
179173 public ArrayItems asArrayItems () { return this ; }
180-
181- /* (non-Javadoc)
182- * @see java.lang.Object#equals(java.lang.Object)
183- */
174+
184175 @ Override
185176 public boolean equals (Object obj ) {
186177 if (obj instanceof Items ) {
@@ -194,38 +185,40 @@ public boolean equals(Object obj) {
194185 public JsonSchema [] getJsonSchemas () {
195186 return jsonSchemas ;
196187 }
197-
198- /* (non-Javadoc)
199- * @see com.fasterxml.jackson.databind.jsonSchema.types.ArraySchema.Items#isArrayItems()
200- */
188+
201189 @ Override
202190 public boolean isArrayItems () { return true ; }
203191 }
204192
205- public static class ItemsDeserializer extends JsonDeserializer <Items > {
193+ public static class ItemsDeserializer extends StdDeserializer <Items >
194+ {
195+ private static final long serialVersionUID = 1L ;
206196
207- @ Override
208- public Items deserialize (JsonParser parser ,
209- DeserializationContext context ) throws IOException , JsonProcessingException {
210- ObjectCodec mapper = parser .getCodec ();
211- JsonNode node = parser .readValueAs (JsonNode .class );
197+ public ItemsDeserializer () {
198+ super (Items .class );
199+ }
212200
213- if (node .isArray ()) {
214- JsonSchema [] schemas = mapper .treeToValue (node , JsonSchema [].class );
201+ @ Override
202+ public Items deserialize (JsonParser parser ,
203+ DeserializationContext context ) throws IOException
204+ {
205+ // 07-Oct-2015, tatu: Could further optimize by fetching delegating
206+ // deserializer in `createContextual`, but should do for now
207+ if (parser .isExpectedStartArrayToken ()) {
208+ JsonSchema [] schemas = context .readValue (parser , JsonSchema [].class );
209+ return new ArrayItems (schemas );
210+ }
211+ JsonSchema schema = context .readValue (parser , JsonSchema .class );
212+ return new SingleItems (schema );
213+ }
214+ }
215215
216- return new ArrayItems (schemas );
217- }
218- else
219- return new SingleItems (mapper .treeToValue (node , JsonSchema .class ));
220- }
221- }
222-
223- /**
224- * This attribute defines the allowed items in an instance array, and
216+ /**
217+ * This attribute defines the allowed items in an instance array, and
225218 MUST be a jsonSchema or an array of jsonSchemas. The default value is an
226219 empty jsonSchema which allows any value for items in the instance array.
227- */
228- public static abstract class Items {
220+ */
221+ public static abstract class Items {
229222
230223 @ JsonIgnore
231224 public boolean isSingleItems () { return false ; }
@@ -242,10 +235,6 @@ public static abstract class Items {
242235 to indicate additional items in the array are not allowed
243236 */
244237 public static class NoAdditionalItems extends AdditionalItems {
245-
246- /* (non-Javadoc)
247- * @see java.lang.Object#equals(java.lang.Object)
248- */
249238 @ Override
250239 public boolean equals (Object obj ) {
251240 return obj instanceof NoAdditionalItems ;
0 commit comments