Search in sources :

Example 6 with ArrayNode

use of com.fasterxml.jackson.databind.node.ArrayNode in project native-navigation by airbnb.

the class ConversionUtil method toJsonArray.

/** Converts a {@link ReadableArray} into an Json {@link ArrayNode} */
static ArrayNode toJsonArray(ReadableArray readableArray) {
    JsonNodeFactory nodeFactory = JsonNodeFactory.instance;
    ArrayNode result = nodeFactory.arrayNode();
    for (int i = 0; i < readableArray.size(); i++) {
        ReadableType indexType = readableArray.getType(i);
        switch(indexType) {
            case Null:
                result.addNull();
                break;
            case Boolean:
                result.add(readableArray.getBoolean(i));
                break;
            case Number:
                result.add(readableArray.getDouble(i));
                break;
            case String:
                result.add(readableArray.getString(i));
                break;
            case Map:
                result.add(toJsonObject(readableArray.getMap(i)));
                break;
            case Array:
                result.add(toJsonArray(readableArray.getArray(i)));
                break;
            default:
                Log.e(TAG, "Could not convert object at index " + i + ".");
        }
    }
    return result;
}
Also used : ArrayNode(com.fasterxml.jackson.databind.node.ArrayNode) JsonNodeFactory(com.fasterxml.jackson.databind.node.JsonNodeFactory)

Example 7 with ArrayNode

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

the class RequiredArrayRuleTest method shouldUpdateJavaDoc.

@Test
public void shouldUpdateJavaDoc() throws JClassAlreadyExistsException {
    JDefinedClass jclass = new JCodeModel()._class(TARGET_CLASS_NAME);
    jclass.field(JMod.PRIVATE, jclass.owner().ref(String.class), "fooBar");
    jclass.field(JMod.PRIVATE, jclass.owner().ref(String.class), "foo");
    ObjectMapper mapper = new ObjectMapper();
    ArrayNode requiredNode = mapper.createArrayNode().add("fooBar");
    rule.apply("Class", requiredNode, jclass, new Schema(null, requiredNode, requiredNode));
    JDocComment fooBarJavaDoc = jclass.fields().get("fooBar").javadoc();
    JDocComment fooJavaDoc = jclass.fields().get("foo").javadoc();
    assertThat(fooBarJavaDoc.size(), is(1));
    assertThat((String) fooBarJavaDoc.get(0), is("\n(Required)"));
    assertThat(fooJavaDoc.size(), is(0));
}
Also used : JDefinedClass(com.sun.codemodel.JDefinedClass) Schema(org.jsonschema2pojo.Schema) ArrayNode(com.fasterxml.jackson.databind.node.ArrayNode) JCodeModel(com.sun.codemodel.JCodeModel) JDocComment(com.sun.codemodel.JDocComment) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) Test(org.junit.Test)

Example 8 with ArrayNode

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

the class RequiredArrayRuleTest method shouldUpdateAnnotations.

@Test
public void shouldUpdateAnnotations() throws JClassAlreadyExistsException {
    setupRuleFactoryToIncludeJsr303();
    JDefinedClass jclass = new JCodeModel()._class(TARGET_CLASS_NAME);
    jclass.field(JMod.PRIVATE, jclass.owner().ref(String.class), "fooBar");
    jclass.field(JMod.PRIVATE, jclass.owner().ref(String.class), "foo");
    ObjectMapper mapper = new ObjectMapper();
    ArrayNode requiredNode = mapper.createArrayNode().add("foo_bar");
    rule.apply("Class", requiredNode, jclass, new Schema(null, requiredNode, requiredNode));
    Collection<JAnnotationUse> fooBarAnnotations = jclass.fields().get("fooBar").annotations();
    Collection<JAnnotationUse> fooAnnotations = jclass.fields().get("foo").annotations();
    assertThat(fooBarAnnotations.size(), is(1));
    assertThat(fooBarAnnotations.iterator().next().getAnnotationClass().name(), is(NotNull.class.getSimpleName()));
    assertThat(fooAnnotations.size(), is(0));
}
Also used : JDefinedClass(com.sun.codemodel.JDefinedClass) Schema(org.jsonschema2pojo.Schema) JAnnotationUse(com.sun.codemodel.JAnnotationUse) ArrayNode(com.fasterxml.jackson.databind.node.ArrayNode) JCodeModel(com.sun.codemodel.JCodeModel) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) Test(org.junit.Test)

Example 9 with ArrayNode

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

the class FragmentResolverTest method pathCanReferToArrayContentsAtTheDocumentRoot.

@Test
public void pathCanReferToArrayContentsAtTheDocumentRoot() {
    ArrayNode root = new ObjectMapper().createArrayNode();
    root.add(root.objectNode());
    root.add(root.objectNode());
    root.add(root.objectNode());
    assertThat(resolver.resolve(root, "#/0", "#/."), is(sameInstance(root.get(0))));
    assertThat(resolver.resolve(root, "#/1", "#/."), is(sameInstance(root.get(1))));
    assertThat(resolver.resolve(root, "#/2", "#/."), is(sameInstance(root.get(2))));
}
Also used : ArrayNode(com.fasterxml.jackson.databind.node.ArrayNode) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) Test(org.junit.Test)

Example 10 with ArrayNode

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

the class FragmentResolverTest method attemptToUsePropertyNameOnArrayNodeThrowsIllegalArgumentException.

@Test(expected = IllegalArgumentException.class)
public void attemptToUsePropertyNameOnArrayNodeThrowsIllegalArgumentException() {
    ObjectNode root = new ObjectMapper().createObjectNode();
    ArrayNode a = root.arrayNode();
    root.set("a", a);
    resolver.resolve(root, "#/a/b", "#/.");
}
Also used : ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) ArrayNode(com.fasterxml.jackson.databind.node.ArrayNode) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) Test(org.junit.Test)

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