@Override public JsonNode findValue(String fieldName) { for (JsonNode node : _children) { JsonNode value = node.findValue(fieldName); if (value != null) { return value; } } return null; }
@Override public String translate(String text, String sourceLanguage, String targetLanguage) throws TikaException, IOException { if (!this.isAvailable) return text; Response response = client.accept(MediaType.APPLICATION_JSON) .query("user_key", userKey).query("source", sourceLanguage) .query("target", targetLanguage).query("q", text).get(); BufferedReader reader = new BufferedReader(new InputStreamReader( (InputStream) response.getEntity(), UTF_8)); String line = null; StringBuffer responseText = new StringBuffer(); while ((line = reader.readLine()) != null) { responseText.append(line); } ObjectMapper mapper = new ObjectMapper(); JsonNode jsonResp = mapper.readTree(responseText.toString()); if (jsonResp.findValuesAsText("errors").isEmpty()) { return jsonResp.findValuesAsText("translation").get(0); } else { throw new TikaException(jsonResp.findValue("errors").get(0).asText()); } }
private String getValue(String fieldName, JsonNode json) { JsonNode node = json.findValue(fieldName); if(node == null) { return null; } return node.textValue(); }
@Override public JsonNode findValue(String fieldName) { for (Map.Entry<String, JsonNode> entry : _children.entrySet()) { if (fieldName.equals(entry.getKey())) { return entry.getValue(); } JsonNode value = entry.getValue().findValue(fieldName); if (value != null) { return value; } } return null; }
return jsonResp.findValuesAsText("outputText").get(0); } else { throw new TikaException(jsonResp.findValue("message").get(0).asText());
public static Optional<AbsoluteRange> extractHistogramBoundaries(final String query) { try { final JsonParser jp = OBJECT_MAPPER.getFactory().createParser(query); final JsonNode rootNode = OBJECT_MAPPER.readTree(jp); final JsonNode timestampNode = rootNode.findValue("range").findValue("timestamp"); final String from = elasticSearchTimeFormatToISO8601(timestampNode.findValue("from").asText()); final String to = elasticSearchTimeFormatToISO8601(timestampNode.findValue("to").asText()); return Optional.of(AbsoluteRange.create(from, to)); } catch (Exception ignored) { return Optional.empty(); } } }
static String doGetEC2InstanceRegion(final String json) { if (null != json) { try { JsonNode node = mapper.readTree(json.getBytes(StringUtils.UTF8)); JsonNode region = node.findValue(REGION); return region.asText(); } catch (Exception e) { log.warn("Unable to parse EC2 instance info (" + json + ") : " + e.getMessage(), e); } } return null; }
/** * Attempt to parse the error code from the response content. Returns null if information is not * present in the content. Codes are expected to be in the form <b>"typeName"</b> or * <b>"prefix#typeName"</b> Examples : "AccessDeniedException", "com.amazonaws.dynamodb.v20111205#ProvisionedThroughputExceededException" */ private String parseErrorCodeFromContents(JsonNode jsonContents) { if (jsonContents == null || !jsonContents.has(errorCodeFieldName)) { return null; } String code = jsonContents.findValue(errorCodeFieldName).asText(); int separator = code.lastIndexOf("#"); return code.substring(separator + 1); } }
private Map<String, Object> convertMappingResponse(String mappingResponse, String type) { ObjectMapper mapper = new ObjectMapper(); try { Map result = null; JsonNode node = mapper.readTree(mappingResponse); node = node.findValue("mappings").findValue(type); result = mapper.readValue(mapper.writeValueAsString(node), HashMap.class); return result; } catch (IOException e) { throw new ElasticsearchException("Could not map alias response : " + mappingResponse, e); } }
/** * Parses the given JsonNode which is a <code>@context</code> node and find * the value of the <code>@vocab</code> node. * * @param contextJsonNode * @return <code>String</code> the Vocab's value e.g "@vocab": * "http://schema.org" otherwise empty String * @review */ public String getVocabulary(JsonNode contextJsonNode) { JsonNode jsonNode = contextJsonNode.findValue(JSONLDConstants.VOCAB); if (jsonNode == null) { JsonNode missingNode = MissingNode.getInstance(); return missingNode.asText(); } return jsonNode.asText(); }
final long date = node.findValue("date").asLong();
/** * It takes two steps to create a List<AliasMetadata> from the elasticsearch http response because the aliases field * is actually a Map by alias name, but the alias name is on the AliasMetadata. * * @param aliasResponse * @return */ List<AliasMetaData> convertAliasResponse(String aliasResponse) { ObjectMapper mapper = new ObjectMapper(); try { JsonNode node = mapper.readTree(aliasResponse); Iterator<String> names = node.fieldNames(); String name = names.next(); node = node.findValue("aliases"); Map<String, AliasData> aliasData = mapper.readValue(mapper.writeValueAsString(node), new TypeReference<Map<String, AliasData>>() {}); Iterable<Map.Entry<String, AliasData>> aliasIter = aliasData.entrySet(); List<AliasMetaData> aliasMetaDataList = new ArrayList<AliasMetaData>(); for (Map.Entry<String, AliasData> aliasentry : aliasIter) { AliasData data = aliasentry.getValue(); aliasMetaDataList.add(AliasMetaData.newAliasMetaDataBuilder(aliasentry.getKey()).filter(data.getFilter()) .routing(data.getRouting()).searchRouting(data.getSearch_routing()).indexRouting(data.getIndex_routing()) .build()); } return aliasMetaDataList; } catch (IOException e) { throw new ElasticsearchException("Could not map alias response : " + aliasResponse, e); } }
propertyNode = properties.findValue(requiredArrayItem);
static String doGetEC2InstanceRegion(final String json) { if (null != json) { try { JsonNode node = mapper.readTree(json.getBytes(StringUtils.UTF8)); JsonNode region = node.findValue(REGION); return region.asText(); } catch (Exception e) { log.warn("Unable to parse EC2 instance info (" + json + ") : " + e.getMessage(), e); } } return null; }
/** * Attempt to parse the error code from the response content. Returns null if information is not * present in the content. Codes are expected to be in the form <b>"typeName"</b> or * <b>"prefix#typeName"</b> Examples : "AccessDeniedException", "com.amazonaws.dynamodb.v20111205#ProvisionedThroughputExceededException" */ private String parseErrorCodeFromContents(JsonNode jsonContents) { if (jsonContents == null || !jsonContents.has(errorCodeFieldName)) { return null; } String code = jsonContents.findValue(errorCodeFieldName).asText(); int separator = code.lastIndexOf("#"); return code.substring(separator + 1); } }
public static JsonNode getJsonNodeByKey(String content, String key) throws JsonProcessingException, IOException { getObjectMapperInstance(); mapper.configure(DeserializationFeature.UNWRAP_ROOT_VALUE, false);// 序列化默认以类名为根元素 JsonNode jsonNode = mapper.readTree(content); return jsonNode.findValue(key); } }
@Override public JsonNode findValue(String fieldName) { for (JsonNode node : _children) { JsonNode value = node.findValue(fieldName); if (value != null) { return value; } } return null; }
@Override public JsonNode findValue(String fieldName) { for (JsonNode node : _children) { JsonNode value = node.findValue(fieldName); if (value != null) { return value; } } return null; }
private Object[] getValues(final JsonNode readTree) { final List<Column> columns = getColumns(); final Object[] list = new Object[columns.size()]; for (int i = 0; i < columns.size(); i++) { final JsonNode node = readTree.findValue(columns.get(i).getName()); final String value = node.asText(); list[i] = value; } return list; }