/** * Factory method for constructing an empty JSON Object ("struct") node */ @Override public ObjectNode objectNode() { return new ObjectNode(this); }
@Override protected ObjectNode createMissingNode() { return new ObjectNode(NODE_FACTORY); } }
public DataSourceImpl(ModelManager model) { this(model, new ObjectNode(JsonNodeFactory.instance)); }
@SuppressWarnings("unchecked") @Override public ObjectNode deepCopy() { ObjectNode ret = new ObjectNode(_nodeFactory); for (Map.Entry<String, JsonNode> entry: _children.entrySet()) ret._children.put(entry.getKey(), entry.getValue().deepCopy()); return ret; }
public JsonNode build() { Objects.requireNonNull(resourceStreamSupplier); Objects.requireNonNull(parser); Objects.requireNonNull(merger); JsonNode rootNode; try (Stream<URL> sources = resourceStreamSupplier.get()) { rootNode = sources .map(parser::apply) .filter(Optional::isPresent) .map(Optional::get) .reduce(merger) .orElseGet(() -> new ObjectNode(new JsonNodeFactory(true))); } return overrider.apply(rootNode); } }
protected JsonNode findChild(String path) { // assuming prefix is case-insensitive. This allows prefixes that are defined in the shell vars and nowhere // else... // TODO: this also makes YAML prefix case-insensitive, and the whole config more ambiguous, which is less than // ideal. Perhaps we can freeze prefix case for YAMLs by starting with a synthetic JsonNode based on the prefix // and then overlay CS config (YAML) only then - CI config (vars)? This will require deep refactoring. Also // we will need to know the type of the root JsonNode (String vs Object vs List, etc.) // or we just make it case-sensitive like the rest of the config... return CiPropertySegment .create(rootNode, path) .lastPathComponent().map(t -> t.getNode()) .orElse(new ObjectNode(null)); }
public ConfigSource fromPropertiesYamlLiteral(Map<String, String> props, String keyPrefix) { ObjectNode source = new ObjectNode(JsonNodeFactory.instance); DataSource ds = new DataSourceImpl(model, source); Yaml yaml = newYaml(); for (Map.Entry<String, String> pair : props.entrySet()) { if (!pair.getKey().startsWith(keyPrefix)) { continue; } String keyName = pair.getKey().substring(keyPrefix.length()); Object parsedValue = yaml.load(pair.getValue()); // TODO exception handling JsonNode node = objectToJson(parsedValue); // handle "." as a map acccessor. for example: // in.parser.type=csv => {"in": {"parser": {"type": "csv"}}} // TODO handle "[]" as array index String[] fragments = keyName.split("\\."); DataSource key = ds; for (int i = 0; i < fragments.length - 1; i++) { key = key.getNestedOrSetEmpty(fragments[i]); // TODO exception handling } key.set(fragments[fragments.length - 1], node); } return new DataSourceImpl(model, source); }
@Test public void always_return_same_object() { // Test because of Bug #211 DocumentContext context = using(JACKSON_JSON_NODE_CONFIGURATION).parse(JSON_DOCUMENT); ObjectNode node1 = context.read("$"); ObjectNode child1 = new ObjectNode(JsonNodeFactory.instance); child1.put("name", "test"); context.put("$", "child", child1); ObjectNode node2 = context.read("$"); ObjectNode child2 = context.read("$.child"); assertThat(node1).isSameAs(node2); assertThat(child1).isSameAs(child2); }
public static Sort create(String fieldName, Object ascOrder) { ObjectNode node = new ObjectNode(JsonNodeFactory.instance); //Only allow boolean type for value. This specifies whether to sort ascending or descending if (ascOrder instanceof Boolean) { node.put(fieldName, (Boolean) ascOrder); } else { throw new UnsupportedOperationException("Sort creation doesn't accept type: " + ascOrder.toString() + " at present."); } return Sort.create(node); }
public JsonNode toNotifyJson() { ObjectNode result = new ObjectNode(Topology.OBJECT_MAPPER.getNodeFactory()); result.put("name", this.name); for (String k:properties.keySet()){ result.put(k, properties.get(k)); } return result; }
@Override public JsonNode serialize(Map<String, AttributeValue<U>> object) { Map<String, JsonNode> jsonMap = object.entrySet().stream() .collect(ImmutableMap.toImmutableMap(Entry::getKey, entry -> entry.getValue().toJson())); return new ObjectNode(JsonNodeFactory.instance, jsonMap); }
protected JsonNode findChild(String path) { // assuming prefix is case-insensitive. This allows prefixes that are defined in the shell vars and nowhere // else... // TODO: this also makes YAML prefix case-insensitive, and the whole config more ambiguous, which is less than // ideal. Perhaps we can freeze prefix case for YAMLs by starting with a synthetic JsonNode based on the prefix // and then overlay CS config (YAML) only then - CI config (vars)? This will require deep refactoring. Also // we will need to know the type of the root JsonNode (String vs Object vs List, etc.) return new CiPathSegment(rootNode, path, '.').lastPathComponent().map(t -> t.getNode()) .orElse(new ObjectNode(null)); }
private URLFilter createFilter(boolean removeAnchor, boolean checkValidURI) { ObjectNode filterParams = new ObjectNode(JsonNodeFactory.instance); filterParams.put("removeAnchorPart", Boolean.valueOf(removeAnchor)); filterParams.put("checkValidURI", Boolean.valueOf(checkValidURI)); return createFilter(filterParams); }
private URLFilter createFilter() { ObjectNode filterParams = new ObjectNode(JsonNodeFactory.instance); filterParams.put("regexFilterFile", "default-regex-filters.txt"); return createFilter(filterParams); }
private URLFilter createFilter(boolean removeAnchor, List<String> queryElementsToRemove) { ObjectNode filterParams = new ObjectNode(JsonNodeFactory.instance); filterParams.set("queryElementsToRemove", getArrayNode(queryElementsToRemove)); filterParams.put("removeAnchorPart", Boolean.valueOf(removeAnchor)); return createFilter(filterParams); }
private URLFilter createFilter(int length, int repet) { BasicURLFilter filter = new BasicURLFilter(); ObjectNode filterParams = new ObjectNode(JsonNodeFactory.instance); filterParams.put("maxPathRepetition", repet); filterParams.put("maxLength", length); Map<String, Object> conf = new HashMap<>(); filter.configure(conf, filterParams); return filter; }
private URLFilter createFilter(String key, int value) { MaxDepthFilter filter = new MaxDepthFilter(); ObjectNode filterParams = new ObjectNode(JsonNodeFactory.instance); filterParams.put(key, value); Map<String, Object> conf = new HashMap<>(); filter.configure(conf, filterParams); return filter; }
private URLFilter createFilter(List<String> queryElementsToRemove) { ObjectNode filterParams = new ObjectNode(JsonNodeFactory.instance); filterParams.set("queryElementsToRemove", getArrayNode(queryElementsToRemove)); return createFilter(filterParams); }
@Test(expected = IllegalStateException.class) public void deserializedRequestsShouldThrowWhenFirstParameterIsNotString() throws JsonParseException, JsonMappingException, IOException { JsonNode[] nodes = new JsonNode[] { new ObjectNode(new JsonNodeFactory(false)).booleanNode(true), new ObjectNode(new JsonNodeFactory(false)).putObject("{}"), new ObjectNode(new JsonNodeFactory(false)).textNode("#0")}; ProtocolRequest.deserialize(nodes); }
@Test(expected = IllegalStateException.class) public void deserializedRequestsShouldThrowWhenThirdParameterIsNotString() throws JsonParseException, JsonMappingException, IOException { JsonNode[] nodes = new JsonNode[] { new ObjectNode(new JsonNodeFactory(false)).textNode("getAccounts"), new ObjectNode(new JsonNodeFactory(false)).putObject("{}"), new ObjectNode(new JsonNodeFactory(false)).booleanNode(true)}; ProtocolRequest.deserialize(nodes); }