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.jboss.aerogear.unifiedpush.rest.util.RequestTransformer.java
private JsonNode transformJson(JsonNode patch, StringBuilder json) throws IOException, JsonPatchException { JsonNode jsonNode = convertToJsonNode(json); for (JsonNode operation : patch) { try {/*from w w w . ja v a 2 s . com*/ final ArrayNode nodes = JsonNodeFactory.instance.arrayNode(); nodes.add(operation); JsonPatch patchOperation = JsonPatch.fromJson(nodes); jsonNode = patchOperation.apply(jsonNode); } catch (JsonPatchException e) { logger.log(Level.FINEST, "ignore field not found"); } } return jsonNode; }
From source file:io.gs2.identifier.Gs2IdentifierClient.java
/** * GSI?????<br>/*from w ww . j a va 2s. co m*/ * <br> * * @param request * @return ? */ public CreateIdentifierResult createIdentifier(CreateIdentifierRequest request) { ObjectNode body = JsonNodeFactory.instance.objectNode(); HttpPost post = createHttpPost( Gs2Constant.ENDPOINT_HOST + "/user/" + (request.getUserName() == null || request.getUserName().equals("") ? "null" : request.getUserName()) + "/identifier", credential, ENDPOINT, CreateIdentifierRequest.Constant.MODULE, CreateIdentifierRequest.Constant.FUNCTION, body.toString()); if (request.getRequestId() != null) { post.setHeader("X-GS2-REQUEST-ID", request.getRequestId()); } return doRequest(post, CreateIdentifierResult.class); }
From source file:com.nebhale.jsonpath.internal.parser.RecoveringPathParserTest.java
@Test public void wildcardDotChild() { JsonNode nodeStore = NODE.get("store"); ArrayNode expected = JsonNodeFactory.instance.arrayNode(); expected.add(nodeStore.get("book")); expected.add(nodeStore.get("bicycle")); ParserResult result = this.parser.parse("$.store.*"); assertNoProblems(result);//ww w. j a va 2 s .co m assertEquals(expected, result.getPathComponent().get(NODE)); }
From source file:net.sf.taverna.t2.activities.spreadsheet.SpreadsheetUtilsTest.java
/** * Test method for {@link net.sf.taverna.t2.activities.spreadsheet.SpreadsheetUtils#getPortName(java.lang.String, java.util.Map)}. *//* w w w . j a v a 2 s . c o m*/ @Test public void testGetPortNameStringMapOfStringString() { assertEquals("A", SpreadsheetUtils.getPortName("A", null)); assertEquals("AABR", SpreadsheetUtils.getPortName("AABR", null)); ObjectNode configuration = JsonNodeFactory.instance.objectNode(); ArrayNode columnNames = configuration.arrayNode(); columnNames.addObject().put("column", "B").put("port", "beta"); configuration.put("columnNames", columnNames); assertEquals("beta", SpreadsheetUtils.getPortName("B", configuration)); assertEquals("T", SpreadsheetUtils.getPortName("T", configuration)); }
From source file:controllers.impl.proxy.api.Hocon.java
private ObjectNode hoconToJson(final Config hocon) { final ObjectNode resultJson = JsonNodeFactory.instance.objectNode(); for (final Map.Entry<String, ConfigValue> entry : hocon.entrySet()) { resultJson.put(entry.getKey(), entry.getValue().unwrapped().toString()); }/*from w w w.ja v a 2s . c o m*/ return resultJson; }
From source file:com.turn.shapeshifter.AutoParserTest.java
@Test public void testParseWithEmptyRepeated() throws Exception { Actor actor = Actor.newBuilder().setName("James Dean").build(); ObjectNode json = (ObjectNode) new AutoSerializer(Actor.getDescriptor()).serialize(actor, ReadableSchemaRegistry.EMPTY); json.put("quotes", new ArrayNode(JsonNodeFactory.instance)); Message parsedMessage = new AutoParser(Actor.getDescriptor()).parse(json, ReadableSchemaRegistry.EMPTY); Actor parsedActor = Actor.newBuilder().mergeFrom(parsedMessage).build(); Assert.assertEquals("James Dean", parsedActor.getName()); Assert.assertEquals(0, parsedActor.getQuotesCount()); }
From source file:io.fabric8.profiles.ProfilesHelpers.java
public static JsonNode merge(JsonNode target, JsonNode source) { if (target == null) { return source; }/* ww w . j a v a 2 s .c o m*/ if (target.isArray() && source.isArray()) { // we append values from the source. ArrayNode copy = (ArrayNode) target.deepCopy(); for (JsonNode n : source) { if ((n.isTextual() && DELETED.equals(n.textValue()))) { copy = JsonNodeFactory.instance.arrayNode(); } else { copy.add(n); } } return copy; } else if (target.isObject() && source.isObject()) { ObjectNode copy = (ObjectNode) target.deepCopy(); if (source.get(DELETED) != null) { copy = JsonNodeFactory.instance.objectNode(); } else { Iterator<String> iterator = source.fieldNames(); while (iterator.hasNext()) { String key = iterator.next(); if (!DELETED.equals(key)) { JsonNode value = source.get(key); if ((value.isTextual() && DELETED.equals(value.textValue()))) { copy.remove(key); } else { JsonNode original = target.get(key); value = merge(original, value); copy.set(key, value); } } } } return copy; } else { return source; } }
From source file:org.eel.kitchen.jsonschema.other.FatalErrorTests.java
@Test(invocationCount = 10, threadPoolSize = 4) public void keywordBuildFailureRaisesFatalError() { // Build a bundle with only the failing validator final KeywordBundle bundle = new KeywordBundle(); final Keyword foo = Keyword.withName("foo").withValidatorClass(Foo.class).build(); bundle.registerKeyword(foo);//from w w w .j a v a2 s . com // Build a new factory with that only keyword final JsonSchemaFactory factory = new JsonSchemaFactory.Builder().withKeywordBundle(bundle).build(); // Create our schema, which will also be our data, we don't care final JsonNode node = JsonNodeFactory.instance.objectNode().put("foo", "bar"); final JsonSchema schema = factory.fromSchema(node); final ValidationReport report = schema.validate(node); assertTrue(report.hasFatalError()); }
From source file:controllers.MetaController.java
private static void put(final ObjectNode node, final String remaining, final ConfigValue value) { final int dotIndex = remaining.indexOf('.'); final boolean leaf = dotIndex == -1; if (leaf) {/*from w w w .jav a2 s.co m*/ node.set(remaining, getConfigNode(value.unwrapped())); } else { final String firstChunk = remaining.substring(0, dotIndex); ObjectNode child = (ObjectNode) node.get(firstChunk); if (child == null || child.isNull()) { child = JsonNodeFactory.instance.objectNode(); node.set(firstChunk, child); } put(child, remaining.substring(dotIndex + 1), value); } }