Search in sources :

Example 11 with JsonNode

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;
}
Also used : IntNode(com.fasterxml.jackson.databind.node.IntNode) ArrayList(java.util.ArrayList) FloatNode(com.fasterxml.jackson.databind.node.FloatNode) DoubleNode(com.fasterxml.jackson.databind.node.DoubleNode) JsonNode(com.fasterxml.jackson.databind.JsonNode) TextNode(com.fasterxml.jackson.databind.node.TextNode) ArrayNode(com.fasterxml.jackson.databind.node.ArrayNode) NumericNode(com.fasterxml.jackson.databind.node.NumericNode) LongNode(com.fasterxml.jackson.databind.node.LongNode)

Example 12 with JsonNode

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;
}
Also used : JsonNode(com.fasterxml.jackson.databind.JsonNode) ArrayProperty(io.swagger.models.properties.ArrayProperty) RefProperty(io.swagger.models.properties.RefProperty) Property(io.swagger.models.properties.Property) MapProperty(io.swagger.models.properties.MapProperty) ObjectProperty(io.swagger.models.properties.ObjectProperty)

Example 13 with JsonNode

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");
    }
}
Also used : ArrayList(java.util.ArrayList) JsonNode(com.fasterxml.jackson.databind.JsonNode) ArrayNode(com.fasterxml.jackson.databind.node.ArrayNode)

Example 14 with JsonNode

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;
}
Also used : HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) JsonNode(com.fasterxml.jackson.databind.JsonNode)

Example 15 with JsonNode

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;
    }
}
Also used : RefModel(io.swagger.models.RefModel) ComposedModel(io.swagger.models.ComposedModel) RefModel(io.swagger.models.RefModel) ComposedModel(io.swagger.models.ComposedModel) Model(io.swagger.models.Model) ArrayModel(io.swagger.models.ArrayModel) JsonNode(com.fasterxml.jackson.databind.JsonNode) ArrayList(java.util.ArrayList) List(java.util.List) ModelImpl(io.swagger.models.ModelImpl)

Aggregations

JsonNode (com.fasterxml.jackson.databind.JsonNode)1055 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)275 Test (org.junit.Test)267 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)165 CloseableHttpResponse (org.apache.http.client.methods.CloseableHttpResponse)125 IOException (java.io.IOException)124 ArrayNode (com.fasterxml.jackson.databind.node.ArrayNode)97 HashMap (java.util.HashMap)78 ArrayList (java.util.ArrayList)75 HttpGet (org.apache.http.client.methods.HttpGet)69 JsonException (jmri.server.json.JsonException)66 Deployment (org.activiti.engine.test.Deployment)66 InputStream (java.io.InputStream)64 StringEntity (org.apache.http.entity.StringEntity)54 ByteArrayInputStream (java.io.ByteArrayInputStream)53 ProcessInstance (org.activiti.engine.runtime.ProcessInstance)49 Map (java.util.Map)45 Task (org.activiti.engine.task.Task)41 HttpPost (org.apache.http.client.methods.HttpPost)39 Tree (org.apache.jackrabbit.oak.api.Tree)30