List of usage examples for com.fasterxml.jackson.databind.node ObjectNode get
public JsonNode get(String paramString)
From source file:com.squarespace.template.ReferenceScannerTest.java
@Test public void testPredicates() throws CodeException { ObjectNode result = scan("{.even? 2}#{.or odd? foo}!{.end}"); render(result);/*from ww w . j a v a2 s .c o m*/ assertEquals(result.get("instructions").get("PREDICATE").asInt(), 1); assertEquals(result.get("instructions").get("OR_PREDICATE").asInt(), 1); assertEquals(result.get("instructions").get("TEXT").asInt(), 2); }
From source file:org.apache.streams.rss.test.SyndEntryActivitySerizlizerTest.java
@Test public void testJsonData() throws Exception { Scanner scanner = new Scanner(this.getClass().getResourceAsStream("/TestSyndEntryJson.txt")); List<Activity> activities = Lists.newLinkedList(); List<ObjectNode> objects = Lists.newLinkedList(); SyndEntryActivitySerializer serializer = new SyndEntryActivitySerializer(); while (scanner.hasNext()) { String line = scanner.nextLine(); System.out.println(line); ObjectNode node = (ObjectNode) mapper.readTree(line); objects.add(node);/*from ww w . j a v a 2s . co m*/ activities.add(serializer.deserialize(node)); } assertEquals(11, activities.size()); for (int x = 0; x < activities.size(); x++) { ObjectNode n = objects.get(x); Activity a = activities.get(x); testActor(n.get("author").asText(), a.getActor()); testAuthor(n.get("author").asText(), a.getObject().getAuthor()); testProvider("id:providers:rss", "RSS", a.getProvider()); testProviderUrl(a.getProvider()); testVerb("post", a.getVerb()); testPublished(n.get("publishedDate").asText(), a.getPublished()); testUrl(n.get("uri").asText(), n.get("link").asText(), a); } }
From source file:org.gitana.platform.client.transfer.CopyJob.java
public List<TransferImport> getImports() { List<TransferImport> imports = new ArrayList<TransferImport>(); ArrayNode array = getArray(FIELD_IMPORTS); for (int i = 0; i < array.size(); i++) { ObjectNode object = (ObjectNode) array.get(i); TransferDependencyChain sources = TransferDependencyChain.create((ArrayNode) object.get("sources")); TransferDependencyChain targets = TransferDependencyChain.create((ArrayNode) object.get("targets")); TransferImport transferImport = new TransferImport(sources, targets); imports.add(transferImport);//from w w w . java 2 s.co m } return imports; }
From source file:org.onosproject.codec.impl.IntentCodec.java
@Override public Intent decode(ObjectNode json, CodecContext context) { checkNotNull(json, "JSON cannot be null"); String type = nullIsIllegal(json.get(TYPE), TYPE + MISSING_MEMBER_MESSAGE).asText(); if (type.equals(PointToPointIntent.class.getSimpleName())) { return context.codec(PointToPointIntent.class).decode(json, context); } else if (type.equals(HostToHostIntent.class.getSimpleName())) { return context.codec(HostToHostIntent.class).decode(json, context); } else if (type.equals(OpticalConnectivityIntent.class.getSimpleName())) { return context.codec(OpticalConnectivityIntent.class).decode(json, context); //Edited }//from www . j a v a 2 s. co m throw new IllegalArgumentException("Intent type " + type + " is not supported"); }
From source file:com.ibm.alchemy.api.DisambiguatedProcessor.java
@Override public List<StreamsDatum> process(StreamsDatum entry) { List<StreamsDatum> result = Lists.newArrayList(); ObjectNode rootDocument = MAPPER.convertValue(entry.getDocument(), ObjectNode.class); try {//from ww w . ja v a2 s.c om ArrayNode entities = (ArrayNode) rootDocument.get("extensions").get("entities").get("entities"); for (JsonNode entity : entities) { ObjectNode objectNode = (ObjectNode) entity; ObjectNode disambiguated = (ObjectNode) entity.get("disambiguated"); result.add(new StreamsDatum(disambiguated, disambiguated.get("name").asText())); } } catch (Throwable e) { } finally { return result; } }
From source file:org.apache.streams.converter.test.HoconConverterProcessorTest.java
/** * Tests derived object substitution conversion from String to ObjectNode *//*from w ww .ja v a 2 s . co m*/ @Test public void testHoconConverter2() { final String TEST_ID_2 = "2"; final String TEST_JSON_2 = "{\"race\":\"klingon\",\"gender\":\"male\",\"age\":18}"; StreamsProcessor processor = new HoconConverterProcessor(ObjectNode.class, "test2.conf", "demographics"); processor.prepare(null); StreamsDatum datum = new StreamsDatum(TEST_JSON_2, TEST_ID_2); List<StreamsDatum> result2 = processor.process(datum); assertNotNull(result2); assertEquals(1, result2.size()); StreamsDatum resultDatum = result2.get(0); assertTrue(resultDatum.getDocument() instanceof ObjectNode); assertTrue(resultDatum.getId().equals(TEST_ID_2)); ObjectNode resultDoc = (ObjectNode) resultDatum.getDocument(); assertNotNull(resultDoc); assertTrue(resultDoc.get("race") != null); assertTrue(resultDoc.get("age").asDouble() == 18); assertTrue(resultDoc.get("gender").asText().equals("female")); }
From source file:io.confluent.connect.elasticsearch.BulkIndexingClient.java
@Override public BulkResponse execute(Bulk bulk) throws IOException { final BulkResult result = client.execute(bulk); if (result.isSucceeded()) { return BulkResponse.success(); }// ww w.ja v a 2 s .c om boolean retriable = true; final List<Key> versionConflicts = new ArrayList<>(); final List<String> errors = new ArrayList<>(); for (BulkResult.BulkResultItem item : result.getItems()) { if (item.error != null) { final ObjectNode parsedError = (ObjectNode) OBJECT_MAPPER.readTree(item.error); final String errorType = parsedError.get("type").asText(""); if ("version_conflict_engine_exception".equals(errorType)) { versionConflicts.add(new Key(item.index, item.type, item.id)); } else if ("mapper_parse_exception".equals(errorType)) { retriable = false; errors.add(item.error); } else { errors.add(item.error); } } } if (!versionConflicts.isEmpty()) { LOG.debug("Ignoring version conflicts for items: {}", versionConflicts); if (errors.isEmpty()) { // The only errors were version conflicts return BulkResponse.success(); } } final String errorInfo = errors.isEmpty() ? result.getErrorMessage() : errors.toString(); return BulkResponse.failure(retriable, errorInfo); }
From source file:de.thingweb.servient.MultiThingTests.java
@Test public void notUrlConformNames() throws Exception { final String thingName = ensureUTF8("Ugly strange nime"); final Thing thing = new Thing(thingName); final String propertyName = ensureUTF8("not url komptibel"); thing.addProperty(Property.getBuilder(propertyName).build()); final String actionName = ensureUTF8("wierdly named ktschn"); thing.addAction(Action.getBuilder(actionName).build()); server.addThing(thing);/*from ww w .j ava 2 s. c o m*/ ServientBuilder.start(); URL thingroot = new URL("http://localhost:8080/things/"); final JsonNode jsonNode = jsonMapper.readTree(thingroot); assertThat("should be an object", jsonNode.isObject(), is(true)); final ObjectNode repo = (ObjectNode) jsonNode; final JsonNode thingDesc = repo.get(thingName); assertThat(thingDesc, notNullValue()); assertThat(thingDesc.isObject(), is(true)); // check if thingdesc is parseable final Thing thing1 = ThingDescriptionParser.fromJavaMap(thingDesc); assertThat("should be the same name", thing1.getName(), equalTo(thing.getName())); assertThat("should contain an action", thing1.getActions(), hasSize(greaterThanOrEqualTo(1))); assertThat("property name should be the same", thing1.getActions().get(0).getName(), equalTo(actionName)); assertThat("should contain a property", thing1.getProperties(), hasSize(greaterThanOrEqualTo(1))); assertThat("action name should be the same", thing1.getProperties().get(0).getName(), equalTo(propertyName)); }
From source file:io.swagger.test.processors.JacksonProcessorTest.java
@Test public void testConvertYamlContent() throws Exception { String input = "name: fehguy\nuserId: 42"; EntityProcessorFactory.addProcessor(JacksonProcessor.class, JacksonProcessor.APPLICATION_YAML_TYPE); InputStream is = new ByteArrayInputStream(input.getBytes()); MediaType t = MediaType.valueOf("application/yaml"); ObjectNode o = (ObjectNode) EntityProcessorFactory.readValue(t, is, JsonNode.class); assertEquals(o.getClass(), ObjectNode.class); assertEquals(o.get("name").asText(), "fehguy"); assertEquals(o.get("userId").asText(), "42"); }
From source file:com.aerofs.baseline.metrics.MetricsCommand.java
private ObjectNode getParent(ObjectNode root, String key) { ObjectNode node = root; for (String component : key.split("\\.")) { ObjectNode nextNode = (ObjectNode) node.get(component); if (nextNode == null) { nextNode = mapper.createObjectNode(); node.set(component, nextNode); }/* w w w . j ava2s . com*/ node = nextNode; } return node; }