Search in sources :

Example 1 with ArrayNode

use of org.apache.flink.shaded.jackson2.com.fasterxml.jackson.databind.node.ArrayNode in project jvm-serializers by eishay.

the class JacksonJsonTree method readMedia.

protected static Media readMedia(JsonNode node) {
    Media media = new Media();
    JsonNode bitrate = node.get("bitrate");
    if (bitrate != null && !bitrate.isNull()) {
        media.bitrate = bitrate.intValue();
        media.hasBitrate = true;
    }
    media.copyright = node.path("copyright").textValue();
    media.duration = node.path("duration").longValue();
    media.format = node.path("format").textValue();
    media.height = node.path("height").intValue();
    media.player = Media.Player.valueOf(node.get("player").textValue());
    ArrayNode personsArrayNode = (ArrayNode) node.get("persons");
    int size = personsArrayNode.size();
    List<String> persons = new ArrayList<String>(size);
    for (JsonNode person : personsArrayNode) {
        persons.add(person.textValue());
    }
    media.persons = persons;
    media.size = node.get("size").intValue();
    media.title = node.get("title").textValue();
    media.uri = node.get("uri").textValue();
    media.width = node.get("width").intValue();
    return media;
}
Also used : Media(data.media.Media) ArrayList(java.util.ArrayList) JsonNode(com.fasterxml.jackson.databind.JsonNode) ArrayNode(com.fasterxml.jackson.databind.node.ArrayNode)

Example 2 with ArrayNode

use of org.apache.flink.shaded.jackson2.com.fasterxml.jackson.databind.node.ArrayNode in project jvm-serializers by eishay.

the class JacksonJsonTree method addMedia.

protected static ObjectNode addMedia(Media media, ObjectNode node) {
    if (media.hasBitrate) {
        node.put("bitrate", media.bitrate);
    }
    node.put("copyright", media.copyright);
    node.put("duration", media.duration);
    node.put("format", media.format);
    node.put("height", media.height);
    ArrayNode persons = node.arrayNode();
    for (String person : media.persons) {
        persons.add(person);
    }
    node.set("persons", persons);
    node.put("player", media.player.name());
    node.put("size", media.size);
    node.put("title", media.title);
    node.put("uri", media.uri);
    node.put("width", media.width);
    return node;
}
Also used : ArrayNode(com.fasterxml.jackson.databind.node.ArrayNode)

Example 3 with ArrayNode

use of org.apache.flink.shaded.jackson2.com.fasterxml.jackson.databind.node.ArrayNode in project jvm-serializers by eishay.

the class JacksonJsonTree method readMediaContent.

protected static MediaContent readMediaContent(JsonNode root) throws IOException {
    MediaContent mediaContent = new MediaContent();
    mediaContent.media = readMedia(root.get("media"));
    mediaContent.images = readImages((ArrayNode) root.get("images"));
    return mediaContent;
}
Also used : MediaContent(data.media.MediaContent) ArrayNode(com.fasterxml.jackson.databind.node.ArrayNode)

Example 4 with ArrayNode

use of org.apache.flink.shaded.jackson2.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 5 with ArrayNode

use of org.apache.flink.shaded.jackson2.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)

Aggregations

ArrayNode (com.fasterxml.jackson.databind.node.ArrayNode)979 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)542 JsonNode (com.fasterxml.jackson.databind.JsonNode)402 Test (org.junit.Test)140 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)125 ArrayList (java.util.ArrayList)110 IOException (java.io.IOException)93 Map (java.util.Map)74 HashMap (java.util.HashMap)68 List (java.util.List)50 TextNode (com.fasterxml.jackson.databind.node.TextNode)38 Test (org.testng.annotations.Test)35 DefaultSerializerProvider (com.fasterxml.jackson.databind.ser.DefaultSerializerProvider)30 HashSet (java.util.HashSet)30 JsonNodeFactory (com.fasterxml.jackson.databind.node.JsonNodeFactory)25 Deployment (org.activiti.engine.test.Deployment)23 File (java.io.File)22 InputStream (java.io.InputStream)20 Iterator (java.util.Iterator)20 StringEntity (org.apache.http.entity.StringEntity)20