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);
}
}
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);
}
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;
}
Aggregations