List of usage examples for com.fasterxml.jackson.databind JsonNode textValue
public String textValue()
From source file:com.syncedsynapse.kore2.utils.JsonUtils.java
public static String stringFromJsonNode(JsonNode node, String key) { // Duplicate code for performance resons if (node == null) return null; JsonNode value = node.get(key); if (value == null) return null; return value.textValue(); }
From source file:com.vaporwarecorp.mirror.util.JsonUtil.java
public static String textValue(JsonNode node, String key) { JsonNode keyNode = jsonNodeValue(node, key); if (keyNode != null) { return StringUtils.trimToNull(keyNode.textValue()); }//w w w . j a va 2 s . c o m return null; }
From source file:com.syncedsynapse.kore2.utils.JsonUtils.java
public static String stringFromJsonNode(JsonNode node, String key, String defaultValue) { if (node == null) return defaultValue; JsonNode value = node.get(key); if (value == null) return defaultValue; return value.textValue(); }
From source file:com.rusticisoftware.tincan.Agent.java
public static Agent fromJson(JsonNode jsonNode) { String objectType = "Agent"; JsonNode objectTypeNode = jsonNode.path("objectType"); if (!objectTypeNode.isMissingNode()) { objectType = objectTypeNode.textValue(); }/*w w w .j av a 2s .c om*/ return "Group".equals(objectType) ? new Group(jsonNode) : new Agent(jsonNode); }
From source file:io.fabric8.profiles.ProfilesHelpers.java
public static JsonNode merge(JsonNode target, JsonNode source) { if (target == null) { return source; }/*from w ww. j a v a2 s .co m*/ if (target.isArray() && source.isArray()) { // we append values from the source. ArrayNode copy = (ArrayNode) target.deepCopy(); for (JsonNode n : source) { if ((n.isTextual() && DELETED.equals(n.textValue()))) { copy = JsonNodeFactory.instance.arrayNode(); } else { copy.add(n); } } return copy; } else if (target.isObject() && source.isObject()) { ObjectNode copy = (ObjectNode) target.deepCopy(); if (source.get(DELETED) != null) { copy = JsonNodeFactory.instance.objectNode(); } else { Iterator<String> iterator = source.fieldNames(); while (iterator.hasNext()) { String key = iterator.next(); if (!DELETED.equals(key)) { JsonNode value = source.get(key); if ((value.isTextual() && DELETED.equals(value.textValue()))) { copy.remove(key); } else { JsonNode original = target.get(key); value = merge(original, value); copy.set(key, value); } } } } return copy; } else { return source; } }
From source file:controllers.Index.java
private static void readData(final BulkRequestBuilder bulkRequest, final BufferedReader br, final Client client, final String aIndex) throws IOException { final ObjectMapper mapper = new ObjectMapper(); String line;/*from w ww. jav a 2s .co m*/ int currentLine = 1; String organisationData = null; String[] idUriParts = null; String organisationId = null; // First line: index with id, second line: source while ((line = br.readLine()) != null) { JsonNode rootNode = mapper.readValue(line, JsonNode.class); if (currentLine % 2 != 0) { JsonNode index = rootNode.get("index"); idUriParts = index.findValue("_id").asText().split("/"); organisationId = idUriParts[idUriParts.length - 1].replace("#!", ""); } else { organisationData = line; JsonNode libType = rootNode.get("type"); if (libType == null || !libType.textValue().equals("Collection")) { bulkRequest.add(client .prepareIndex(aIndex, Application.CONFIG.getString("index.es.type"), organisationId) .setSource(organisationData)); } } currentLine++; } }
From source file:de.up.ling.irtg.util.FirstOrderModel.java
/** * Reads the options from a Json string representation. The options for the * SetAlgebra consist in a specification of the universe and the * interpretations of the atomic concepts. For instance, the following * string says that "sleep" is a binary relation with the single element * (e,r1), whereas "rabbit" is a unary relation containing the elements r1 * and r2.<p>//from w w w .j a v a2 s. c o m * * {"sleep": [["e", "r1"]], "rabbit": [["r1"], ["r2"]], "white": [["r1"], * ["b"]], "in": [["r1","h"], ["f","h2"]], "hat": [["h"], ["h2"]] } * * * @param optionReader * @throws Exception */ public static FirstOrderModel read(Reader optionReader) throws Exception { FirstOrderModel model = new FirstOrderModel(); String optionString = StringTools.slurp(optionReader); Map<String, Set<List<String>>> atomicInterpretations = new HashMap<String, Set<List<String>>>(); if (!optionString.trim().equals("")) { ObjectMapper mapper = new ObjectMapper(); JsonNode root = mapper.readValue(optionString, JsonNode.class); if (!root.isObject()) { throw new Exception("Invalid universe description: should be a map"); } else { Iterator<String> preds = root.fieldNames(); while (preds.hasNext()) { String pred = preds.next(); Set<List<String>> tuples = new HashSet<List<String>>(); JsonNode child = root.get(pred); if (!child.isArray()) { throw new Exception("Invalid universe description: Entry '" + pred + "' should be a list."); } else { int childIndex = 0; for (JsonNode tuple : child) { List<String> tupleElements = new ArrayList<String>(); childIndex++; if (!tuple.isArray()) { throw new Exception("Invalid universe description: tuple " + childIndex + " under '" + pred + "' should be a list."); } else { for (JsonNode tupleEl : tuple) { tupleElements.add(tupleEl.textValue()); } } tuples.add(tupleElements); } } atomicInterpretations.put(pred, tuples); } } } model.setAtomicInterpretations(atomicInterpretations); return model; }
From source file:de.qaware.cloud.deployer.commons.config.util.ContentTreeUtil.java
/** * Reads the string with the specified key in the object tree. * * @param contentObjectTree The object tree which contains the string identified by the specified key. * @param key The key which identifies the string. * @return The value of the key in form of a string. * @throws ResourceConfigException If the key isn't available in the object tree. *//*from w w w . jav a 2 s .c o m*/ public static String readStringValue(JsonNode contentObjectTree, String key) throws ResourceConfigException { if (contentObjectTree.hasNonNull(key)) { JsonNode jsonNode = contentObjectTree.get(key); if (jsonNode.isTextual()) { return jsonNode.textValue(); } else { throw new ResourceConfigException( COMMONS_MESSAGE_BUNDLE.getMessage("DEPLOYER_COMMONS_ERROR_READING_STRING_VALUE", key)); } } else { throw new ResourceConfigException( COMMONS_MESSAGE_BUNDLE.getMessage("DEPLOYER_COMMONS_ERROR_READING_NODE_VALUE", key)); } }
From source file:com.github.fge.jsonschema.core.load.RefResolver.java
private static JsonRef nodeAsRef(final JsonNode node) { final JsonNode refNode = node.path("$ref"); if (!refNode.isTextual()) return null; try {/*from www .j av a 2s .co m*/ return JsonRef.fromString(refNode.textValue()); } catch (JsonReferenceException ignored) { return null; } }
From source file:com.github.fge.jsonschema2avro.predicates.AvroPredicates.java
private static NodeType getType(final JsonNode node) { final JsonNode typeNode = node.path("type"); return typeNode.isTextual() ? NodeType.fromName(typeNode.textValue()) : null; }