List of usage examples for com.fasterxml.jackson.databind JsonNode get
public JsonNode get(String paramString)
From source file:com.surfs.storage.web.utils.JsonUtils.java
public static Map<String, String> jsonStringConvertMap(String jsonString, String... args) throws JsonProcessingException, IOException { if (jsonString == null) return new HashMap<String, String>(); JsonNode jsonNode = mapper.readTree(jsonString); Map<String, String> map = new HashMap<String, String>(); for (String key : args) { map.put(key, jsonNode.get(key).toString()); }//w w w . j av a 2 s .co m return map; }
From source file:com.pros.jsontransform.plugin.filter.ArrayFilterTaxPercentRange.java
public static boolean evaluate(final JsonNode filterNode, final JsonNode elementNode, final ObjectTransformer transformer) { // expect price and tax nodes in elementNode double price = elementNode.get("price").asDouble(); double tax = elementNode.get("tax").asDouble(); double percentTax = tax * 100 / price; boolean ltRangeValid = true; boolean gtRangeValid = true; JsonNode rangeNode = filterNode.get(CONSTRAINT_NAME); if (rangeNode.isObject()) { JsonNode ltNode = rangeNode.path("$less-than"); if (!ltNode.isMissingNode()) { ltRangeValid = percentTax < ltNode.asDouble(); }//from w w w . j a v a 2s . c om JsonNode gtNode = rangeNode.path("$greater-than"); if (!gtNode.isMissingNode()) { gtRangeValid = percentTax > gtNode.asDouble(); } } return ltRangeValid && gtRangeValid; }
From source file:com.flipkart.zjsonpatch.PatchTestCase.java
public static Collection<PatchTestCase> load(String fileName) throws IOException { String path = "/testdata/" + fileName + ".json"; InputStream resourceAsStream = PatchTestCase.class.getResourceAsStream(path); String testData = IOUtils.toString(resourceAsStream, "UTF-8"); JsonNode tree = MAPPER.readTree(testData); List<PatchTestCase> result = new ArrayList<PatchTestCase>(); for (JsonNode node : tree.get("errors")) { if (isEnabled(node)) { result.add(new PatchTestCase(false, node)); }//www. j av a2 s . c om } for (JsonNode node : tree.get("ops")) { if (isEnabled(node)) { result.add(new PatchTestCase(true, node)); } } return result; }
From source file:org.agorava.linkedin.jackson.DeserializationUtils.java
public static <T> T deserializeFromDataNode(JsonParser jp, DeserializationContext ctxt, String propertyName, TypeReference<T> typeReference) throws IOException, JsonProcessingException { if (jp.hasCurrentToken() && jp.getCurrentToken().equals(JsonToken.START_OBJECT)) { JsonNode dataNode = jp.readValueAs(JsonNode.class); if (dataNode.has(propertyName)) { return OBJECT_MAPPER.reader(typeReference).<T>readValue(dataNode.get(propertyName)); }/*w w w .j av a 2 s .c om*/ return null; } throw ctxt.mappingException("Expected JSON object"); }
From source file:io.syndesis.rest.v1.handler.connection.ConnectionActionHandler.java
static String typeFrom(final Object obj) { final JsonNode node = (JsonNode) obj; return node.get("title").asText(); }
From source file:it.polimi.diceH2020.SPACE4Cloud.shared.validation.ValidationUtils.java
private static JsonSchema _getSchemaNode(JsonNode jsonNode) throws ProcessingException { final JsonNode schemaIdentifier = jsonNode.get(JSON_SCHEMA_IDENTIFIER_ELEMENT); if (null == schemaIdentifier) { ((ObjectNode) jsonNode).put(JSON_SCHEMA_IDENTIFIER_ELEMENT, JSON_V4_SCHEMA_IDENTIFIER); }//ww w . j a v a 2 s .c o m final JsonSchemaFactory factory = JsonSchemaFactory.byDefault(); return factory.getJsonSchema(jsonNode); }
From source file:com.brett.http.geo.baidu.GeoRequestHttpClient.java
public static JsonNode geoAcquire(String city) throws Exception { CloseableHttpClient httpclient = HttpClients.createDefault(); // DefaultHttpParams.getDefaultParams().setParameter("http.protocol.cookie-policy", CookiePolicy.BROWSER_COMPATIBILITY); // httpclient.getParams().setParameter(ClientPNames.COOKIE_POLICY, CookiePolicy.BEST_MATCH); try {//from w w w. jav a2 s . c om String address = URLEncoder.encode(city, "utf-8"); String url = "http://api.map.baidu.com/geocoder/v2/?address={address}&output=json&ak=E4805d16520de693a3fe707cdc962045"; url = url.replaceFirst("\\{address\\}", address); HttpGet httpget = new HttpGet(url); httpget.setHeader("Accept", "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8"); httpget.setHeader("Accept-Encoding", "gzip, deflate, sdch"); httpget.setHeader("Accept-Language", "zh-CN,zh;q=0.8"); httpget.setHeader("Cache-Control", "no-cache"); httpget.setHeader("Connection", "keep-alive"); httpget.setHeader("Referer", "http://developer.baidu.com/map/index.php?title=webapi/guide/webservice-geocoding"); httpget.setHeader("User-Agent", "Mozilla/5.0 (Windows NT 6.3; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/40.0.2214.93 Safari/537.36"); System.out.println("Executing request httpget.getRequestLine() " + httpget.getRequestLine()); // Create a custom response handler ResponseHandler<String> responseHandler = new ResponseHandler<String>() { public String handleResponse(final HttpResponse response) throws ClientProtocolException, IOException { int status = response.getStatusLine().getStatusCode(); if (status >= 200 && status < 300) { HttpEntity entity = response.getEntity(); return entity != null ? EntityUtils.toString(entity, "utf-8") : null; } else { throw new ClientProtocolException("Unexpected response status: " + status); } } }; String responseBody = httpclient.execute(httpget, responseHandler); System.out.println("----------------------------------------"); System.out.println(HtmlDecoder.decode(responseBody)); System.out.println(responseBody); System.out.println("----------------------------------------"); ObjectMapper mapper = new ObjectMapper(); mapper.readValue(responseBody, AddressCoord.class); // JsonNode root = mapper.readTree(responseBody.substring("showLocation&&showLocation(".length(), responseBody.length()-1)); // {"status":0,"result":{"location":{"lng":116.30783584945,"lat":40.056876296398},"precise":1,"confidence":80,"level":"\u5546\u52a1\u5927\u53a6"}} JsonNode root = mapper.readTree(responseBody); System.out.println("result : " + city + " = " + root.get("result")); return root; } finally { httpclient.close(); } }
From source file:com.collective.celos.SlotState.java
public static SlotState fromJSONNode(WorkflowID id, JsonNode node) { ScheduledTime time = new ScheduledTime(node.get(TIME_PROP).textValue()); return fromJSONNode(new SlotID(id, time), node); }
From source file:com.ibm.watson.catalyst.jumpqa.trec.TrecReader.java
private static Trec json2trec(final JsonNode trecJson) { final TrecBuilder tb = new TrecBuilder(); if (trecJson.has("file")) { tb.setFile(trecJson.get("file").asText()); }// ww w . ja v a 2 s .co m tb.setPauId(trecJson.get("pauID").asText()); tb.setPauTitle(trecJson.get("pauTitle").asText()); tb.setSourceDoc(trecJson.get("sourceDoc").asText()); tb.setParagraphs(getParagraphs(trecJson)); return tb.build(); }
From source file:cf.client.Token.java
public static Token parseJson(InputStream json) { try {/*ww w . j a v a2s .co m*/ final JsonNode node = new ObjectMapper().readTree(json); final String accessToken = node.get("access_token").asText(); final Type type = Type.getType(node.get("token_type").asText()); final Date expiration = new Date(System.currentTimeMillis() + node.get("expires_in").asLong()); final String rawScopes = node.get("scope").asText(); final String[] splitScopes = rawScopes.split("\\s+"); final List<String> scopes = Collections.unmodifiableList(Arrays.asList(splitScopes)); final UUID jti = UUID.fromString(node.get("jti").asText()); return new Token(accessToken, type, expiration, scopes, jti); } catch (IOException e) { throw new RuntimeException(e); } }