com.fasterxml.jackson.databind.node.TextNode.valueOf()方法的使用及代码示例

x33g5p2x  于2022-01-29 转载在 其他  
字(11.0k)|赞(0)|评价(0)|浏览(115)

本文整理了Java中com.fasterxml.jackson.databind.node.TextNode.valueOf()方法的一些代码示例,展示了TextNode.valueOf()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。TextNode.valueOf()方法的具体详情如下:
包路径:com.fasterxml.jackson.databind.node.TextNode
类名称:TextNode
方法名:valueOf

TextNode.valueOf介绍

[英]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.
[中]应用于构造实例的工厂方法。对于一些常见的情况,可以重用规范实例:目前空字符串就是这种情况,将来也可能是其他情况。如果传递null,则将返回null。

代码示例

代码示例来源:origin: redisson/redisson

/**
 * Factory method for constructing a node that represents JSON
 * String value
 */
@Override
public TextNode textNode(String text) { return TextNode.valueOf(text); }

代码示例来源:origin: aws/aws-sdk-java

/**
 * If an explicit null is set we preserve that in a {@link NullNode} so that we
 * can serialize an explicit JSON null instead of ommitting that field from the JSON object.
 *
 * @return NullNode if path is null, otherwise a TextNode containing the value.
 */
private JsonNode resolvePath(String pathString) {
  if (pathString == null) {
    return NullNode.getInstance();
  }
  return TextNode.valueOf(pathString);
}

代码示例来源:origin: stagemonitor/stagemonitor

private JsonNode merge(JsonNode source, JsonNode replacement) throws IOException {
  JsonNode replacementNodeEncoded = replacement.get(fieldName);
  if (replacementNodeEncoded != null) {
    ObjectNode decodedSource = tryDecode(source.get(fieldName), mapper.createObjectNode(), fieldName);
    decodedSource.setAll(tryDecode(replacement.get(fieldName), mapper.createObjectNode(), fieldName));
    return TextNode.valueOf(mapper.writeValueAsString(decodedSource));
  } else {
    return source.get(fieldName);
  }
}

代码示例来源:origin: apache/avro

/**
 * Set name-value pair properties for this type or field.
 */
public final S prop(String name, String val) {
 return prop(name, TextNode.valueOf(val));
}

代码示例来源:origin: stagemonitor/stagemonitor

private JsonNode merge(JsonNode source, JsonNode replacement) throws IOException {
  JsonNode replacementNodeEncoded = replacement.get(fieldName);
  if (replacementNodeEncoded != null) {
    HashMap<String, JsonNode> result = new HashMap<String, JsonNode>();
    result.putAll(groupArrayElementsByKey(tryDecode(source.get(fieldName), mapper.createArrayNode(), fieldName), key));
    result.putAll(groupArrayElementsByKey(tryDecode(replacement.get(fieldName), mapper.createArrayNode(), fieldName), key));
    return TextNode.valueOf(mapper.writeValueAsString(result.values()));
  } else {
    return source.get(fieldName);
  }
}

代码示例来源:origin: apache/avro

/**
 * Adds a property with the given name <tt>name</tt> and
 * value <tt>value</tt>. Neither <tt>name</tt> nor <tt>value</tt> can be
 * <tt>null</tt>. It is illegal to add a property if another with
 * the same name but different value already exists in this schema.
 *
 * @param name The name of the property to add
 * @param value The value for the property to add
 */
public void addProp(String name, String value) {
 addProp(name, TextNode.valueOf(value));
}
public void addProp(String name, Object value) {

代码示例来源:origin: apache/avro

JsonProperties(Set<String> reserved, Map<String,?> propMap) {
 this.reserved = reserved;
 for (Entry<String, ?> a : propMap.entrySet()) {
  Object v = a.getValue();
  JsonNode json = null;
  if (v instanceof String) {
   json = TextNode.valueOf((String)v);
  } else if (v instanceof JsonNode){
   json = (JsonNode)v;
  } else {
   json = JacksonUtils.toJsonNode(v);
  }
  props.put(a.getKey(), json);
 }
}

代码示例来源:origin: dropwizard/dropwizard

} else {
  final ArrayNode array = (ArrayNode) child;
  array.set(index, TextNode.valueOf(value));
  return;

代码示例来源:origin: stagemonitor/stagemonitor

@Test
public void addFieldMerger_IsUsedForSpecifiedFields() throws Exception {
  // Given
  ObjectNode a = mapper.createObjectNode();
  ObjectNode b = mapper.createObjectNode();
  a.put("a", "source");
  a.put("b", "source");
  b.put("a", "replacement");
  b.put("b", "replacement");
  // When
  JsonNode result = JsonMerger.merge(a, b,
      mergeStrategy().addFieldMerger("b", (source, replacement, fieldName) -> source.get(fieldName)));
  // Then
  assertThat(result).hasSize(2);
  assertThat(result.get("a")).isEqualTo(TextNode.valueOf("replacement"));
  assertThat(result.get("b")).isEqualTo(TextNode.valueOf("source"));
}

代码示例来源:origin: stagemonitor/stagemonitor

@Test
public void mergeDefinitions_ReplacesKeysFromSourceWithReplacement() throws Exception {
  // Given
  ObjectNode a = mapper.createObjectNode();
  ObjectNode b = mapper.createObjectNode();
  a.put("a", "a");
  b.put("a", "b");
  // When
  JsonNode result = JsonMerger.merge(a, b, mergeStrategy());
  // Then
  assertThat(result).hasSize(1);
  assertThat(result.get("a")).isEqualTo(TextNode.valueOf("b"));
}

代码示例来源:origin: stagemonitor/stagemonitor

@Test
public void defaultMerger_IsUsedForAllFields() throws Exception {
  // Given
  ObjectNode a = mapper.createObjectNode();
  ObjectNode b = mapper.createObjectNode();
  a.put("a", "a");
  b.put("a", "b");
  // When
  JsonNode result = JsonMerger.merge(a, b,
      mergeStrategy().defaultMerger((source, replacement, fieldName) -> source.get(fieldName)));
  // Then
  assertThat(result).hasSize(1);
  assertThat(result.get("a")).isEqualTo(TextNode.valueOf("a"));
}

代码示例来源:origin: stagemonitor/stagemonitor

@Test
public void mergeDefinitions_AddsKeyFromReplacementToSource() throws Exception {
  // Given
  ObjectNode a = mapper.createObjectNode();
  ObjectNode b = mapper.createObjectNode();
  a.put("a", "a");
  b.put("b", "b");
  // When
  JsonNode resultWithEmptyMergeStrategy = JsonMerger.merge(a, b, mergeStrategy());
  JsonNode resultWithoutOptions = JsonMerger.merge(a, b);
  // Then
  assertThat(resultWithEmptyMergeStrategy).isEqualTo(resultWithoutOptions);
  assertThat(resultWithEmptyMergeStrategy).hasSize(2);
  assertThat(resultWithEmptyMergeStrategy.get("a")).isEqualTo(TextNode.valueOf("a"));
  assertThat(resultWithEmptyMergeStrategy.get("b")).isEqualTo(TextNode.valueOf("b"));
}

代码示例来源:origin: spotify/helios

/**
 * Verify that the Helios master generates and returns a hash if the submitted job creation
 * request does not include one.
 */
@Test
public void testHashLessJobCreation() throws Exception {
 startDefaultMaster();
 final Job job = Job.newBuilder()
   .setName(testJobName)
   .setVersion(testJobVersion)
   .setImage(BUSYBOX)
   .setCommand(IDLE_COMMAND)
   .setCreatingUser(TEST_USER)
   .build();
 // Remove the hash from the id in the json serialized job
 final ObjectNode json = (ObjectNode) Json.reader().readTree(Json.asString(job));
 json.set("id", TextNode.valueOf(testJobName + ":" + testJobVersion));
 final HttpURLConnection req = post("/jobs?user=" + TEST_USER,
   Json.asBytes(json));
 assertEquals(req.getResponseCode(), 200);
 final CreateJobResponse res = Json.read(toByteArray(req.getInputStream()),
   CreateJobResponse.class);
 assertEquals(OK, res.getStatus());
 assertTrue(res.getErrors().isEmpty());
 assertEquals(job.getId().toString(), res.getId());
}

代码示例来源:origin: apache/avro

@Test
public void testToJsonNode() {
 assertEquals(null, toJsonNode(null));
 assertEquals(NullNode.getInstance(), toJsonNode(JsonProperties.NULL_VALUE));
 assertEquals(BooleanNode.TRUE, toJsonNode(true));
 assertEquals(IntNode.valueOf(1), toJsonNode(1));
 assertEquals(LongNode.valueOf(2), toJsonNode(2L));
 assertEquals(FloatNode.valueOf(1.0f), toJsonNode(1.0f));
 assertEquals(DoubleNode.valueOf(2.0), toJsonNode(2.0));
 assertEquals(TextNode.valueOf("\u0001\u0002"), toJsonNode(new byte[] { 1, 2 }));
 assertEquals(TextNode.valueOf("a"), toJsonNode("a"));
 assertEquals(TextNode.valueOf("UP"), toJsonNode(Direction.UP));
 ArrayNode an = JsonNodeFactory.instance.arrayNode();
 an.add(1);
 assertEquals(an, toJsonNode(Collections.singletonList(1)));
 ObjectNode on = JsonNodeFactory.instance.objectNode();
 on.put("a", 1);
 assertEquals(on, toJsonNode(Collections.singletonMap("a", 1)));
}

代码示例来源:origin: apache/avro

@Test
public void testToObject() {
 assertEquals(null, toObject(null));
 assertEquals(JsonProperties.NULL_VALUE, toObject(NullNode.getInstance()));
 assertEquals(true, toObject(BooleanNode.TRUE));
 assertEquals(1, toObject(IntNode.valueOf(1)));
 assertEquals(2L, toObject(IntNode.valueOf(2), Schema.create(Schema.Type.LONG)));
 assertEquals(1.0f, toObject(DoubleNode.valueOf(1.0), Schema.create(Schema.Type.FLOAT)));
 assertEquals(2.0, toObject(DoubleNode.valueOf(2.0)));
 assertEquals(TextNode.valueOf("\u0001\u0002"), toJsonNode(new byte[]{1, 2}));
 assertArrayEquals(new byte[]{1, 2},
   (byte[]) toObject(TextNode.valueOf("\u0001\u0002"), Schema.create(Schema.Type.BYTES)));
 assertEquals("a", toObject(TextNode.valueOf("a")));
 assertEquals("UP", toObject(TextNode.valueOf("UP"),
   SchemaBuilder.enumeration("Direction").symbols("UP", "DOWN")));
 ArrayNode an = JsonNodeFactory.instance.arrayNode();
 an.add(1);
 assertEquals(Collections.singletonList(1), toObject(an));
 ObjectNode on = JsonNodeFactory.instance.objectNode();
 on.put("a", 1);
 assertEquals(Collections.singletonMap("a", 1), toObject(on));
 assertEquals(Collections.singletonMap("a", 1L), toObject(on,
   SchemaBuilder.record("r").fields().requiredLong("a").endRecord()));
 assertEquals(JsonProperties.NULL_VALUE, toObject(NullNode.getInstance(),
   SchemaBuilder.unionOf().nullType().and().intType().endUnion()));
 assertEquals("a", toObject(TextNode.valueOf("a"),
   SchemaBuilder.unionOf().stringType().and().intType().endUnion()));
}

代码示例来源:origin: spring-projects/spring-integration

@Test
public void testSplitterAggregator() {
  List<String> payload = Arrays.asList("a", "b", "c", "d", "e");
  QueueChannel replyChannel = new QueueChannel();
  this.splitAggregateInput.send(MessageBuilder.withPayload(payload)
      .setReplyChannel(replyChannel)
      .build());
  Message<?> receive = replyChannel.receive(2000);
  assertNotNull(receive);
  assertThat(receive.getPayload(), instanceOf(List.class));
  @SuppressWarnings("unchecked")
  List<Object> result = (List<Object>) receive.getPayload();
  for (int i = 0; i < payload.size(); i++) {
    assertThat(result.get(i), instanceOf(TextNode.class));
    assertEquals(TextNode.valueOf(payload.get(i)), result.get(i));
  }
}

代码示例来源:origin: rakam-io/rakam

return value.getBOOL() ? BooleanNode.TRUE : BooleanNode.FALSE;
} else if (value.getS() != null) {
  return TextNode.valueOf(value.getS());
} else if (value.getN() != null) {
  double v = Double.parseDouble(value.getN());

代码示例来源:origin: com.jwebmp.jackson.core/jackson-databind

/**
 * Factory method for constructing a node that represents JSON
 * String value
 */
@Override
public TextNode textNode(String text) { return TextNode.valueOf(text); }

代码示例来源:origin: com.palantir.config.crypto/encrypted-config-value-module

@Override
  public JsonNode visitText(TextNode textNode) {
    return TextNode.valueOf(substitutor.replace(textNode.textValue()));
  }
}

代码示例来源:origin: org.apache.isis.core/isis-core-viewer-restfulobjects-rendering

@Before
public void setUp() throws Exception {
  mockObjectSpec = context.mock(ObjectSpecification.class);
  mockEncodableFacet = context.mock(EncodableFacet.class);
  mockObjectAdapter = context.mock(ObjectAdapter.class);
  mockAdapterManager = context.mock(AdapterManager.class);
  JsonValueEncoder.testSetAdapterManager(mockAdapterManager);
  representation = new JsonRepresentation(TextNode.valueOf("aString"));
}

相关文章