List of usage examples for com.fasterxml.jackson.databind JsonNode asText
public abstract String asText();
From source file:org.lendingclub.mercator.aws.LaunchConfigScanner.java
protected List<String> getSecurityGroups(LaunchConfiguration c) { List<String> toReturnList = new ArrayList<>(); JsonNode n = new ObjectMapper().valueToTree(c); JsonNode securityGroups = n.path("securityGroups"); for (JsonNode sg : securityGroups) { toReturnList.add(sg.asText()); }//from www .ja va 2 s .c o m return toReturnList; }
From source file:org.createnet.raptor.models.objects.Channel.java
public void parse(JsonNode json) { if (json.isTextual()) { type = json.asText(); } else {/* w ww.j a v a2 s .c om*/ if (json.has("name")) { name = json.get("name").asText(); } if (json.has("type")) { type = json.get("type").asText(); } if (json.has("unit")) { unit = json.get("unit").asText(); } } }
From source file:org.fcrepo.camel.reindexing.RestProcessor.java
/** * Convert the incoming REST request into the correct * Fcrepo header fields./*w ww. j a va2 s . com*/ * * @param exchange the current message exchange */ public void process(final Exchange exchange) throws Exception { final Message in = exchange.getIn(); final String path = in.getHeader(Exchange.HTTP_PATH, "", String.class); final String contentType = in.getHeader(Exchange.CONTENT_TYPE, "", String.class); final String body = in.getBody(String.class); final Set<String> endpoints = new HashSet<>(); for (final String s : in.getHeader(ReindexingHeaders.RECIPIENTS, "", String.class).split(",")) { endpoints.add(s.trim()); } in.removeHeaders("CamelHttp*"); in.removeHeader("JMSCorrelationID"); in.setBody(null); if (contentType.equals("application/json") && body != null && !body.trim().isEmpty()) { final ObjectMapper mapper = new ObjectMapper(); try { final JsonNode root = mapper.readTree(body); final Iterator<JsonNode> ite = root.elements(); while (ite.hasNext()) { final JsonNode n = ite.next(); endpoints.add(n.asText()); } } catch (JsonProcessingException e) { LOGGER.debug("Invalid JSON", e); in.setHeader(Exchange.HTTP_RESPONSE_CODE, BAD_REQUEST); in.setBody("Invalid JSON"); } } in.setHeader(FcrepoHeaders.FCREPO_IDENTIFIER, path); in.setHeader(ReindexingHeaders.RECIPIENTS, String.join(",", endpoints)); }
From source file:org.calrissian.mango.json.deser.TupleDeserializer.java
@Override public Tuple deserialize(JsonParser jsonParser, DeserializationContext deserializationContext) throws IOException { JsonNode root = jsonParser.getCodec().readTree(jsonParser); String key = root.get("key").asText(); Object value = null;// w ww. ja v a2s. c om JsonNode type_json = root.get("type"); if (type_json != null) { String type = type_json.asText(); String val_str = root.get("value").asText(); value = typeRegistry.decode(type, val_str); } Map<String, Object> metadata = new HashMap<>(); JsonNode metadataArray = root.get("metadata"); if (metadataArray != null) { for (JsonNode metadataItem : metadataArray) { String metaKey = metadataItem.get("key").asText(); String alias = metadataItem.get("type").asText(); String normalized = metadataItem.get("value").asText(); metadata.put(metaKey, typeRegistry.decode(alias, normalized)); } } return new Tuple(key, value, metadata); }
From source file:io.gravitee.definition.jackson.datatype.api.deser.LoadBalancerDeserializer.java
@Override public LoadBalancer deserialize(JsonParser jp, DeserializationContext ctxt) throws IOException { JsonNode node = jp.getCodec().readTree(jp); LoadBalancer loadBalancer = new LoadBalancer(); final JsonNode typeNode = node.get("type"); if (typeNode != null) { loadBalancer.setType(LoadBalancerType.valueOf(typeNode.asText().toUpperCase())); }// w ww .j av a2 s . co m return loadBalancer; }
From source file:com.redhat.lightblue.crud.validator.MatchesChecker.java
@Override public void checkConstraint(ConstraintValidator validator, FieldTreeNode fieldMetadata, Path fieldMetadataPath, FieldConstraint constraint, Path valuePath, JsonDoc doc, JsonNode fieldValue) { Pattern pattern = ((MatchesConstraint) constraint).getValue(); Matcher matcher = pattern.matcher(fieldValue.asText()); if (!"".equals(fieldValue.asText()) && !matcher.matches()) { validator.addDocError(Error.get(CrudConstants.ERR_INVALID_ENTITY, fieldValue.asText())); }//from w w w . j a va 2 s. co m }
From source file:com.hortonworks.pso.data.generator.fields.StringField.java
public StringField(JsonNode node) { super(node);/*w w w . j a v a2s . c om*/ if (node.has("random")) { JsonNode rNode = node.get("random"); if (rNode.get("min") != null) min = rNode.get("min").asInt(); if (rNode.get("max") != null) max = rNode.get("max").asInt(); if (min < max) diff = Math.abs(max - min); if (rNode.get("chars") != null) { charStr = rNode.get("chars").asText(); } if (rNode.get("pool") != null) { // size is required poolSize = rNode.get("pool").get("size").asInt(); fillPool(); } } else if (node.has("set")) { JsonNode setNode = node.get("set"); type = TYPE.SET; set = new String[setNode.size()]; int i = 0; for (Iterator<JsonNode> it = setNode.elements(); it.hasNext();) { JsonNode element = it.next(); set[i++] = element.asText(); } } }
From source file:alpine.json.TrimmedStringArrayDeserializer.java
@Override public String[] deserialize(JsonParser jsonParser, DeserializationContext context) throws IOException { final List<String> list = new ArrayList<>(); final JsonNode node = jsonParser.readValueAsTree(); if (node.isArray()) { final Iterator elements = node.elements(); while (elements.hasNext()) { final JsonNode childNode = (JsonNode) elements.next(); final String value = StringUtils.trimToNull(childNode.asText()); if (value != null) { list.add(value);//from www .j av a2 s . c om } } } if (list.size() == 0) { return null; } else { return list.toArray(new String[list.size()]); } }
From source file:org.createnet.raptor.models.data.types.StringRecord.java
@Override public String parseValue(Object value) { try {/*from w w w . ja va 2 s . co m*/ if (value instanceof String) { return (String) value; } if (value instanceof JsonNode) { JsonNode node = (JsonNode) value; if (node.isTextual()) return node.asText(); if (node.isNumber()) return node.asText(); } return (String) value; } catch (Exception e) { throw new RaptorComponent.ParserException(e); } }
From source file:com.pros.jsontransform.expression.FunctionAppendTest.java
@Test public void test() throws ObjectTransformerException, JsonProcessingException, IOException { JsonNode object = mapper/* www . ja v a 2s .c o m*/ .readTree("{" + " \"value\":\"hello\"," + " \"args\":{\"$what\":\" world\"}" + "}"); JsonNode result = FunctionAppend.evaluate(object.get("args"), object.get("value"), transformer); assertEquals("wrong result", "hello world", result.asText()); }