List of usage examples for com.fasterxml.jackson.databind JsonNode get
public JsonNode get(String paramString)
From source file:controllers.Reconcile.java
private static String buildQueryString(Entry<String, JsonNode> entry) { String queryString = entry.getValue().get("query").asText(); JsonNode props = entry.getValue().get("properties"); if (props != null) { for (JsonNode p : props) { queryString += " " + p.get("v").asText(); }/*from w w w . j a v a2s .com*/ } return queryString; }
From source file:org.apache.solr.kelvin.SingletonConditionRegistry.java
public static ICondition instantiate(JsonNode conf) throws Exception { String type = ""; if (conf.has("type")) type = conf.get("type").asText(); //legacy/* ww w . j av a 2 s . c om*/ if (conf.has("mode")) type = conf.get("mode").asText(); ICondition ret = registry.instantiate(type); ret.configure(conf); return ret; }
From source file:com.ibm.watson.catalyst.corpus.tfidf.Template.java
public static Pattern getTemplatePattern(JsonNode document, String before, String after) { JsonNode terms = document.get("words"); List<String> words = new ArrayList<String>(); for (JsonNode termNode : terms) { if (termNode.get("frequency").asInt() < 5) continue; if (termNode.get("string").asText().length() < 2) continue; Term t = new Term(termNode); words.add(t.getTerm());// ww w .ja v a2s .co m } StringBuffer sb = new StringBuffer(""); sb.append(before).append(makeOr(words)).append(after); Pattern p = Pattern.compile(sb.toString(), Pattern.CASE_INSENSITIVE); return p; }
From source file:eu.trentorise.opendata.jackan.ckan.CkanError.java
/** * To overcome the __type problem. Tried many combinations but Jackson is * not collaborating here, even if in Group.isOrganization case setting the * JsonProperty("is_organization") did work. *//*from w w w.j a va 2 s . c o m*/ static CkanError read(String json) { try { CkanError ce = new CkanError(); JsonNode jn = CkanClient.getObjectMapper().readTree(json); ce.setMessage(jn.get("message").asText()); ce.setType(jn.get("__type").asText()); return ce; } catch (IOException ex) { throw new JackanException("Couldn parse CkanError.", ex); } }
From source file:io.github.robwin.swagger.loader.Swagger20Parser.java
private static Swagger convertToSwagger(String data) throws IOException { ObjectMapper mapper;//from w w w . j a va 2 s . c o m if (data.trim().startsWith("{")) { mapper = Json.mapper(); } else { mapper = Yaml.mapper(); } JsonNode rootNode = mapper.readTree(data); // must have swagger node set JsonNode swaggerNode = rootNode.get("swagger"); if (swaggerNode == null) { throw new IllegalArgumentException("Swagger String has an invalid format."); } else { return mapper.convertValue(rootNode, Swagger.class); } }
From source file:org.springframework.social.facebook.api.impl.PagedListUtils.java
public static PagingParameters getPagedListParameters(JsonNode pagingNode, String pageKey) { if (pagingNode == null || pagingNode.get(pageKey) == null) { return null; }//from w w w. j a v a 2 s . c o m String pageNode = pagingNode.get(pageKey).textValue(); String limitString = extractParameterValueFromUrl(pageNode, "limit"); String sinceString = extractParameterValueFromUrl(pageNode, "since"); String untilString = extractParameterValueFromUrl(pageNode, "until"); String offsetString = extractParameterValueFromUrl(pageNode, "offset"); String after = extractEncodedParameterValueFromUrl(pageNode, "after"); String before = extractEncodedParameterValueFromUrl(pageNode, "before"); return new PagingParameters(limitString != null ? Integer.valueOf(limitString) : null, offsetString != null ? Integer.valueOf(offsetString) : null, sinceString != null ? Long.valueOf(sinceString) : null, untilString != null ? Long.valueOf(untilString) : null, after, before); }
From source file:la.alsocan.jsonshapeshifter.schemas.SchemaNode.java
protected static final SchemaNode buildSchemaNode(JsonNode node, String name, String path, boolean required) { switch (node.get("type") != null ? node.get("type").asText() : "?") { case "object": return new SchemaObjectNode(name, path, required).withResolvedChildren(node); case "array": return new SchemaArrayNode(name, path, required).withResolvedChild(node); case "string": return new SchemaNode(name, path, ENodeType.STRING, required); case "integer": return new SchemaNode(name, path, ENodeType.INTEGER, required); case "number": return new SchemaNode(name, path, ENodeType.NUMBER, required); case "boolean": return new SchemaNode(name, path, ENodeType.BOOLEAN, required); case "null": return new SchemaNode(name, path, ENodeType.NULL, required); default:/*from w w w. j ava 2 s . c o m*/ throw new UnsupportedJsonSchemaException("Unknown type for element '" + path + "'"); } }
From source file:org.jboss.aerogear.webpush.standalone.ConfigReader.java
private static WebPushServerConfig parseWebPushProperties(final JsonNode json) { final JsonNode host = json.get("host"); final JsonNode port = json.get("port"); final Builder builder = DefaultWebPushConfig.create(host.asText(), port.asInt()); final JsonNode password = json.get("password"); if (password != null) { builder.password(password.asText()); }//www .j a va 2s . c om final JsonNode cert = json.get("cert"); if (cert != null) { builder.cert(cert.asText()); } final JsonNode privateKey = json.get("privateKey"); if (privateKey != null) { builder.privateKey(privateKey.asText()); } final JsonNode endpointHost = json.get("endpoint-host"); if (endpointHost != null) { builder.endpointHost(endpointHost.asText()); } final JsonNode endpointPort = json.get("endpoint-port"); if (endpointPort != null) { builder.endpointPort(endpointPort.asInt()); } final JsonNode endpointTls = json.get("endpoint-tls"); if (endpointTls != null) { builder.endpointTls(endpointTls.asBoolean()); } final JsonNode subscriptionMaxAge = json.get("subscription-max-age"); if (subscriptionMaxAge != null) { builder.subscriptionMaxAge(subscriptionMaxAge.asLong()); } return builder.build(); }
From source file:com.reprezen.swagedit.validation.ValidationUtil.java
public static int getLine(JsonNode error, Node yamlTree) { if (!error.has("instance") || !error.get("instance").has("pointer")) return 1; String path = error.get("instance").get("pointer").asText(); if (path == null || path.isEmpty()) return 1; path = path.substring(1, path.length()); String[] strings = path.split("/"); if (yamlTree instanceof MappingNode) { MappingNode mn = (MappingNode) yamlTree; Node findNode = findNode(mn, Arrays.asList(strings)); if (findNode != null) { return findNode.getStartMark().getLine() + 1; }//from w ww . j a v a2 s . c o m } return 1; }
From source file:com.attribyte.essem.StatsParser.java
/** * Parses a stats response./*from w w w. j a v a 2s . co m*/ * @param esObject The ES response object. * @return The parsed stats. */ public static Stats parseStats(ObjectNode esObject, RateUnit rateUnit) { //This assumes the "extended stats" aggregation. JsonNode aggregations = esObject.get("aggregations"); if (aggregations != null) { JsonNode stats = aggregations.get("stats"); if (stats != null) { Stats newStats = new Stats(getIntField(stats, "count", 0), getDoubleField(stats, "min", 0.0), getDoubleField(stats, "max", 0.0), getDoubleField(stats, "avg", 0.0), getDoubleField(stats, "sum", 0.0), getDoubleField(stats, "sum_of_squares", 0.0), getDoubleField(stats, "variance", 0.0), getDoubleField(stats, "std_deviation", 0.0)); return rateUnit != null ? newStats.scale(rateUnit.mult) : newStats; } else { return Stats.EMPTY_STATS; } } else { return Stats.EMPTY_STATS; } }