Search in sources :

Example 31 with JsonNode

use of org.apache.flink.shaded.jackson2.com.fasterxml.jackson.databind.JsonNode in project textdb by TextDB.

the class PlanStoreResourceTest method checkJsonEquivalence.

public static boolean checkJsonEquivalence(String json1, String json2) throws IOException {
    ObjectMapper mapper = new ObjectMapper();
    JsonNode tree1 = mapper.readTree(json1);
    JsonNode tree2 = mapper.readTree(json2);
    return tree1.equals(tree2);
}
Also used : JsonNode(com.fasterxml.jackson.databind.JsonNode) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper)

Example 32 with JsonNode

use of org.apache.flink.shaded.jackson2.com.fasterxml.jackson.databind.JsonNode in project textdb by TextDB.

the class JsonSerializationTest method testIntegerField.

@Test
public void testIntegerField() {
    IntegerField integerField = new IntegerField(100);
    JsonNode jsonNode = TestUtils.testJsonSerialization(integerField);
    Assert.assertTrue(jsonNode.get(JsonConstants.FIELD_VALUE).isInt());
}
Also used : IntegerField(edu.uci.ics.textdb.api.field.IntegerField) JsonNode(com.fasterxml.jackson.databind.JsonNode) Test(org.junit.Test)

Example 33 with JsonNode

use of org.apache.flink.shaded.jackson2.com.fasterxml.jackson.databind.JsonNode in project textdb by TextDB.

the class PredicateBaseTest method testPredicate.

/*
     * A helper test function to assert if a predicate is 
     *   serialized / deserialized correctly
     *   by converting predicate to json, then back to predicate, then back to json again,
     *   assert two json strings are the same, (test if anything changed between conversions)
     *   and the json contains "operatorType" and "id". (test if the predicate is registered in PredicateBase)
     *   
     */
public static void testPredicate(PredicateBase predicate) throws Exception {
    JsonNode jsonNode = TestUtils.testJsonSerialization(predicate);
    Assert.assertTrue(jsonNode.has(PropertyNameConstants.OPERATOR_TYPE));
    Assert.assertTrue(jsonNode.has(PropertyNameConstants.OPERATOR_ID));
}
Also used : JsonNode(com.fasterxml.jackson.databind.JsonNode)

Example 34 with JsonNode

use of org.apache.flink.shaded.jackson2.com.fasterxml.jackson.databind.JsonNode 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 35 with JsonNode

use of org.apache.flink.shaded.jackson2.com.fasterxml.jackson.databind.JsonNode 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

JsonNode (com.fasterxml.jackson.databind.JsonNode)4105 Test (org.junit.Test)1257 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)802 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)544 IOException (java.io.IOException)532 ArrayNode (com.fasterxml.jackson.databind.node.ArrayNode)384 ArrayList (java.util.ArrayList)315 Test (org.junit.jupiter.api.Test)277 HashMap (java.util.HashMap)249 Map (java.util.Map)201 DefaultSerializerProvider (com.fasterxml.jackson.databind.ser.DefaultSerializerProvider)174 CloseableHttpResponse (org.apache.http.client.methods.CloseableHttpResponse)127 List (java.util.List)122 InputStream (java.io.InputStream)116 KernelTest (com.twosigma.beakerx.KernelTest)114 JsonProcessingException (com.fasterxml.jackson.core.JsonProcessingException)84 Response (javax.ws.rs.core.Response)79 File (java.io.File)78 HttpGet (org.apache.http.client.methods.HttpGet)75 ByteArrayInputStream (java.io.ByteArrayInputStream)70