/** * Method for constructing a {@link JsonParser} out of JSON tree * representation. * * @param n Root node of the tree that resulting parser will read from */ @Override public JsonParser treeAsTokens(TreeNode n) { return new TreeTraversingParser((JsonNode) n, this); }
@Override public JsonParser traverse() { return new TreeTraversingParser(this); }
@Override public JsonParser traverse(ObjectCodec codec) { return new TreeTraversingParser(this, codec); }
@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); }
@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); } }
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); }
@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); } }
final T config = mapper.readValue(new TreeTraversingParser(node), klass); validate(path, config); return config;
/** * Method for constructing a {@link JsonParser} out of JSON tree * representation. * * @param n Root node of the tree that resulting parser will read from */ @Override public JsonParser treeAsTokens(TreeNode n) { return new TreeTraversingParser((JsonNode) n, this); }
@Override public JsonParser traverse() { return new TreeTraversingParser(this); }
@Override public JsonParser traverse(ObjectCodec codec) { return new TreeTraversingParser(this, codec); }
/** * Method for constructing a {@link JsonParser} out of JSON tree * representation. * * @param n Root node of the tree that resulting parser will read from */ @Override public JsonParser treeAsTokens(TreeNode n) { return new TreeTraversingParser((JsonNode) n, this); }
/** * Method for constructing a {@link JsonParser} out of JSON tree * representation. * * @param n Root node of the tree that resulting parser will read from */ @Override public JsonParser treeAsTokens(TreeNode n) { return new TreeTraversingParser((JsonNode) n, this); }
default <T> T mapTo(ObjectMapper objectMapper, Map description, Class<T> clazz) throws IOException { ObjectNode objectNode = objectMapper.valueToTree(description); return objectMapper.readValue(new TreeTraversingParser(objectNode, objectMapper), clazz); } }
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); }
@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); } }
@Override public Set<ClassDefinition> parseReader(Reader in) { final JsonNode node; try { node = objectMapper.readTree(jsonFactory.createParser(in)); PackageDefinition packageDefinition = objectMapper.readValue(new TreeTraversingParser(node), PackageDefinition.class); return toClassDefinitions(packageDefinition); } catch (IOException e) { throw new ParsingException("Cannot parse reader!"); } }
/** * Maps the stage's context to a typed object at a provided pointer. Uses * <a href="https://tools.ietf.org/html/rfc6901">JSON Pointer</a> notation for determining the pointer's position */ public <O> O mapTo(String pointer, Class<O> type) { try { return objectMapper.readValue(new TreeTraversingParser(getPointer(pointer != null ? pointer : "", contextToNode()), objectMapper), type); } catch (IOException e) { throw new IllegalArgumentException(format("Unable to map context to %s", type), e); } }
@Override public Set<ClassDefinition> parseReader(Reader in) { final JsonNode node; try { node = objectMapper.readTree(yamlFactory.createParser(in)); PackageDefinition packageDefinition = objectMapper.readValue(new TreeTraversingParser(node), PackageDefinition.class); return toClassDefinitions(packageDefinition); } catch (IOException e) { throw new ParsingException("Cannot parse reader!"); } }
private ManagedDataSourceFactory createDataSourceFactory(Injector injector) { Class<? extends ManagedDataSourceFactory> factoryType = delegateFactoryType(injector); JavaType jacksonType = TypeFactory.defaultInstance().constructType(factoryType); ObjectMapper mapper = createObjectMapper(injector); JsonNode nodeWithType = jsonNodeWithType(getTypeLabel(factoryType)); try { return mapper.readValue(new TreeTraversingParser(nodeWithType, mapper), jacksonType); } catch (IOException e) { throw new BootiqueException(1, "Deserialization of JDBC DataSource configuration failed.", e); } }