Search in sources :

Example 6 with JsonSchemaGenerator

use of com.fasterxml.jackson.module.jsonSchema.JsonSchemaGenerator in project fabric8 by jboss-fuse.

the class JsonSchemaLookup method getSchemaForClass.

public String getSchemaForClass(Class<?> clazz) {
    LOG.info("Looking up schema for " + clazz.getCanonicalName());
    String name = clazz.getName();
    try {
        ObjectWriter writer = mapper.writer().with(new FourSpacePrettyPrinter());
        JsonSchemaGenerator jsg = new JsonSchemaGenerator(mapper);
        JsonSchema jsonSchema = jsg.generateSchema(clazz);
        return writer.writeValueAsString(jsonSchema);
    } catch (Exception e) {
        LOG.log(Level.FINEST, "Failed to generate JSON schema for class " + name, e);
        return "";
    }
}
Also used : JsonSchema(com.fasterxml.jackson.module.jsonSchema.JsonSchema) ObjectWriter(com.fasterxml.jackson.databind.ObjectWriter) JsonSchemaGenerator(com.fasterxml.jackson.module.jsonSchema.JsonSchemaGenerator)

Aggregations

JsonSchemaGenerator (com.fasterxml.jackson.module.jsonSchema.JsonSchemaGenerator)6 JsonSchema (com.fasterxml.jackson.module.jsonSchema.JsonSchema)5 ObjectWriter (com.fasterxml.jackson.databind.ObjectWriter)2 JsonProperty (com.fasterxml.jackson.annotation.JsonProperty)1 JavaType (com.fasterxml.jackson.databind.JavaType)1 JsonNode (com.fasterxml.jackson.databind.JsonNode)1 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)1 SchemaFactoryWrapper (com.fasterxml.jackson.module.jsonSchema.factories.SchemaFactoryWrapper)1 ObjectSchema (com.fasterxml.jackson.module.jsonSchema.types.ObjectSchema)1 TexeraException (edu.uci.ics.texera.api.exception.TexeraException)1 IOException (java.io.IOException)1 Path (java.nio.file.Path)1 Ignore (org.junit.Ignore)1 Test (org.junit.Test)1