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;
}
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));
}
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));
}
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))));
}
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", "#/.");
}
Aggregations