List of usage examples for com.fasterxml.jackson.databind.node TextNode TextNode
public TextNode(String paramString)
From source file:com.squarespace.template.Context.java
public JsonNode buildNode(String value) { return new TextNode(value); }
From source file:com.github.reinert.jjschema.HyperSchemaGeneratorV4.java
private static <T> ObjectNode transformJsonToHyperSchema(Class<T> type, ObjectNode jsonSchema) { ObjectNode properties = (ObjectNode) jsonSchema.get("properties"); Iterator<String> namesIterator = properties.fieldNames(); while (namesIterator.hasNext()) { String prop = namesIterator.next(); try {// ww w . j a va 2 s.c o m Field field = type.getDeclaredField(prop); com.github.reinert.jjschema.Media media = field .getAnnotation(com.github.reinert.jjschema.Media.class); if (media != null) { ObjectNode hyperProp = (ObjectNode) properties.get(prop); hyperProp.put(MEDIA_TYPE, media.type()); hyperProp.put(BINARY_ENCODING, media.binaryEncoding()); if (hyperProp.get("type").isArray()) { TextNode typeString = new TextNode("string"); ((ArrayNode) hyperProp.get("type")).set(0, typeString); } else { hyperProp.put("type", "string"); } properties.put(prop, hyperProp); } } catch (NoSuchFieldException e) { //e.printStackTrace(); } catch (SecurityException e) { //e.printStackTrace(); } } return jsonSchema; }
From source file:controllers.Rules.java
@Security.Authenticated(Secured.class) @BodyParser.Of(BodyParser.Json.class) public static Promise<Result> addFeature(String name) { JsonNode json = request().body().asJson(); final ObjectNode avm = (ObjectNode) json.deepCopy(); avm.retain("ruleUUID", "uuid"); final ObjectNode feature = Json.newObject(); feature.put("name", json.findValue("name").asText()); feature.put("type", json.findValue("type").asText()); Promise<Boolean> added = Substructure.nodes.connect(avm, feature); Promise<Feature> feat = Feature.nodes.get(feature); return added.zip(feat).map(new Function<Tuple<Boolean, Feature>, Result>() { ObjectNode result = Json.newObject(); public Result apply(Tuple<Boolean, Feature> t) { Boolean added = t._1; if (added) { Feature feat = t._2;//from www .j ava 2 s . c o m if (feat.isComplex()) { String parentUUID = avm.get("uuid").asText(); String featureUUID = feat.getUUID(); String uuid = UUIDGenerator.from(parentUUID + featureUUID); ObjectNode value = Json.newObject(); value.put("uuid", uuid); value.putArray("pairs"); result.put("value", value); } else { result.put("value", new TextNode("underspecified")); } result.put("message", "Feature successfully added."); return ok(result); } result.put("message", "Feature not added."); return badRequest(result); } }); }
From source file:org.apache.olingo.fit.utils.JSONUtilities.java
@Override public InputStream readEntities(final List<String> links, final String linkName, final String next, final boolean forceFeed) throws IOException { if (links.isEmpty()) { throw new NotFoundException(); }//from ww w. j ava 2s . c o m final ObjectNode node = mapper.createObjectNode(); final ByteArrayOutputStream bos = new ByteArrayOutputStream(); if (forceFeed || links.size() > 1) { bos.write("[".getBytes()); } for (String link : links) { try { final Map.Entry<String, String> uriMap = Commons.parseEntityURI(link); final Map.Entry<String, InputStream> entity = readEntity(uriMap.getKey(), uriMap.getValue(), Accept.JSON_FULLMETA); if (bos.size() > 1) { bos.write(",".getBytes()); } IOUtils.copy(entity.getValue(), bos); } catch (Exception e) { // log and ignore link LOG.warn("Error parsing uri {}", link, e); } } if (forceFeed || links.size() > 1) { bos.write("]".getBytes()); } node.set(Constants.get(ConstantKey.JSON_VALUE_NAME), mapper.readTree(new ByteArrayInputStream(bos.toByteArray()))); if (StringUtils.isNotBlank(next)) { node.set(Constants.get(ConstantKey.JSON_NEXTLINK_NAME), new TextNode(next)); } return IOUtils.toInputStream(node.toString(), Constants.ENCODING); }
From source file:org.apache.hadoop.gateway.filter.rewrite.impl.json.JsonFilterReader.java
private void processValueString() throws IOException { Level child;/*from w w w . j a va 2 s .c o m*/ Level parent; String value = null; parent = stack.peek(); if (parent.isArray()) { ArrayNode array = (ArrayNode) parent.node; array.add(parser.getText()); if (bufferingLevel == null) { value = filterStreamValue(parent); array.set(array.size() - 1, new TextNode(value)); } else { array.removeAll(); } } else { child = stack.pop(); parent = stack.peek(); ((ObjectNode) parent.node).put(child.field, parser.getText()); if (bufferingLevel == null) { child.node = parent.node; // Populate the JsonNode of the child for filtering. value = filterStreamValue(child); } } if (bufferingLevel == null) { if (parent.node.isArray()) { ((ArrayNode) parent.node).removeAll(); } else { ((ObjectNode) parent.node).removeAll(); } generator.writeString(value); } }
From source file:com.msopentech.odatajclient.testservice.utils.JSONUtilities.java
@Override public InputStream readEntities(final List<String> links, final String linkName, final String next, final boolean forceFeed) throws Exception { if (links.isEmpty()) { throw new NotFoundException(); }// w w w .ja v a 2 s . c o m final ObjectMapper mapper = new ObjectMapper(); final ObjectNode node = mapper.createObjectNode(); final ByteArrayOutputStream bos = new ByteArrayOutputStream(); if (forceFeed || links.size() > 1) { bos.write("[".getBytes()); } for (String link : links) { try { final Map.Entry<String, String> uri = Commons.parseEntityURI(link); final Map.Entry<String, InputStream> entity = readEntity(uri.getKey(), uri.getValue(), Accept.JSON_FULLMETA); if (bos.size() > 1) { bos.write(",".getBytes()); } IOUtils.copy(entity.getValue(), bos); } catch (Exception e) { // log and ignore link LOG.warn("Error parsing uri {}", link, e); } } if (forceFeed || links.size() > 1) { bos.write("]".getBytes()); } node.set(JSON_VALUE_NAME, mapper.readTree(new ByteArrayInputStream(bos.toByteArray()))); if (StringUtils.isNotBlank(next)) { node.set(JSON_NEXTLINK_NAME, new TextNode(next)); } return IOUtils.toInputStream(node.toString()); }
From source file:org.walkmod.conf.providers.YAMLConfigurationProvider.java
@Override public void addPluginConfig(final PluginConfig pluginConfig, boolean recursive) throws TransformerException { File cfg = new File(fileName); ArrayNode pluginList = null;/*w w w. j av a2s.co m*/ JsonNode node = null; try { node = mapper.readTree(cfg); } catch (Exception e) { } if (node == null) { node = new ObjectNode(mapper.getNodeFactory()); } if (recursive && node.has("modules")) { JsonNode aux = node.get("modules"); if (aux.isArray()) { ArrayNode modules = (ArrayNode) aux; int max = modules.size(); for (int i = 0; i < max; i++) { JsonNode module = modules.get(i); if (module.isTextual()) { String moduleDir = module.asText(); try { File auxFile = new File(fileName).getCanonicalFile().getParentFile(); YAMLConfigurationProvider child = new YAMLConfigurationProvider( auxFile.getAbsolutePath() + File.separator + moduleDir + File.separator + "walkmod.yml"); child.createConfig(); child.addPluginConfig(pluginConfig, recursive); } catch (IOException e) { throw new TransformerException(e); } } } } } else { if (!node.has("plugins")) { pluginList = new ArrayNode(mapper.getNodeFactory()); if (node.isObject()) { ObjectNode aux = (ObjectNode) node; aux.set("plugins", pluginList); } else { throw new TransformerException("The root element is not a JSON node"); } } else { JsonNode aux = node.get("plugins"); if (aux.isArray()) { pluginList = (ArrayNode) node.get("plugins"); } else { throw new TransformerException("The plugins element is not a valid array"); } } pluginList.add(new TextNode(pluginConfig.getGroupId() + ":" + pluginConfig.getArtifactId() + ":" + pluginConfig.getVersion())); write(node); } }
From source file:org.apache.olingo.fit.utils.JSONUtilities.java
@Override public InputStream addEditLink(final InputStream content, final String title, final String href) throws IOException { final ObjectNode srcNode = (ObjectNode) mapper.readTree(content); IOUtils.closeQuietly(content);/*w w w . jav a 2 s. c o m*/ srcNode.set(Constants.get(ConstantKey.JSON_EDITLINK_NAME), new TextNode(href)); return IOUtils.toInputStream(srcNode.toString(), Constants.ENCODING); }
From source file:org.apache.olingo.fit.utils.JSONUtilities.java
@Override public InputStream addOperation(final InputStream content, final String name, final String metaAnchor, final String href) throws IOException { final ObjectNode srcNode = (ObjectNode) mapper.readTree(content); IOUtils.closeQuietly(content);//ww w . java 2 s . c om final ObjectNode action = mapper.createObjectNode(); action.set("title", new TextNode(name)); action.set("target", new TextNode(href)); srcNode.set(metaAnchor, action); return IOUtils.toInputStream(srcNode.toString(), Constants.ENCODING); }
From source file:org.apache.olingo.fit.utils.JSONUtilities.java
@Override public InputStream replaceProperty(final InputStream src, final InputStream replacement, final List<String> path, final boolean justValue) throws IOException { final ObjectNode srcNode = (ObjectNode) mapper.readTree(src); IOUtils.closeQuietly(src);//from w w w . j av a 2s .co m JsonNode replacementNode; if (justValue) { replacementNode = new TextNode(IOUtils.toString(replacement)); } else { replacementNode = mapper.readTree(replacement); if (replacementNode.has("value")) { replacementNode = replacementNode.get("value"); } } IOUtils.closeQuietly(replacement); JsonNode node = srcNode; for (int i = 0; i < path.size() - 1; i++) { node = node.get(path.get(i)); if (node == null) { throw new NotFoundException(); } } ((ObjectNode) node).set(path.get(path.size() - 1), replacementNode); return IOUtils.toInputStream(srcNode.toString(), Constants.ENCODING); }