List of usage examples for com.fasterxml.jackson.databind.node JsonNodeFactory instance
JsonNodeFactory instance
To view the source code for com.fasterxml.jackson.databind.node JsonNodeFactory instance.
Click Source Link
From source file:org.apache.taverna.gis.GisActivityFactoryTest.java
@Test public void testGetInputPorts() { Set<String> expectedInputs = new HashSet<String>(); expectedInputs.add("firstInput"); Set<ActivityInputPort> inputPorts = activityFactory.getInputPorts(configuration); assertEquals("Unexpected inputs", expectedInputs.size(), inputPorts.size()); for (ActivityInputPort inputPort : inputPorts) { assertTrue("Wrong input : " + inputPort.getName(), expectedInputs.remove(inputPort.getName())); }// w w w . j av a 2 s. c om ObjectNode specialConfiguration = JsonNodeFactory.instance.objectNode(); specialConfiguration.put("exampleString", "specialCase"); specialConfiguration.put("exampleUri", "http://localhost:8080/myEndPoint"); assertEquals("Unexpected inputs", 2, activityFactory.getInputPorts(specialConfiguration).size()); }
From source file:io.syndesis.maven.ExtractConnectorDescriptorsMojo.java
@Override @SuppressWarnings("PMD.EmptyCatchBlock") public void execute() throws MojoExecutionException, MojoFailureException { ArrayNode root = new ArrayNode(JsonNodeFactory.instance); URLClassLoader classLoader = null; try {/*from w w w .j av a2 s.c o m*/ PluginDescriptor desc = (PluginDescriptor) getPluginContext().get("pluginDescriptor"); List<Artifact> artifacts = desc.getArtifacts(); ProjectBuildingRequest buildingRequest = new DefaultProjectBuildingRequest( session.getProjectBuildingRequest()); buildingRequest.setRemoteRepositories(remoteRepositories); for (Artifact artifact : artifacts) { ArtifactResult result = artifactResolver.resolveArtifact(buildingRequest, artifact); File jar = result.getArtifact().getFile(); classLoader = createClassLoader(jar); if (classLoader == null) { throw new IOException("Can not create classloader for " + jar); } ObjectNode entry = new ObjectNode(JsonNodeFactory.instance); addConnectorMeta(entry, classLoader); addComponentMeta(entry, classLoader); if (entry.size() > 0) { addGav(entry, artifact); root.add(entry); } } if (root.size() > 0) { saveCamelMetaData(root); } } catch (ArtifactResolverException | IOException e) { throw new MojoExecutionException(e.getMessage(), e); } finally { if (classLoader != null) { try { classLoader.close(); } catch (IOException ignored) { } } } }
From source file:org.springframework.data.rest.webmvc.json.patch.JsonPatchPatchConverter.java
/** * Renders a {@link Patch} as a {@link JsonNode}. * /*from w w w . jav a 2s . c o m*/ * @param patch the patch * @return a {@link JsonNode} containing JSON Patch. */ public JsonNode convert(Patch patch) { List<PatchOperation> operations = patch.getOperations(); JsonNodeFactory nodeFactory = JsonNodeFactory.instance; ArrayNode patchNode = nodeFactory.arrayNode(); for (PatchOperation operation : operations) { ObjectNode opNode = nodeFactory.objectNode(); opNode.set("op", nodeFactory.textNode(operation.getOp())); opNode.set("path", nodeFactory.textNode(operation.getPath())); if (operation instanceof FromOperation) { FromOperation fromOp = (FromOperation) operation; opNode.set("from", nodeFactory.textNode(fromOp.getFrom())); } Object value = operation.getValue(); if (value != null) { opNode.set("value", MAPPER.valueToTree(value)); } patchNode.add(opNode); } return patchNode; }
From source file:com.sqs.tq.fdc.FileVariantAnalyser.java
private ObjectNode convertToJson(List<GroupData> hashSortedByCount) { ObjectNode result = JsonNodeFactory.instance.objectNode(); ArrayNode groupsNode = result.arrayNode(); result.put("name", "???"); result.set("groups", groupsNode); for (GroupData gd : hashSortedByCount) { ObjectNode jgd = groupsNode.objectNode(); ArrayNode filesNode = groupsNode.arrayNode(); groupsNode.add(jgd);/*from w w w . j a va 2 s. c o m*/ jgd.put("hash", gd.hash); jgd.set("files", filesNode); for (FileData fd : gd.data) { filesNode.add(fd.fqn); } } return result; }
From source file:com.mirth.connect.client.ui.components.rsta.RSTAPreferences.java
String getKeyStrokesJSON() { ObjectNode keyStrokesNode = JsonNodeFactory.instance.objectNode(); for (Entry<String, KeyStroke> entry : getKeyStrokeMap().entrySet()) { if (entry.getValue() != null) { ArrayNode arrayNode = keyStrokesNode.putArray(entry.getKey()); arrayNode.add(entry.getValue().getKeyCode()); arrayNode.add(entry.getValue().getModifiers()); } else {//from w w w. j av a2 s.c o m keyStrokesNode.putNull(entry.getKey()); } } return keyStrokesNode.toString(); }
From source file:org.flowable.admin.service.engine.EventSubscriptionService.java
public void triggerMessageEvent(ServerConfig serverConfig, String eventName, String tenantId) { ObjectNode node = JsonNodeFactory.instance.objectNode(); node.put("message", eventName); if (tenantId != null && tenantId.length() > 0) { node.put("tenantId", tenantId); }/*from w w w . j a v a2 s . c o m*/ HttpPost post = clientUtil.createPost("runtime/process-instances", serverConfig); post.setEntity(clientUtil.createStringEntity(node)); clientUtil.executeRequest(post, serverConfig); }
From source file:com.nebhale.jsonpath.internal.parser.RecoveringPathParserTest.java
@Test public void wildcardIndex() { JsonNode nodeBook = NODE.get("store").get("book"); ArrayNode expected = JsonNodeFactory.instance.arrayNode(); expected.add(nodeBook.get(0));/*from w w w .j ava 2 s.c o m*/ expected.add(nodeBook.get(1)); expected.add(nodeBook.get(2)); expected.add(nodeBook.get(3)); ParserResult result = this.parser.parse("$.store.book[*]"); assertNoProblems(result); assertEquals(expected, result.getPathComponent().get(NODE)); }
From source file:org.apache.solr.kelvin.scorer.ScorersTest.java
public void testTestScorer() throws Exception { TestScorer T = new TestScorer(); T.configure(JsonNodeFactory.instance.objectNode()); T.update(null, new TestCaseTestEvent(null, null, true)); T.update(null, new TestCaseTestEvent(null, new Properties(), true)); T.update(null, new TestCaseTestEvent(null, new Properties(), false)); T.update(null, new TestCaseTestEvent(null, new Properties(), true)); T.update(null, new TestCaseTestEvent(null, new Properties(), false)); T.update(null, new TestCaseTestEvent(null, new Properties(), true)); T.update(null, new TestCaseTestEvent(null, new Properties(), false)); T.update(null, new TestCaseTestEvent(null, null, false)); assertEquals(1.0, peek(T, "numTests").getValue()); assertEquals(3.0, peek(T, "numQueries").getValue()); }
From source file:com.turn.shapeshifter.AutoSerializer.java
/** * Serializes a repeated field./*from w w w . ja v a2s. c o m*/ * * @param message the message being serialized * @param registry a registry of schemas, for enclosed object types * @param field the descriptor of the repeated field to serialize * @param count the count of repeated items in the field * @return the JSON representation of the serialized * @throws SerializationException */ private ArrayNode serializeRepeatedField(Message message, FieldDescriptor field, ReadableSchemaRegistry registry) throws SerializationException { ArrayNode array = new ArrayNode(JsonNodeFactory.instance); int count = message.getRepeatedFieldCount(field); for (int i = 0; i < count; i++) { Object value = message.getRepeatedField(field, i); JsonNode valueNode = serializeValue(value, field, registry); if (!valueNode.isNull()) { array.add(valueNode); } } return array; }
From source file:com.stratio.ingestion.sink.kafka.KafkaSinkTest.java
@Test public void test() throws EventDeliveryException, UnsupportedEncodingException { Transaction tx = channel.getTransaction(); tx.begin();//www . ja va 2 s . co m ObjectNode jsonBody = new ObjectNode(JsonNodeFactory.instance); jsonBody.put("myString", "foo"); jsonBody.put("myInt32", 32); Map<String, String> headers = new HashMap<String, String>(); headers.put("myString", "bar"); headers.put("myInt64", "64"); headers.put("myBoolean", "true"); headers.put("myDouble", "1.0"); headers.put("myNull", "foobar"); Event event = EventBuilder.withBody(jsonBody.toString().getBytes(Charsets.UTF_8), headers); channel.put(event); tx.commit(); tx.close(); kafkaSink.process(); kafka.api.FetchRequest req = new FetchRequestBuilder().clientId(CLIENT_ID).addFetch("test", 0, 0L, 100) .build(); FetchResponse fetchResponse = simpleConsumer.fetch(req); ByteBufferMessageSet messageSet = fetchResponse.messageSet("test", 0); Assert.assertTrue(messageSet.sizeInBytes() > 0); for (MessageAndOffset messageAndOffset : messageSet) { ByteBuffer payload = messageAndOffset.message().payload(); byte[] bytes = new byte[payload.limit()]; payload.get(bytes); String message = new String(bytes, "UTF-8"); Assert.assertNotNull(message); Assert.assertEquals(message, "{\"myString\":\"foo\",\"myInt32\":32}"); } }