Debian Codegraph @

src/test/java/com/fasterxml/jackson/module/jaxb/misc/TestSchemaGeneration.java

raw
1 package com.fasterxml.jackson.module.jaxb.misc;
2
3 import javax.xml.bind.annotation.*;
4
5 import com.fasterxml.jackson.databind.JsonNode;
6 import com.fasterxml.jackson.databind.ObjectMapper;
7 import com.fasterxml.jackson.databind.node.ObjectNode;
8 import com.fasterxml.jackson.databind.jsonschema.JsonSchema;
9 import com.fasterxml.jackson.module.jaxb.BaseJaxbTest;
10
11 /**
12 * Test(s) to see that JAXB annotations-based information is properly
13 * accessible and used by JSON Schema generation
14 *
15 * @author tatu
16 */
17 @SuppressWarnings("deprecation")
18 public class TestSchemaGeneration extends BaseJaxbTest
19 {
20 @XmlAccessorType(XmlAccessType.FIELD)
21 protected static class Person {
22 public String firstName;
23 public String lastName;
24
25 @XmlElement(type=Address.class)
26 public IAddress address;
27 }
28
29 protected interface IAddress {
30 public String getCity();
31 public void setCity(String city);
32 }
33
34 protected static class Address implements IAddress {
35 private String city;
36 private String state;
37
38 @Override
39 public String getCity() { return city; }
40 @Override
41 public void setCity(String city) { this.city = city; }
42
43 public String getState() { return state; }
44 public void setState(String state) { this.state = state; }
45 }
46
47 /*
48 /**********************************************************
49 /* Tests
50 /**********************************************************
51 */
52
53 /**
54 * Test for [JACKSON-415]
55 *
56 * @since 1.7
57 */
58 public void testWithJaxb() throws Exception
59 {
60 ObjectMapper mapper = getJaxbMapper();
61 JsonSchema jsonSchema = mapper.generateJsonSchema(Address.class);
62 ObjectNode root = jsonSchema.getSchemaNode();
63 // should find two properties ("city", "state"), not just one...
64 JsonNode itemsNode = root.findValue("properties");
65 assertNotNull("Missing 'state' field", itemsNode.get("state"));
66 assertNotNull("Missing 'city' field", itemsNode.get("city"));
67 assertEquals(2, itemsNode.size());
68 }
69 }