/** * Factory method that should be used to construct instances. * For some common cases, can reuse canonical instances: currently * this is the case for empty Strings, in future possible for * others as well. If null is passed, will return null. * * @return Resulting {@link TextNode} object, if <b>v</b> * is NOT null; null if it is. */ public static TextNode valueOf(String v) { if (v == null) { return null; } if (v.length() == 0) { return EMPTY_STRING_NODE; } return new TextNode(v); }
@Override protected JsonNode getCurrentChild() { assert currentChild != null; if (lhs) { return new TextNode(currentChild.getKey()); } return currentChild.getValue(); }
private void addLambdaCodeURI(JsonNode resources) { for (Entry<String, File> function : lambdaFunctions.entrySet()) { TextNode codeUri = new TextNode(function.getValue().getAbsolutePath()); ObjectNode apiProperties = (ObjectNode) resources.get(function.getKey()).get("Properties"); apiProperties.set("CodeUri", codeUri); } }
private ObjectNode data(String exceptionTypeName, String... keyValuePairs) { ObjectNode data = mapper.createObjectNode(); if (exceptionTypeName != null) data.set(JsonRpcBasicServer.EXCEPTION_TYPE_NAME, new TextNode(exceptionTypeName)); for (String pair : keyValuePairs) { String[] parts = pair.split("="); data.set(parts[0], new TextNode(parts[1])); } return data; } }
dataObject.set( JsonRpcBasicServer.ERROR_MESSAGE, new TextNode(error.get(JsonRpcBasicServer.ERROR_MESSAGE).asText()));
@Test public void shouldGetClaims() throws Exception { Map<String, JsonNode> tree = new HashMap<>(); tree.put("extraClaim", new TextNode("extraValue")); tree.put("sub", new TextNode("auth0")); PayloadImpl payload = new PayloadImpl(null, null, null, null, null, null, null, tree, objectReader); assertThat(payload, is(notNullValue())); Map<String, Claim> claims = payload.getClaims(); assertThat(claims, is(notNullValue())); assertThat(claims.get("extraClaim"), is(notNullValue())); assertThat(claims.get("sub"), is(notNullValue())); }
private ObjectNode error(Integer code, String message, ObjectNode data) { ObjectNode error = mapper.createObjectNode(); if (code != null) error.set(JsonRpcBasicServer.ERROR_CODE, new IntNode(code)); if (message != null) error.set(JsonRpcBasicServer.ERROR_MESSAGE, new TextNode(message)); if (data != null) error.set(JsonRpcBasicServer.DATA, data); return error; }
@Before public void setUp() throws Exception { mapper = getDefaultObjectMapper(); objectReader = mapper.reader(); expiresAt = Mockito.mock(Date.class); notBefore = Mockito.mock(Date.class); issuedAt = Mockito.mock(Date.class); Map<String, JsonNode> tree = new HashMap<>(); tree.put("extraClaim", new TextNode("extraValue")); payload = new PayloadImpl("issuer", "subject", Collections.singletonList("audience"), expiresAt, notBefore, issuedAt, "jwtId", tree, objectReader); }
@Test public void shouldGetExtraClaim() throws Exception { Map<String, JsonNode> tree = new HashMap<>(); tree.put("extraClaim", new TextNode("extraValue")); BasicHeader header = new BasicHeader(null, null, null, null, tree, objectReader); assertThat(header, is(notNullValue())); assertThat(header.getHeaderClaim("extraClaim"), is(instanceOf(JsonNodeClaim.class))); assertThat(header.getHeaderClaim("extraClaim").asString(), is("extraValue")); }
@Test public void shouldGetStringWhenParsingTextNode() throws Exception { Map<String, JsonNode> tree = new HashMap<>(); TextNode node = new TextNode("something here"); tree.put("key", node); String text = deserializer.getString(tree, "key"); assertThat(text, is(notNullValue())); assertThat(text, is("something here")); }
@Test public void shouldGetStringWhenParsingTextNode() throws Exception { Map<String, JsonNode> tree = new HashMap<>(); TextNode node = new TextNode("something here"); tree.put("key", node); String text = deserializer.getString(tree, "key"); assertThat(text, is(notNullValue())); assertThat(text, is("something here")); } }
@Test public void shouldGetEmptyStringArrayWhenParsingEmptyTextNode() throws Exception { Map<String, JsonNode> tree = new HashMap<>(); TextNode textNode = new TextNode(""); tree.put("key", textNode); List<String> values = deserializer.getStringOrArray(tree, "key"); assertThat(values, is(notNullValue())); assertThat(values, is(IsEmptyCollection.empty())); }
@Test public void shouldGetStringArrayWhenParsingArrayNode() throws Exception { Map<String, JsonNode> tree = new HashMap<>(); List<JsonNode> subNodes = new ArrayList<>(); TextNode textNode1 = new TextNode("one"); TextNode textNode2 = new TextNode("two"); subNodes.add(textNode1); subNodes.add(textNode2); ArrayNode arrNode = new ArrayNode(JsonNodeFactory.instance, subNodes); tree.put("key", arrNode); List<String> values = deserializer.getStringOrArray(tree, "key"); assertThat(values, is(notNullValue())); assertThat(values, is(IsCollectionWithSize.hasSize(2))); assertThat(values, is(IsCollectionContaining.hasItems("one", "two"))); }
@Test public void shouldGetStringArrayWhenParsingTextNode() throws Exception { Map<String, JsonNode> tree = new HashMap<>(); TextNode textNode = new TextNode("something"); tree.put("key", textNode); List<String> values = deserializer.getStringOrArray(tree, "key"); assertThat(values, is(notNullValue())); assertThat(values, is(IsCollectionWithSize.hasSize(1))); assertThat(values, is(IsCollectionContaining.hasItems("something"))); }
@Test public void shouldThrowWhenParsingNonNumericNode() throws Exception { exception.expect(JWTDecodeException.class); exception.expectMessage("The claim 'key' contained a non-numeric date value."); Map<String, JsonNode> tree = new HashMap<>(); TextNode node = new TextNode("123456789"); tree.put("key", node); deserializer.getDateFromSeconds(tree, "key"); }
@Test public void itReturnsGenericErrorForUnmodeledExceptions() throws Exception { PojoTestException e = new PojoTestException("some value", "another value", new RuntimeException("oh dear!")); JsonError error = resolver.resolveError( e, PojoService.class.getMethod("nonPojoCall", String.class), Arrays.asList(new TextNode("foo"))); JsonNode node = mapper.valueToTree(error); assertThat(node) .hasField("code", JsonError.INTERNAL_ERROR.code) .hasField("message", "some value:another value") .hasNullField("data"); } }
TextNode text = new TextNode("foo", ""); elem.replaceWith(text);
return new DoubleNode(in.readDouble()); case STRING: return new TextNode(in.readString()); case BOOLEAN: return in.readBoolean() ? BooleanNode.TRUE : BooleanNode.FALSE;
case STRING_LITERAL: s = JsonString(); n = new TextNode(s); break; case INTEGER_LITERAL:
@Test public void itPreservesErrorInformationForModeledExceptions() throws Exception { PojoTestException e = new PojoTestException("some value", "another value", new RuntimeException("oh dear!")); JsonError error = resolver.resolveError( e, PojoService.class.getMethod("pojoCall", String.class), Arrays.asList(new TextNode("foo"))); JsonNode node = mapper.valueToTree(error); assertThat(node) .hasField("code", PojoErrorResolver.ERROR_CODE) .hasField("message", "some value:another value"); JsonNode data = node.get("data"); assertThat(data) .hasField(JsonRpcBasicServer.EXCEPTION_TYPE_NAME, PojoTestException.class.getName()) .hasField("someValue", "some value") .hasField("anotherValue", "another value") .hasNoField("cause") .hasNoField("stackTrace") .hasNoField("suppressed") .hasNoField("localisedMessage"); }