Search in sources :

Example 11 with ArrayNode

use of com.fasterxml.jackson.databind.node.ArrayNode in project KaiZen-OpenAPI-Editor by RepreZen.

the class SwaggerSchema method allowJsonRefInContext.

public void allowJsonRefInContext(String jsonReferenceContext, boolean allow) {
    if (jsonRefContexts.get(jsonReferenceContext) == null) {
        throw new IllegalArgumentException("Invalid JSON Reference Context: " + jsonReferenceContext);
    }
    // special case
    if (SwaggerPreferenceConstants.VALIDATION_REF_SECURITY_DEFINITIONS_OBJECT.equals(jsonReferenceContext)) {
        allowJsonRefInSecurityDefinitionsObject(allow);
        return;
    }
    ArrayNode definition = (ArrayNode) jsonRefContexts.get(jsonReferenceContext);
    // should preserve order of the original ArrayNode._children
    List<JsonNode> children = Lists.newArrayList(definition.elements());
    int indexOfJsonReference = children.indexOf(refToJsonReferenceNode);
    boolean alreadyHasJsonReference = indexOfJsonReference > -1;
    if (allow) {
        if (!alreadyHasJsonReference) {
            definition.add(refToJsonReferenceNode.deepCopy());
        }
    } else {
        // disallow
        if (alreadyHasJsonReference) {
            definition.remove(indexOfJsonReference);
        }
    }
}
Also used : JsonNode(com.fasterxml.jackson.databind.JsonNode) ArrayNode(com.fasterxml.jackson.databind.node.ArrayNode)

Example 12 with ArrayNode

use of com.fasterxml.jackson.databind.node.ArrayNode in project KaiZen-OpenAPI-Editor by RepreZen.

the class MultipleSwaggerErrorBuilder method getHumanFriendlyText.

protected String getHumanFriendlyText(JsonNode swaggerSchemaNode, final String defaultValue) {
    JsonNode title = swaggerSchemaNode.get("title");
    if (title != null) {
        return title.asText();
    }
    // nested array
    if (swaggerSchemaNode.get("items") != null) {
        return getHumanFriendlyText(swaggerSchemaNode.get("items"), defaultValue);
    }
    // "$ref":"#/definitions/headerParameterSubSchema"
    JsonNode ref = swaggerSchemaNode.get("$ref");
    if (ref != null) {
        return getLabelForRef(ref.asText());
    }
    // Auxiliary oneOf in "oneOf": [ { "$ref": "#/definitions/securityRequirement" }]
    JsonNode oneOf = swaggerSchemaNode.get("oneOf");
    if (oneOf != null) {
        if (oneOf instanceof ArrayNode) {
            ArrayNode arrayNode = (ArrayNode) oneOf;
            if (arrayNode.size() > 0) {
                Iterator<String> labels = transform(arrayNode.elements(), new Function<JsonNode, String>() {

                    @Override
                    public String apply(JsonNode el) {
                        return getHumanFriendlyText(el, defaultValue);
                    }
                });
                return "[" + Joiner.on(", ").join(labels) + "]";
            }
        }
    }
    return defaultValue;
}
Also used : JsonNode(com.fasterxml.jackson.databind.JsonNode) ArrayNode(com.fasterxml.jackson.databind.node.ArrayNode)

Example 13 with ArrayNode

use of com.fasterxml.jackson.databind.node.ArrayNode in project jackson-databind by FasterXML.

the class ObjectReaderTest method testTreeToValue.

/*
    /**********************************************************
    /* Test methods, ObjectCodec
    /**********************************************************
     */
public void testTreeToValue() throws Exception {
    ArrayNode n = MAPPER.createArrayNode();
    n.add("xyz");
    ObjectReader r = MAPPER.readerFor(String.class);
    List<?> list = r.treeToValue(n, List.class);
    assertEquals(1, list.size());
}
Also used : ArrayNode(com.fasterxml.jackson.databind.node.ArrayNode)

Example 14 with ArrayNode

use of com.fasterxml.jackson.databind.node.ArrayNode in project jackson-databind by FasterXML.

the class NodeMergeTest method testObjectDeepUpdate.

public void testObjectDeepUpdate() throws Exception {
    ObjectNode base = MAPPER.createObjectNode();
    ObjectNode props = base.putObject("props");
    props.put("base", 123);
    props.put("value", 456);
    ArrayNode a = props.putArray("array");
    a.add(true);
    base.putNull("misc");
    assertSame(base, MAPPER.readerForUpdating(base).readValue(aposToQuotes("{'props':{'value':true, 'extra':25.5, 'array' : [ 3 ]}}")));
    assertEquals(2, base.size());
    ObjectNode resultProps = (ObjectNode) base.get("props");
    assertEquals(4, resultProps.size());
    assertEquals(123, resultProps.path("base").asInt());
    assertTrue(resultProps.path("value").asBoolean());
    assertEquals(25.5, resultProps.path("extra").asDouble());
    JsonNode n = resultProps.get("array");
    assertEquals(ArrayNode.class, n.getClass());
    assertEquals(2, n.size());
    assertEquals(3, n.get(1).asInt());
}
Also used : ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) ArrayNode(com.fasterxml.jackson.databind.node.ArrayNode)

Example 15 with ArrayNode

use of com.fasterxml.jackson.databind.node.ArrayNode in project Activiti by Activiti.

the class BaseBpmnJsonConverter method addFormProperties.

protected void addFormProperties(List<FormProperty> formProperties, ObjectNode propertiesNode) {
    if (CollectionUtils.isEmpty(formProperties))
        return;
    ObjectNode formPropertiesNode = objectMapper.createObjectNode();
    ArrayNode propertiesArrayNode = objectMapper.createArrayNode();
    for (FormProperty property : formProperties) {
        ObjectNode propertyItemNode = objectMapper.createObjectNode();
        propertyItemNode.put(PROPERTY_FORM_ID, property.getId());
        propertyItemNode.put(PROPERTY_FORM_NAME, property.getName());
        propertyItemNode.put(PROPERTY_FORM_TYPE, property.getType());
        if (StringUtils.isNotEmpty(property.getExpression())) {
            propertyItemNode.put(PROPERTY_FORM_EXPRESSION, property.getExpression());
        } else {
            propertyItemNode.putNull(PROPERTY_FORM_EXPRESSION);
        }
        if (StringUtils.isNotEmpty(property.getVariable())) {
            propertyItemNode.put(PROPERTY_FORM_VARIABLE, property.getVariable());
        } else {
            propertyItemNode.putNull(PROPERTY_FORM_VARIABLE);
        }
        if (StringUtils.isNotEmpty(property.getDatePattern())) {
            propertyItemNode.put(PROPERTY_FORM_DATE_PATTERN, property.getDatePattern());
        }
        if (CollectionUtils.isNotEmpty(property.getFormValues())) {
            ArrayNode valuesNode = objectMapper.createArrayNode();
            for (FormValue formValue : property.getFormValues()) {
                ObjectNode valueNode = objectMapper.createObjectNode();
                valueNode.put(PROPERTY_FORM_ENUM_VALUES_NAME, formValue.getName());
                valueNode.put(PROPERTY_FORM_ENUM_VALUES_ID, formValue.getId());
                valuesNode.add(valueNode);
            }
            propertyItemNode.put(PROPERTY_FORM_ENUM_VALUES, valuesNode);
        }
        propertyItemNode.put(PROPERTY_FORM_REQUIRED, property.isRequired());
        propertyItemNode.put(PROPERTY_FORM_READABLE, property.isReadable());
        propertyItemNode.put(PROPERTY_FORM_WRITABLE, property.isWriteable());
        propertiesArrayNode.add(propertyItemNode);
    }
    formPropertiesNode.put("formProperties", propertiesArrayNode);
    propertiesNode.put(PROPERTY_FORM_PROPERTIES, formPropertiesNode);
}
Also used : ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) FormValue(org.activiti.bpmn.model.FormValue) FormProperty(org.activiti.bpmn.model.FormProperty) ArrayNode(com.fasterxml.jackson.databind.node.ArrayNode)

Aggregations

ArrayNode (com.fasterxml.jackson.databind.node.ArrayNode)711 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)383 JsonNode (com.fasterxml.jackson.databind.JsonNode)296 Test (org.junit.Test)113 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)90 ArrayList (java.util.ArrayList)67 IOException (java.io.IOException)62 HashMap (java.util.HashMap)50 Map (java.util.Map)50 TextNode (com.fasterxml.jackson.databind.node.TextNode)30 DefaultSerializerProvider (com.fasterxml.jackson.databind.ser.DefaultSerializerProvider)30 Deployment (org.activiti.engine.test.Deployment)23 List (java.util.List)22 HashSet (java.util.HashSet)21 ArrayNode (org.apache.flink.shaded.jackson2.com.fasterxml.jackson.databind.node.ArrayNode)20 StringEntity (org.apache.http.entity.StringEntity)20 JsonNodeFactory (com.fasterxml.jackson.databind.node.JsonNodeFactory)19 ProcessInstance (org.activiti.engine.runtime.ProcessInstance)19 Cluster (org.apache.geode.tools.pulse.internal.data.Cluster)18 HttpPost (org.apache.http.client.methods.HttpPost)16