类com.fasterxml.jackson.databind.node.TreeTraversingParser源码实例Demo

下面列出了怎么用com.fasterxml.jackson.databind.node.TreeTraversingParser的API类实例代码及写法,或者点击链接到github查看源代码。

源代码1 项目: bootique   文件: JsonNodeConfigurationFactory.java
@Override
public <T> T config(TypeRef<? extends T> type, String prefix) {

    JsonNode child = findChild(prefix);

    JavaType jacksonType = typeFactory.constructType(type.getType());

    try {
        return mapper.readValue(new TreeTraversingParser(child, mapper), jacksonType);
    }
    // TODO: implement better exception handling. See ConfigurationFactory
    // in Dropwizard for inspiration
    catch (IOException e) {
        throw new RuntimeException("Error creating config", e);
    }
}
 
源代码2 项目: heroic   文件: FilterRegistry.java
private Filter deserializeObject(final JsonParser p, final DeserializationContext c)
    throws IOException {
    final ObjectNode object = (ObjectNode) p.readValueAs(JsonNode.class);

    final JsonNode typeNode = object.remove("type");

    if (typeNode == null) {
        throw c.mappingException("Expected 'type' field");
    }

    if (!typeNode.isTextual()) {
        throw c.mappingException("Expected 'type' to be string");
    }

    final String type = typeNode.asText();

    final Class<? extends Filter> cls = typeNameMapping.get(type);

    if (cls == null) {
        throw c.mappingException("No such type: " + type);
    }

    // use tree traversing parser to operate on the node (without 'type') again.
    final TreeTraversingParser parser = new TreeTraversingParser(object, p.getCodec());
    return parser.readValueAs(cls);
}
 
@Override
protected Object parse(Resource resource, Class<?> pluginConfigClass)
        throws Exception{
    InputStream input = new FileInputStream(resource.getFile());
    YAMLParser yamlParser = yamlFactory.createParser(input);
    final JsonNode node = objectMapper.readTree(yamlParser);
    if(node == null){
        return pluginConfigClass.newInstance();
    }
    TreeTraversingParser treeTraversingParser = new TreeTraversingParser(node);
    return objectMapper.readValue(treeTraversingParser, pluginConfigClass);
}
 
源代码4 项目: lams   文件: ObjectReader.java
@Override
public JsonParser treeAsTokens(TreeNode n) {
    // 05-Dec-2017, tatu: Important! Must clear "valueToUpdate" since we do not
    //    want update to be applied here, as a side effect
    ObjectReader codec = withValueToUpdate(null);
    return new TreeTraversingParser((JsonNode) n, codec);
}
 
源代码5 项目: bootique   文件: JsonNodeConfigurationFactory.java
@Override
public <T> T config(Class<T> type, String prefix) {

    JsonNode child = findChild(prefix);

    try {
        return mapper.readValue(new TreeTraversingParser(child, mapper), type);
    }
    // TODO: implement better exception handling. See ConfigurationFactory
    // in Dropwizard for inspiration
    catch (IOException e) {
        throw new RuntimeException("Error creating config", e);
    }
}
 
源代码6 项目: bootique   文件: DefaultJacksonServiceIT.java
protected <T> T readValue(Class<T> type, ObjectMapper mapper, String json) throws IOException {
    JsonParser parser = new JsonFactory().createParser(json);
    JsonNode node = mapper.readTree(parser);
    assertNotNull(node);

    return mapper.readValue(new TreeTraversingParser(node), type);
}
 
源代码7 项目: kork   文件: DataContainer.java
@NotNull
public <T> T getOfType(@NotNull String key, Class<T> type) {
  JsonParser parser =
      new TreeTraversingParser(
          objectMapper.valueToTree(data).at(normalizeKey(key)), objectMapper);
  try {
    return objectMapper.readValue(parser, type);
  } catch (IOException e) {
    throw new KorkTestException(format("Unable to map '%s' to %s", key, type), e);
  }
}
 
源代码8 项目: BioSolr   文件: YamlConfigurationLoader.java
@Override
public IndexerConfiguration loadConfiguration() throws IOException {
	FileReader reader = new FileReader(configFile);
       final JsonNode node = mapper.readTree(yamlFactory.createParser(reader));
       final IndexerConfiguration config = mapper.readValue(new TreeTraversingParser(node), IndexerConfiguration.class);
	
	// Close the file reader
	reader.close();
	
	return config;
}
 
源代码9 项目: BioSolr   文件: YamlConfigurationLoader.java
@Override
public IndexerConfiguration loadConfiguration() throws IOException {
	FileReader reader = new FileReader(configFile);
       final JsonNode node = mapper.readTree(yamlFactory.createParser(reader));
       final IndexerConfiguration config = mapper.readValue(new TreeTraversingParser(node), IndexerConfiguration.class);
	
	// Close the file reader
	reader.close();
	
	return config;
}
 
源代码10 项目: Bats   文件: BaseJsonProcessor.java
@Override
public void setSource(JsonNode node) {
  this.parser = new TreeTraversingParser(node);
}
 
源代码11 项目: Bats   文件: JSONOptions.java
public JsonParser asParser(){
  Preconditions.checkArgument(this.root != null, "Attempted to grab JSONOptions as Parser when no root node was stored.  You can only convert non-opaque JSONOptions values to parsers.");
  return new TreeTraversingParser(root);
}
 
源代码12 项目: dremio-oss   文件: JSONOptions.java
public JsonParser asParser(){
  Preconditions.checkArgument(this.root != null, "Attempted to grab JSONOptions as Parser when no root node was stored.  You can only convert non-opaque JSONOptions values to parsers.");
  return new TreeTraversingParser(root);
}
 
源代码13 项目: dremio-oss   文件: BaseJsonProcessor.java
@Override
public void setSource(JsonNode node) {
  this.parser = new TreeTraversingParser(node);
}
 
源代码14 项目: heroic   文件: Spotify100.java
private AsyncFuture<Void> handleVersion1(final JsonNode tree)
    throws ConsumerSchemaValidationException {
    final JsonMetric metric;

    try {
        metric = new TreeTraversingParser(tree, mapper).readValueAs(JsonMetric.class);
    } catch (IOException e) {
        throw new ConsumerSchemaValidationException("Invalid metric", e);
    }

    if (metric.getValue() == null) {
        throw new ConsumerSchemaValidationException(
            "Metric must have a value but this metric has a null value: " + metric);
    }

    if (metric.getTime() == null) {
        throw new ConsumerSchemaValidationException("time: field must be defined: " + tree);
    }

    if (metric.getTime() <= 0) {
        throw new ConsumerSchemaValidationException(
            "time: field must be a positive number: " + tree);
    }

    if (metric.getKey() == null) {
        throw new ConsumerSchemaValidationException("key: field must be defined: " + tree);
    }

    final Map<String, String> tags = new HashMap<>(metric.getAttributes());

    if (metric.getHost() != null) {
        tags.put(HOST_TAG, metric.getHost());
    }

    final Map<String, String> resource = new HashMap<>(metric.getResource());

    final Series series = Series.of(metric.getKey(), tags, resource);
    final Point p = new Point(metric.getTime(), metric.getValue());
    final List<Point> points = ImmutableList.of(p);

    reporter.reportMessageDrift(clock.currentTimeMillis() - p.getTimestamp());
    reporter.reportMetricsIn(1);
    AsyncFuture<Ingestion> ingestionFuture =
        ingestion.write(new Request(series, MetricCollection.points(points)));

    // Return Void future, to not leak unnecessary information from the backend but just
    // allow monitoring of when the consumption is done.
    return ingestionFuture.directTransform(future -> null);
}
 
源代码15 项目: monasca-common   文件: ConfigurationFactory.java
private T build(JsonNode node, String filename) throws IOException, ConfigurationException {
  T config = mapper.readValue(new TreeTraversingParser(node), configType);
  validate(filename, config);
  return config;
}
 
 类方法
 同包方法