Search in sources :

Example 1 with SchemaAware

use of com.fasterxml.jackson.databind.jsonschema.SchemaAware in project jsonschema2pojo by joelittlejohn.

the class SchemaGenerator method simpleTypeSchema.

private ObjectNode simpleTypeSchema(JsonNode exampleValue) {
    try {
        Object valueAsJavaType = OBJECT_MAPPER.treeToValue(exampleValue, Object.class);
        SchemaAware valueSerializer = getValueSerializer(valueAsJavaType);
        return (ObjectNode) valueSerializer.getSchema(OBJECT_MAPPER.getSerializerProvider(), null);
    } catch (JsonMappingException e) {
        throw new GenerationException("Unable to generate a schema for this json example: " + exampleValue, e);
    } catch (JsonProcessingException e) {
        throw new GenerationException("Unable to generate a schema for this json example: " + exampleValue, e);
    }
}
Also used : SchemaAware(com.fasterxml.jackson.databind.jsonschema.SchemaAware) ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) JsonMappingException(com.fasterxml.jackson.databind.JsonMappingException) GenerationException(org.jsonschema2pojo.exception.GenerationException) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException)

Example 2 with SchemaAware

use of com.fasterxml.jackson.databind.jsonschema.SchemaAware in project jackson-databind by FasterXML.

the class BeanPropertyWriter method depositSchemaProperty.

// // // Legacy support for JsonFormatVisitable
/**
     * Attempt to add the output of the given {@link BeanPropertyWriter} in the
     * given {@link ObjectNode}. Otherwise, add the default schema
     * {@link JsonNode} in place of the writer's output
     * 
     * @param propertiesNode
     *            Node which the given property would exist within
     * @param provider
     *            Provider that can be used for accessing dynamic aspects of
     *            serialization processing
     */
@Override
@Deprecated
public void depositSchemaProperty(ObjectNode propertiesNode, SerializerProvider provider) throws JsonMappingException {
    JavaType propType = getSerializationType();
    // 03-Dec-2010, tatu: SchemaAware REALLY should use JavaType, but alas
    // it doesn't...
    Type hint = (propType == null) ? getType() : propType.getRawClass();
    JsonNode schemaNode;
    // Maybe it already has annotated/statically configured serializer?
    JsonSerializer<Object> ser = getSerializer();
    if (ser == null) {
        // nope
        ser = provider.findValueSerializer(getType(), this);
    }
    boolean isOptional = !isRequired();
    if (ser instanceof SchemaAware) {
        schemaNode = ((SchemaAware) ser).getSchema(provider, hint, isOptional);
    } else {
        schemaNode = com.fasterxml.jackson.databind.jsonschema.JsonSchema.getDefaultSchemaNode();
    }
    _depositSchemaProperty(propertiesNode, schemaNode);
}
Also used : Type(java.lang.reflect.Type) SchemaAware(com.fasterxml.jackson.databind.jsonschema.SchemaAware)

Example 3 with SchemaAware

use of com.fasterxml.jackson.databind.jsonschema.SchemaAware in project jackson-databind by FasterXML.

the class AsArraySerializerBase method getSchema.

@SuppressWarnings("deprecation")
@Override
public JsonNode getSchema(SerializerProvider provider, Type typeHint) throws JsonMappingException {
    ObjectNode o = createSchemaNode("array", true);
    if (_elementSerializer != null) {
        JsonNode schemaNode = null;
        if (_elementSerializer instanceof SchemaAware) {
            schemaNode = ((SchemaAware) _elementSerializer).getSchema(provider, null);
        }
        if (schemaNode == null) {
            schemaNode = com.fasterxml.jackson.databind.jsonschema.JsonSchema.getDefaultSchemaNode();
        }
        o.set("items", schemaNode);
    }
    return o;
}
Also used : ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) SchemaAware(com.fasterxml.jackson.databind.jsonschema.SchemaAware)

Aggregations

SchemaAware (com.fasterxml.jackson.databind.jsonschema.SchemaAware)3 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)2 JsonProcessingException (com.fasterxml.jackson.core.JsonProcessingException)1 JsonMappingException (com.fasterxml.jackson.databind.JsonMappingException)1 Type (java.lang.reflect.Type)1 GenerationException (org.jsonschema2pojo.exception.GenerationException)1