use of com.fasterxml.jackson.databind.JsonNode in project swagger-core by swagger-api.
the class PropertyDeserializer method getEnum.
private static List<String> getEnum(JsonNode node, PropertyBuilder.PropertyId type) {
final List<String> result = new ArrayList<String>();
JsonNode detailNode = getDetailNode(node, type);
if (detailNode != null) {
ArrayNode an = (ArrayNode) detailNode;
for (JsonNode child : an) {
if (child instanceof TextNode || child instanceof NumericNode || child instanceof IntNode || child instanceof LongNode || child instanceof DoubleNode || child instanceof FloatNode) {
result.add(child.asText());
}
}
}
return result.isEmpty() ? null : result;
}
use of com.fasterxml.jackson.databind.JsonNode in project swagger-core by swagger-api.
the class PropertyDeserializer method deserialize.
@Override
public Property deserialize(JsonParser jp, DeserializationContext ctxt) throws IOException, JsonProcessingException {
JsonNode node = jp.getCodec().readTree(jp);
Property property = propertyFromNode(node);
if (property != null) {
property.setXml(getXml(node));
}
return property;
}
use of com.fasterxml.jackson.databind.JsonNode in project swagger-core by swagger-api.
the class PropertyDeserializer method getRequired.
private static List<String> getRequired(JsonNode node, PropertyBuilder.PropertyId type) {
List<String> result = new ArrayList<String>();
final JsonNode detailNode = getDetailNode(node, type);
if (detailNode == null) {
return result;
}
if (detailNode.isArray()) {
ArrayNode arrayNode = (ArrayNode) detailNode;
Iterator<JsonNode> fieldNameIter = arrayNode.iterator();
while (fieldNameIter.hasNext()) {
JsonNode item = fieldNameIter.next();
result.add(item.asText());
}
return result;
} else {
throw new RuntimeException("Required property should be a list");
}
}
use of com.fasterxml.jackson.databind.JsonNode in project swagger-core by swagger-api.
the class PropertyDeserializer method getVendorExtensions.
//because of the complexity of deserializing properties we must handle vendor extensions by hand
private static Map<String, Object> getVendorExtensions(JsonNode node) {
Map<String, Object> result = new HashMap<String, Object>();
Iterator<String> fieldNameIter = node.fieldNames();
while (fieldNameIter.hasNext()) {
String fieldName = fieldNameIter.next();
if (fieldName.startsWith("x-")) {
JsonNode extensionField = node.get(fieldName);
Object extensionObject = Json.mapper().convertValue(extensionField, Object.class);
result.put(fieldName, extensionObject);
}
}
return result;
}
use of com.fasterxml.jackson.databind.JsonNode in project swagger-core by swagger-api.
the class ModelDeserializer method deserialize.
@Override
public Model deserialize(JsonParser jp, DeserializationContext ctxt) throws IOException, JsonProcessingException {
JsonNode node = jp.getCodec().readTree(jp);
JsonNode sub = node.get("$ref");
JsonNode allOf = node.get("allOf");
if (sub != null) {
return Json.mapper().convertValue(sub, RefModel.class);
} else if (allOf != null) {
ComposedModel model = null;
// we only support one parent, no multiple inheritance or composition
model = Json.mapper().convertValue(node, ComposedModel.class);
List<Model> allComponents = model.getAllOf();
if (allComponents.size() >= 1) {
model.setParent(allComponents.get(0));
if (allComponents.size() >= 2) {
model.setChild(allComponents.get(allComponents.size() - 1));
List<RefModel> interfaces = new ArrayList<RefModel>();
int size = allComponents.size();
for (Model m : allComponents.subList(1, size - 1)) {
if (m instanceof RefModel) {
RefModel ref = (RefModel) m;
interfaces.add(ref);
}
}
model.setInterfaces(interfaces);
} else {
model.setChild(new ModelImpl());
}
}
return model;
} else {
sub = node.get("type");
Model model = null;
if (sub != null && "array".equals(((TextNode) sub).textValue())) {
model = Json.mapper().convertValue(node, ArrayModel.class);
} else {
model = Json.mapper().convertValue(node, ModelImpl.class);
}
return model;
}
}
Aggregations