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.usergrid.android.sdk.utils.JsonUtils.java
public static void setLongProperty(Map<String, JsonNode> properties, String name, Long value) { if (value == null) { properties.remove(name);//from ww w .ja v a 2s . com } else { properties.put(name, JsonNodeFactory.instance.numberNode(value)); } }
From source file:com.github.pjungermann.config.types.json.JsonConverterTest.java
@Test public void from_hierarchicalJsonObject_convertToConfig() { ObjectNode level2 = new ObjectNode(JsonNodeFactory.instance); level2.set("an", new TextNode("entry")); ObjectNode level1 = new ObjectNode(JsonNodeFactory.instance); level1.set("level_2", level2); level1.set("another", new TextNode("value")); ArrayNode arrayNode = new ArrayNode(JsonNodeFactory.instance); arrayNode.add(1);/*from ww w . j a v a2 s . c om*/ arrayNode.add(2); arrayNode.add(3); ObjectNode json = new ObjectNode(JsonNodeFactory.instance); json.set("level_1", level1); json.set("boolean_true", BooleanNode.getTrue()); json.set("boolean_false", BooleanNode.getFalse()); json.set("number", new IntNode(123456)); json.set("string", new TextNode("string value")); json.set("list", arrayNode); Config config = converter.from(json); assertEquals(true, config.get("boolean_true")); assertEquals(false, config.get("boolean_false")); assertEquals(123456, config.get("number")); assertEquals("string value", config.get("string")); assertEquals("entry", config.get("level_1.level_2.an")); assertEquals("value", config.get("level_1.another")); List list = (List) config.get("list"); assertEquals(1, list.get(0)); assertEquals(2, list.get(1)); assertEquals(3, list.get(2)); }
From source file:com.hengyi.japp.print.server.rest.JappExceptionMapper.java
private void getError(ArrayNode arrayErrors, Throwable exception) { if (exception == null) { return;/*from w w w . j a v a 2 s . co m*/ } if (exception instanceof AppException) { AppException appException = (AppException) exception; ObjectNode error = JsonNodeFactory.instance.objectNode().put("errorCode", appException.getErrorCode()); arrayErrors.add(error); } else if (exception instanceof AppMultiException) { AppMultiException appMultiException = (AppMultiException) exception; appMultiException.getAppExceptions().forEach( o -> arrayErrors.add(JsonNodeFactory.instance.objectNode().put("errorCode", o.getErrorCode()))); } else if (StringUtils.isNotBlank(exception.getMessage())) { arrayErrors.add(JsonNodeFactory.instance.objectNode().put("errorMsg", exception.getMessage())); } getError(arrayErrors, exception.getCause()); }
From source file:com.chenchengzhi.windtalkers.core.Issue.java
public ObjectNode translate() { ObjectNode errorsNode = new ObjectNode(JsonNodeFactory.instance); errorsNode.put("statusCode", statusCode.getDescription()); if (className != null) { errorsNode.put("className", className); errorsNode.put("methodName", methodName); errorsNode.put("reason", reason); }//from w w w . j a v a2s.c o m return errorsNode; }
From source file:com.nebhale.jsonpath.internal.component.IndexPathComponent.java
@Override protected JsonNode select(JsonNode input) { if (this.indexes.length == 1) { return input.get(this.indexes[0]); } else {//from ww w . j av a 2s . c o m ArrayNode result = JsonNodeFactory.instance.arrayNode(); for (int index : this.indexes) { result.add(input.get(index)); } return result; } }
From source file:org.apache.solr.kelvin.ScorerLoader.java
@Override protected void addDefaults() { if (resources.size() == 0) { resources.add(new MissingResultScorer()); resources.add(new TestScorer()); resources.add(new SimpleScorer()); resources.add(new EventCollectorScorer()); resources.add(new MissingFieldScorer()); JsonNode emptyConfig = JsonNodeFactory.instance.objectNode(); for (IConfigurable r : resources) { try { r.configure(emptyConfig); } catch (Exception e) { e.printStackTrace();//w w w . java2 s .com } } } }
From source file:com.nebhale.jsonpath.internal.component.WildcardPathComponentTest.java
@Test public void selectWildcardObject() { JsonNode nodeStore = NODE.get("store"); ArrayNode expected = JsonNodeFactory.instance.arrayNode(); expected.add(nodeStore.get("book")); expected.add(nodeStore.get("bicycle")); JsonNode result = new WildcardPathComponent(null).select(nodeStore); assertEquals(expected, result);//from w ww.j a v a 2 s .c o m }
From source file:net.mostlyharmless.jghservice.connector.github.GithubIssue.java
public JsonNode getJson() { JsonNodeFactory factory = JsonNodeFactory.instance; ObjectNode newNode = factory.objectNode(); return null; }
From source file:io.sidecar.event.EventWithIdsJsonValidationTest.java
@BeforeMethod public void loadValidEventJsonAsString() throws Exception { String validEvent = IOUtils.toString(this.getClass().getResource("/proposed_event.json")); ObjectNode eventAsJson = (ObjectNode) mapper.readTree(validEvent); eventUnderTest = mapper.readValue(eventAsJson.traverse(), Event.class); eventWithAppIdAsJson = JsonNodeFactory.instance.objectNode(); eventWithAppIdAsJson.set("event", eventAsJson); eventWithAppIdAsJson.put("appId", appIdUnderTest.toString()); eventWithAppIdAsJson.put("orgId", appIdUnderTest.toString()); eventWithAppIdAsJson.put("userId", appIdUnderTest.toString()); }
From source file:controllers.MetaController.java
private static JsonNode getConfigNode(final Object element) { if (element instanceof Configuration) { final Configuration config = (Configuration) element; final ObjectNode node = JsonNodeFactory.instance.objectNode(); for (final Map.Entry<String, ConfigValue> entry : config.entrySet()) { put(node, entry.getKey(), entry.getValue()); }/*from w w w .j a v a 2 s .co m*/ return node; } else if (element instanceof String) { final String config = (String) element; return JsonNodeFactory.instance.textNode(config); } else if (element instanceof Integer) { final Integer integer = (Integer) element; return JsonNodeFactory.instance.numberNode(integer); } else if (element instanceof Double) { final Double d = (Double) element; return JsonNodeFactory.instance.numberNode(d); } else if (element instanceof ArrayList) { final ArrayNode arr = JsonNodeFactory.instance.arrayNode(); @SuppressWarnings("unchecked") final ArrayList<Object> list = (ArrayList<Object>) element; for (final Object o : list) { arr.add(getConfigNode(o)); } return arr; } return JsonNodeFactory.instance.textNode("UNKNOWN TYPE: " + element.getClass().getCanonicalName()); }