• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 package com.fasterxml.jackson.databind.jsonschema;
2 
3 import java.util.*;
4 
5 import com.fasterxml.jackson.databind.*;
6 
7 /**
8  * Trivial test to ensure <code>JsonSchema</code> can be also deserialized
9  */
10 public class TestReadJsonSchema
11     extends com.fasterxml.jackson.databind.BaseMapTest
12 {
13     enum SchemaEnum { YES, NO; }
14 
15     static class Schemable {
16         public String name;
17         public char[] nameBuffer;
18 
19         // We'll include tons of stuff, just to force generation of schema
20         public boolean[] states;
21         public byte[] binaryData;
22         public short[] shorts;
23         public int[] ints;
24         public long[] longs;
25 
26         public float[] floats;
27         public double[] doubles;
28 
29         public Object[] objects;
30         public JsonSerializable someSerializable;
31 
32         public Iterable<Object> iterableOhYeahBaby;
33 
34         public List<String> extra;
35         public ArrayList<String> extra2;
36         public Iterator<String[]> extra3;
37 
38         public Map<String,Double> sizes;
39         public EnumMap<SchemaEnum,List<String>> whatever;
40 
41         SchemaEnum testEnum;
42         public EnumSet<SchemaEnum> testEnums;
43     }
44 
45     /**
46      * Verifies that a simple schema that is serialized can be
47      * deserialized back to equal schema instance
48      */
49     @SuppressWarnings("deprecation")
testDeserializeSimple()50     public void testDeserializeSimple() throws Exception
51     {
52         ObjectMapper mapper = new ObjectMapper();
53         JsonSchema schema = mapper.generateJsonSchema(Schemable.class);
54         assertNotNull(schema);
55 
56         String schemaStr = mapper.writeValueAsString(schema);
57         assertNotNull(schemaStr);
58         JsonSchema result = mapper.readValue(schemaStr, JsonSchema.class);
59         assertEquals("Trying to read from '"+schemaStr+"'", schema, result);
60     }
61 }
62