Java Code Examples for com.fasterxml.jackson.databind.node.TextNode#valueOf()

The following examples show how to use com.fasterxml.jackson.databind.node.TextNode#valueOf() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: DecryptAetIdentifiers.java    From gcp-ingestion with Mozilla Public License 2.0 6 votes vote down vote up
/**
 * Decrypt a payload encoded in a compact serialization of JSON Web Encryption (JWE).
 *
 * <p>The payload may be either a single JWE string or an array of values.
 *
 * <p>Assumes that the payload contains a "kid" parameter that can be used to look up a matching
 * private key.
 */
public static JsonNode decrypt(KeyStore keyStore, JsonNode anonIdNode)
    throws JoseException, KeyNotFoundException {
  if (anonIdNode.isTextual()) {
    String anonId = anonIdNode.textValue();
    JsonWebStructure fromCompact = JsonWebEncryption.fromCompactSerialization(anonId);
    String keyId = fromCompact.getKeyIdHeaderValue();
    PrivateKey key = keyStore.getKeyOrThrow(keyId);
    JsonWebEncryption jwe = new JsonWebEncryption();
    jwe.setKey(key);
    jwe.setContentEncryptionKey(key.getEncoded());
    jwe.setCompactSerialization(anonId);
    return TextNode.valueOf(jwe.getPlaintextString());
  } else if (anonIdNode.isArray()) {
    ArrayNode userIds = Json.createArrayNode();
    for (JsonNode node : anonIdNode) {
      userIds.add(decrypt(keyStore, node));
    }
    return userIds;
  } else {
    throw new IllegalArgumentException(
        "Argument to decrypt must be a TextNode or ArrayNode, but got " + anonIdNode);
  }
}
 
Example 2
Source File: StoredAsJsonTest.java    From Rosetta with Apache License 2.0 6 votes vote down vote up
@Test
public void itHandlesSubTypes() throws JsonProcessingException {
  ConcreteStoredAsJsonList typeInfoBean = new ConcreteStoredAsJsonList();
  typeInfoBean.setInnerBeans(Collections.singletonList(inner));

  TextNode expectedList = TextNode.valueOf("[{\"stringProperty\":\"value\"}]");
  JsonNode node = Rosetta.getMapper().valueToTree(typeInfoBean);
  assertThat(node.get("innerBeans")).isEqualTo(expectedList);

  assertThat(Rosetta.getMapper().treeToValue(node, StoredAsJsonListTypeInfoBean.class)
                 .getInnerBeans()
                 .get(0)
                 .getStringProperty())
      .isEqualTo("value");

  assertThat(Rosetta.getMapper().treeToValue(node, ConcreteStoredAsJsonList.class)
                 .getInnerBeans()
                 .get(0)
                 .getStringProperty())
      .isEqualTo("value");
}
 
Example 3
Source File: JsonNodePiiReplacer.java    From data-highway with Apache License 2.0 5 votes vote down vote up
@Override
public JsonNode apply(JsonNode value) {
  if (value instanceof TextNode) {
    return TextNode.valueOf(replacer.replace(value.asText()));
  } else if (value instanceof BinaryNode) {
    return BinaryNode.valueOf(new byte[0]);
  } else {
    return value;
  }
}
 
Example 4
Source File: DecryptAetIdentifiers.java    From gcp-ingestion with Mozilla Public License 2.0 5 votes vote down vote up
/**
 * Return a redacted value if the given node represents a long string.
 *
 * <p>Strings longer than 32 characters might be ecosystem_anon_id values, so we want to make
 * sure they are not propagated to error output.
 */
private static JsonNode redactedNode(JsonNode node) {
  String value = node.textValue();
  if (value != null && value.length() > 32) {
    return TextNode.valueOf(
        String.format("%s<%d characters redacted>", value.substring(0, 4), value.length() - 4));
  } else {
    return node;
  }
}
 
Example 5
Source File: JacksonScalars.java    From graphql-spqr with Apache License 2.0 5 votes vote down vote up
@Override
public TextNode parseValue(Object input) {
    if (input instanceof String) {
        return TextNode.valueOf((String) input);
    }
    if (input instanceof TextNode) {
        return (TextNode) input;
    }
    throw valueParsingException(input, String.class, TextNode.class);
}
 
Example 6
Source File: JacksonScalars.java    From graphql-spqr with Apache License 2.0 4 votes vote down vote up
@Override
public TextNode parseLiteral(Object input) {
    return TextNode.valueOf(literalOrException(input, StringValue.class).getValue());
}
 
Example 7
Source File: AnnotatedServiceBlockingTest.java    From armeria with Apache License 2.0 4 votes vote down vote up
@Get("/jsonNode")
public JsonNode jsonNode(RequestContext ctx) {
    return TextNode.valueOf("Armeria");
}
 
Example 8
Source File: AnnotatedServiceBlockingTest.java    From armeria with Apache License 2.0 4 votes vote down vote up
@Get("/jsonNode")
@Blocking
public JsonNode jsonNode(RequestContext ctx) {
    return TextNode.valueOf("Armeria");
}
 
Example 9
Source File: Serializer.java    From james-project with Apache License 2.0 4 votes vote down vote up
@Override
public JsonNode serialize(String object) {
    return TextNode.valueOf(object);
}
 
Example 10
Source File: JsonDataModelTree.java    From onos with Apache License 2.0 2 votes vote down vote up
/**
 * Sets text on the specific json pointer.
 *
 * @param ptr  json pointer
 * @param text text to set
 * @throws WorkflowException workflow exception
 */
public void setAt(JsonPointer ptr, String text) throws WorkflowException {
    TextNode textNode = TextNode.valueOf(text);

    attach(ptr, textNode);
}