List of usage examples for com.fasterxml.jackson.databind.node TextNode TextNode
public TextNode(String paramString)
From source file:com.mapr.synth.samplers.UUIDSampler.java
@Override public JsonNode sample() { int a = rand.nextInt(); int b = rand.nextInt(1 << 16); int c = 0x4000 + rand.nextInt(1 << 12); int d = 0x8000 + rand.nextInt(1 << 14); long e = rand.nextLong() & ((1L << 48) - 1); return new TextNode(String.format("%08x-%04x-%04x-%04x-%012x", a, b, c, d, e)); }
From source file:es.bsc.amon.util.tree.TreeNodeFactory.java
public static JsonNode toJson(TreeNode n) { JsonNode json = null;// w ww . j a v a 2s .c o m if (n instanceof ObjNode) { json = new ObjectNode(JsonNodeFactory.instance); for (Map.Entry<String, TreeNode> e : ((ObjNode) n).properties.entrySet()) { ((ObjectNode) json).put(e.getKey(), toJson(e.getValue())); } } else if (n instanceof NodeArray) { json = new ArrayNode(JsonNodeFactory.instance); for (TreeNode ne : ((NodeArray) n).elements) { ((ArrayNode) json).add(toJson(ne)); } } else if (n instanceof StringValue) { json = new TextNode(((StringValue) n).value); } else if (n instanceof NumberValue) { Number val = ((NumberValue) n).value; if (val instanceof Byte || val instanceof Short || val instanceof Integer || val instanceof Long) { json = new LongNode(val.longValue()); } else { json = new DoubleNode(val.doubleValue()); } } else throw new RuntimeException("You should not reach this"); return json; }
From source file:com.aol.one.patch.DefaultPatcherPatchableMapTest.java
@Test public void testPatchableReplaceValue() throws PatchException { PatchOperation operation = new ReplaceOperation("/replacedValue", new TextNode("300")); Patcher patcher = PatcherFactory.getDefaultPatcher(); patchableMap.put("replacedValue", "200"); assertThat(patchableMap.get("replacedValue"), is("200")); patcher.patch(patchableMap, operation); assertThat(patchableMap.get("replacedValue"), is("300")); }
From source file:com.github.restdriver.matchers.HasJsonArrayTest.java
@Test public void matcherShouldFailWhenNodeDoesntContainFieldWithGivenName() { assertThat(matcher.matches(object("foo", new TextNode("bar"))), is(false)); }
From source file:com.redhat.lightblue.util.JsonNodeCursorTest.java
@Test public void illegalRoot() throws IOException { try {//w w w . j av a 2s . co m TextNode node = new TextNode("value"); new JsonNodeCursor(new Path(""), node); Assert.fail("Expected IllegalArgumentException with TextNode as root element"); } catch (IllegalArgumentException e) { // expected } }
From source file:com.aol.one.patch.DefaultPatcherPatchableListTest.java
@Test public void testPatchableReplaceValue() throws PatchException { PatchOperation operation = new ReplaceOperation("/replacedValue", new TextNode("300")); Patcher patcher = PatcherFactory.getDefaultPatcher(); // TODO: update }
From source file:com.turn.shapeshifter.transformers.DateTimeTransformer.java
/** * @param object the number of milliseconds since the Unix epoch *//* w w w. j a va 2 s .co m*/ @Override public JsonNode serialize(Object object) { if (object == null) { return NullNode.instance; } Preconditions.checkArgument(object instanceof Long); Long millis = (Long) object; return new TextNode(ISO_8601.print(millis)); }
From source file:com.mapr.synth.samplers.JoinSampler.java
@Override public JsonNode sample() { JsonNode value = delegate.sample();// ww w . j a v a 2s. c o m StringBuilder r = new StringBuilder(); String separator = ""; for (JsonNode component : value) { r.append(separator); r.append(component.asText()); separator = this.separator; } return new TextNode(r.toString()); }
From source file:com.github.restdriver.matchers.HasJsonArrayTest.java
@Test public void matcherShouldFailWhenAskedToMatchNonArrayNode() { assertThat(matcher.matches(object("array", new TextNode("foo"))), is(false)); }
From source file:io.coala.time.ReplicateConfig.java
default <T> T id(final Class<T> idType) { // assumes the id() should be parsed as a JSON text value: "..." return JsonUtil.valueOf(new TextNode(rawId()), idType); }