use of com.fasterxml.jackson.databind.node.ObjectNode in project jsonschema2pojo by joelittlejohn.
the class SchemaMapper method readSchema.
private ObjectNode readSchema(URL schemaUrl) {
switch(ruleFactory.getGenerationConfig().getSourceType()) {
case JSONSCHEMA:
ObjectNode schemaNode = NODE_FACTORY.objectNode();
schemaNode.put("$ref", schemaUrl.toString());
return schemaNode;
case JSON:
return schemaGenerator.schemaFromExample(schemaUrl);
default:
throw new IllegalArgumentException("Unrecognised source type: " + ruleFactory.getGenerationConfig().getSourceType());
}
}
use of com.fasterxml.jackson.databind.node.ObjectNode 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.node.ObjectNode in project jsonschema2pojo by joelittlejohn.
the class SchemaGenerator method objectSchema.
private ObjectNode objectSchema(JsonNode exampleObject) {
ObjectNode schema = OBJECT_MAPPER.createObjectNode();
schema.put("type", "object");
ObjectNode properties = OBJECT_MAPPER.createObjectNode();
for (Iterator<String> iter = exampleObject.fieldNames(); iter.hasNext(); ) {
String property = iter.next();
properties.set(property, schemaFromExample(exampleObject.get(property)));
}
schema.set("properties", properties);
return schema;
}
use of com.fasterxml.jackson.databind.node.ObjectNode in project jsonschema2pojo by joelittlejohn.
the class SchemaGenerator method arraySchema.
private ObjectNode arraySchema(JsonNode exampleArray) {
ObjectNode schema = OBJECT_MAPPER.createObjectNode();
schema.put("type", "array");
if (exampleArray.size() > 0) {
JsonNode exampleItem = exampleArray.get(0).isObject() ? mergeArrayItems(exampleArray) : exampleArray.get(0);
schema.set("items", schemaFromExample(exampleItem));
}
return schema;
}
use of com.fasterxml.jackson.databind.node.ObjectNode in project JsonPath by jayway.
the class JacksonJsonNodeJsonProvider method getMapValue.
@Override
public Object getMapValue(Object obj, String key) {
ObjectNode jsonObject = toJsonObject(obj);
Object o = jsonObject.get(key);
if (!jsonObject.has(key)) {
return UNDEFINED;
} else {
return unwrap(o);
}
}
Aggregations