Package com.fasterxml.jackson.databind.jsonschema

Examples of com.fasterxml.jackson.databind.jsonschema.JsonSchema


     * deserialized back to equal schema instance
     */
    public void testDeserializeSimple() throws Exception
    {
        ObjectMapper mapper = new ObjectMapper();
        JsonSchema schema = mapper.generateJsonSchema(Schemable.class);
        assertNotNull(schema);

        String schemaStr = mapper.writeValueAsString(schema);
        assertNotNull(schemaStr);
        JsonSchema result = mapper.readValue(schemaStr, JsonSchema.class);
        assertEquals("Trying to read from '"+schemaStr+"'", schema, result);
    }
View Full Code Here


                JsonSchema.getDefaultSchemaNode();
        if (!(schemaNode instanceof ObjectNode)) {
            throw new IllegalArgumentException("Class " + type.getName() +
                    " would not be serialized as a JSON object and therefore has no schema");
        }
        return new JsonSchema((ObjectNode) schemaNode);
    }
View Full Code Here

        String className = ((ScalarNode) node).getValue();
        try
        {
            Class<?> clazz = Thread.currentThread().getContextClassLoader().loadClass(className);
            ObjectMapper objectMapper = new ObjectMapper();
            JsonSchema jsonSchema = objectMapper.generateJsonSchema(clazz);
            ByteArrayOutputStream baos = new ByteArrayOutputStream();
            objectMapper.writeValue(baos, jsonSchema);
            String schema = baos.toString();
            return new ScalarNode(Tag.STR, schema, node.getStartMark(), node.getEndMark(), ((ScalarNode) node).getStyle());
        }
View Full Code Here

                JsonSchema.getDefaultSchemaNode();
        if (!(schemaNode instanceof ObjectNode)) {
            throw new IllegalArgumentException("Class " + type.getName() +
                    " would not be serialized as a JSON object and therefore has no schema");
        }
        return new JsonSchema((ObjectNode) schemaNode);
    }
View Full Code Here

                    JsonSchema.getDefaultSchemaNode();
            if (!(schemaNode instanceof ObjectNode)) {
                throw new IllegalArgumentException("Class " + type.getName() +
                        " would not be serialized as a JSON object and therefore has no schema");
            }
            return new JsonSchema((ObjectNode) schemaNode);
        }
View Full Code Here

                    JsonSchema.getDefaultSchemaNode();
            if (!(schemaNode instanceof ObjectNode)) {
                throw new IllegalArgumentException("Class " + type.getName() +
                        " would not be serialized as a JSON object and therefore has no schema");
            }
            return new JsonSchema((ObjectNode) schemaNode);
        }
View Full Code Here

        return new ProjectionQuery(query);
    }

    private ObjectNode getSchemaNode(Class<?> pojoClass) {
        try {
            JsonSchema schema = mapper.generateJsonSchema(pojoClass);
            return schema.getSchemaNode();
        } catch (Exception e) {
            throw new RuntimeException("Unable to create field DBObject for class: " + pojoClass, e);
        }
    }
View Full Code Here

public class ObjectWithJaxbAnnotationsSchemaCustomizer extends JsonSchemaCustomizer {

    @Override
    public JsonSchema customize(JsonSchema originalSchema) {
        JsonSchema schema = super.customize(originalSchema);
//        schema.asObjectSchema().getProperties().get("SomeOtherProp").asStringSchema().setDefault("default-value");
        ((ObjectNode)schema.getSchemaNode().get("properties").get("SomeOtherProp")).set("default", new TextNode("default-value"));
        return schema;
    }
View Full Code Here

    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();
View Full Code Here

    public static String OPENSHIFT_BROKER_HOST = "OPENSHIFT_BROKER_HOST";
//    public static String OPENSHIFT_NAMESPACE = "OPENSHIFT_NAMESPACE";

    @Override
    public JsonSchema customize(JsonSchema originalSchema) {
        JsonSchema jsonSchema = super.customize(originalSchema);
        String defaultServerUrl = System.getenv(OPENSHIFT_BROKER_HOST);
        if (defaultServerUrl == null || defaultServerUrl.trim().equals("")) {
            defaultServerUrl = "openshift.redhat.com";
        }
//        jsonSchema.asObjectSchema().getProperties().get("serverUrl").asStringSchema().setDefault(defaultServerUrl);
        ((ObjectNode)jsonSchema.getSchemaNode().get("properties").get("serverUrl")).set("default", new TextNode(defaultServerUrl));
        return jsonSchema;
    }
View Full Code Here

TOP

Related Classes of com.fasterxml.jackson.databind.jsonschema.JsonSchema

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.