本文整理了Java中com.fasterxml.jackson.databind.JsonNode.traverse()
方法的一些代码示例,展示了JsonNode.traverse()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。JsonNode.traverse()
方法的具体详情如下:
包路径:com.fasterxml.jackson.databind.JsonNode
类名称:JsonNode
方法名:traverse
[英]Method for constructing a JsonParser instance for iterating over contents of the tree that this node is root of. Functionally equivalent to first serializing tree using com.fasterxml.jackson.core.ObjectCodec and then re-parsing but more efficient.
[中]方法,该方法用于构造一个JsonParser实例,用于迭代此节点所在树的内容。在功能上等同于使用com的第一个序列化树。fasterxml。杰克逊。果心ObjectCodec,然后重新解析,但效率更高。
代码示例来源:origin: spring-projects/spring-security
@Override
public Set deserialize(JsonParser jp, DeserializationContext ctxt) throws IOException, JsonProcessingException {
ObjectMapper mapper = (ObjectMapper) jp.getCodec();
JsonNode node = mapper.readTree(jp);
Set<Object> resultSet = new HashSet<>();
if (node != null) {
if (node instanceof ArrayNode) {
ArrayNode arrayNode = (ArrayNode) node;
Iterator<JsonNode> nodeIterator = arrayNode.iterator();
while (nodeIterator.hasNext()) {
JsonNode elementNode = nodeIterator.next();
resultSet.add(mapper.readValue(elementNode.traverse(mapper), Object.class));
}
} else {
resultSet.add(mapper.readValue(node.traverse(mapper), Object.class));
}
}
return Collections.unmodifiableSet(resultSet);
}
}
代码示例来源:origin: embulk/embulk
@Override
public <E> E get(Class<E> type, String attrName, E defaultValue) {
JsonNode json = data.get(attrName);
if (json == null) {
return defaultValue;
}
return model.readObject(type, json.traverse());
}
代码示例来源:origin: spring-projects/spring-security
@Override
public List deserialize(JsonParser jp, DeserializationContext ctxt) throws IOException, JsonProcessingException {
ObjectMapper mapper = (ObjectMapper) jp.getCodec();
JsonNode node = mapper.readTree(jp);
List<Object> result = new ArrayList<Object>();
if (node != null) {
if (node instanceof ArrayNode) {
ArrayNode arrayNode = (ArrayNode) node;
Iterator<JsonNode> nodeIterator = arrayNode.iterator();
while (nodeIterator.hasNext()) {
JsonNode elementNode = nodeIterator.next();
result.add(mapper.readValue(elementNode.traverse(mapper), Object.class));
}
} else {
result.add(mapper.readValue(node.traverse(mapper), Object.class));
}
}
return Collections.unmodifiableList(result);
}
}
代码示例来源:origin: stackoverflow.com
public class App {
public static class Foo {
public int foo;
}
public static void main(String[] args) {
String json = "{\"someArray\":[{\"foo\":5},{\"foo\":6},{\"foo\":7}]}";
ObjectMapper mapper = new ObjectMapper();
JsonNode node = mapper.readTree(json);
node = node.get("someArray");
TypeReference<List<Foo>> typeRef = new TypeReference<List<Foo>>(){};
List<Foo> list = mapper.readValue(node.traverse(), typeRef);
for (Foo f : list) {
System.out.println(f.foo);
}
}
}
代码示例来源:origin: org.springframework.security/spring-security-core
@Override
public List deserialize(JsonParser jp, DeserializationContext ctxt) throws IOException, JsonProcessingException {
ObjectMapper mapper = (ObjectMapper) jp.getCodec();
JsonNode node = mapper.readTree(jp);
List<Object> result = new ArrayList<Object>();
if (node != null) {
if (node instanceof ArrayNode) {
ArrayNode arrayNode = (ArrayNode) node;
Iterator<JsonNode> nodeIterator = arrayNode.iterator();
while (nodeIterator.hasNext()) {
JsonNode elementNode = nodeIterator.next();
result.add(mapper.readValue(elementNode.traverse(mapper), Object.class));
}
} else {
result.add(mapper.readValue(node.traverse(mapper), Object.class));
}
}
return Collections.unmodifiableList(result);
}
}
代码示例来源:origin: stagemonitor/stagemonitor
@Override
public void reload() throws IOException {
final JsonNode json = elasticsearchClient.getJson(path, true);
if (json != null) {
final JsonNode source = json.get("_source").get("configuration");
List<EsConfigurationDto> configAsList = JsonUtils.getMapper().readValue(source.traverse(), new TypeReference<List<EsConfigurationDto>>() {
});
configuration = EsConfigurationDto.toMap(configAsList);
}
}
代码示例来源:origin: org.springframework.security/spring-security-core
@Override
public Set deserialize(JsonParser jp, DeserializationContext ctxt) throws IOException, JsonProcessingException {
ObjectMapper mapper = (ObjectMapper) jp.getCodec();
JsonNode node = mapper.readTree(jp);
Set<Object> resultSet = new HashSet<>();
if (node != null) {
if (node instanceof ArrayNode) {
ArrayNode arrayNode = (ArrayNode) node;
Iterator<JsonNode> nodeIterator = arrayNode.iterator();
while (nodeIterator.hasNext()) {
JsonNode elementNode = nodeIterator.next();
resultSet.add(mapper.readValue(elementNode.traverse(mapper), Object.class));
}
} else {
resultSet.add(mapper.readValue(node.traverse(mapper), Object.class));
}
}
return Collections.unmodifiableSet(resultSet);
}
}
代码示例来源:origin: embulk/embulk
@Override
public <E> E get(Class<E> type, String attrName) {
JsonNode json = data.get(attrName);
if (json == null) {
throw new ConfigException("Attribute " + attrName + " is required but not set");
}
return model.readObject(type, json.traverse());
}
代码示例来源:origin: spring-projects/spring-security
Object principal = null;
if (principalNode.isObject()) {
principal = mapper.readValue(principalNode.traverse(mapper), Object.class);
} else {
principal = principalNode.asText();
readJsonNode(jsonNode, "authorities").traverse(mapper), new TypeReference<List<GrantedAuthority>>() {
});
if (authenticated) {
代码示例来源:origin: org.springframework.security/spring-security-core
Object principal = null;
if (principalNode.isObject()) {
principal = mapper.readValue(principalNode.traverse(mapper), Object.class);
} else {
principal = principalNode.asText();
readJsonNode(jsonNode, "authorities").traverse(mapper), new TypeReference<List<GrantedAuthority>>() {
});
if (authenticated) {
代码示例来源:origin: stackoverflow.com
JsonParser parser = node.traverse();
ObjectMapper mapper = new ObjectMapper();
return mapper.readValue(parser, wrappedType);
代码示例来源:origin: BroadleafCommerce/BroadleafCommerce
dataDTO.setRules((ArrayList<DataDTO>) mapper.readValue(element.getValue().traverse(jp.getCodec()), dtoCollectionType));
代码示例来源:origin: opentripplanner/OpenTripPlanner
@SuppressWarnings("unchecked")
public static PointFeature fromJsonNode(JsonNode feature) throws EmptyPolygonException,
UnsupportedGeometryException {
Feature geoJsonFeature;
try {
geoJsonFeature = deserializer.readValue(feature.traverse(), Feature.class);
} catch (IOException e) {
throw new UnsupportedGeometryException(e.getMessage());
}
PointFeature ret = new PointFeature(geoJsonFeature.getId());
ret.setGeom(GeometryUtils.convertGeoJsonToJtsGeometry(geoJsonFeature.getGeometry()));
Object structured = geoJsonFeature.getProperty("structured");
if (structured == null || !(structured instanceof Map))
return null;
// The code below assume the structured map to have integers only
ret.setAttributes((Map<String, Integer>)(structured));
return ret;
}
代码示例来源:origin: Netflix/hollow
public static void print(JsonNode node) throws Exception {
print(node.traverse());
}
public static void print(JsonParser parser) throws Exception {
代码示例来源:origin: spring-projects/spring-integration
@Override
public T convert(JsonNode root, DeserializationContext ctxt) throws IOException {
Map<String, Object> headers = this.mapper.readValue(root.get("headers").traverse(),
TypeFactory.defaultInstance().constructMapType(HashMap.class, String.class, Object.class));
Object payload = this.mapper.readValue(root.get("payload").traverse(), this.payloadType);
return buildMessage(new MutableMessageHeaders(headers), payload, root, ctxt);
}
代码示例来源:origin: stackoverflow.com
ObjectMapper mapper = new ObjectMapper();
mapper.disable(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES);
JsonNode node = mapper.readTree(new URL(url));
node = node.get("duObjects");
TypeReference<List<Dataset>> typeRef = new TypeReference<List<Dataset>>() {
};
List<Dataset> list = mapper.readValue(node.traverse(), typeRef);
for (int i = 0; i < list.size(); i++) {
Dataset dataSet = list.get(i);
System.out.println(dataSet.getName());
}
代码示例来源:origin: spring-projects/spring-kafka
@Override
public MimeType convert(JsonNode root, DeserializationContext ctxt) throws IOException {
JsonNode type = root.get("type");
JsonNode subType = root.get("subtype");
JsonNode parameters = root.get("parameters");
Map<String, String> params =
DefaultKafkaHeaderMapper.this.objectMapper.readValue(parameters.traverse(),
TypeFactory.defaultInstance()
.constructMapType(HashMap.class, String.class, String.class));
return new MimeType(type.asText(), subType.asText(), params);
}
代码示例来源:origin: spring-projects/spring-data-rest
@Override
public Object evaluate(Class<?> type) {
try {
return mapper.readValue(valueNode.traverse(mapper.getFactory().getCodec()), type);
} catch (Exception o_O) {
throw new PatchException(String.format("Could not read %s into %s!", valueNode, type), o_O);
}
}
}
代码示例来源:origin: spring-projects/spring-integration
@Override
protected AdviceMessage<?> buildMessage(MutableMessageHeaders headers, Object payload, JsonNode root,
DeserializationContext ctxt) throws IOException {
Message<?> inputMessage = getMapper().readValue(root.get("inputMessage").traverse(), Message.class);
return new AdviceMessage<Object>(payload, (MessageHeaders) headers, inputMessage);
}
代码示例来源:origin: spring-projects/spring-integration
@Override
protected ErrorMessage buildMessage(MutableMessageHeaders headers, Object payload, JsonNode root,
DeserializationContext ctxt) throws IOException {
Message<?> originalMessage = getMapper().readValue(root.get("originalMessage").traverse(), Message.class);
return new ErrorMessage((Throwable) payload, headers, originalMessage);
}
内容来源于网络,如有侵权,请联系作者删除!