/**
  * Test for [JACKSON-415]
  *
  * @since 1.7
  */
 public void testWithJaxb() throws Exception {
   ObjectMapper mapper = getJaxbMapper();
   JsonSchema jsonSchema = mapper.generateJsonSchema(Address.class);
   ObjectNode root = jsonSchema.getSchemaNode();
   // should find two properties ("city", "state"), not just one...
   JsonNode itemsNode = root.findValue("properties");
   assertNotNull("Missing 'state' field", itemsNode.get("state"));
   assertNotNull("Missing 'city' field", itemsNode.get("city"));
   assertEquals(2, itemsNode.size());
 }
示例#2
0
 public String getSchemaForClass(Class<?> clazz) {
   LOG.debug("Looking up schema for {}", clazz.getCanonicalName());
   String name = clazz.getName();
   try {
     ObjectWriter writer = mapper.writer().withDefaultPrettyPrinter();
     JsonSchema jsonSchema = mapper.generateJsonSchema(clazz);
     customizeSchema(clazz, jsonSchema);
     return writer.writeValueAsString(jsonSchema);
     //            SchemaFactoryWrapper schemaFactoryWrapper = new SchemaFactoryWrapper();
     //            mapper.acceptJsonFormatVisitor(mapper.constructType(clazz),
     // schemaFactoryWrapper);
     //            com.fasterxml.jackson.module.jsonSchema.JsonSchema jsonSchema =
     // schemaFactoryWrapper.finalSchema();
     //            return writer.writeValueAsString(jsonSchema);
   } catch (Exception e) {
     LOG.warn("Failed to generate JSON schema for class " + name, e);
     throw new RuntimeException(e);
   }
 }