List of usage examples for com.fasterxml.jackson.databind JsonNode asText
public abstract String asText();
From source file:au.org.ands.vocabs.toolkit.db.model.Version.java
/** Get the release date. This value is stored in the data field. Note * the Transient annotation, as this is not a column in the table. * @return The release date/*from w w w . jav a 2 s. com*/ */ @Transient public String getReleaseDate() { if (data == null || data.isEmpty()) { return null; } JsonNode dataJson = TaskUtils.jsonStringToTree(data); JsonNode releaseDate = dataJson.get(RELEASE_DATE_KEY); if (releaseDate == null) { return null; } return releaseDate.asText(); }
From source file:org.walkmod.conf.entities.JSONConfigParser.java
public Map<String, Object> getParams(JsonNode next) { if (next.has("params")) { Iterator<Entry<String, JsonNode>> it2 = next.get("params").fields(); Map<String, Object> params = new HashMap<String, Object>(); while (it2.hasNext()) { Entry<String, JsonNode> param = it2.next(); JsonNode value = param.getValue(); if (value.isTextual()) { params.put(param.getKey(), value.asText()); } else if (value.isInt()) { params.put(param.getKey(), value.asInt()); } else if (value.isBoolean()) { params.put(param.getKey(), value.asBoolean()); } else if (value.isDouble() || value.isFloat() || value.isBigDecimal()) { params.put(param.getKey(), value.asDouble()); } else if (value.isLong() || value.isBigInteger()) { params.put(param.getKey(), value.asLong()); } else { params.put(param.getKey(), value); }/*from www. ja va2s . co m*/ params.put(param.getKey(), param.getValue().asText()); } return params; } return null; }
From source file:org.lendingclub.mercator.aws.ELBScanner.java
protected void addSecurityGroups(JsonNode securityGroups, String elbArn) { List<String> l = new ArrayList<>(); for (JsonNode s : securityGroups) { l.add(s.asText()); }// ww w . j av a2s . c o m String cypher = "match (x:AwsElb {aws_arn:{aws_arn}}) set x.aws_securityGroups={sg}"; getNeoRxClient().execCypher(cypher, "aws_arn", elbArn, "sg", l); }
From source file:com.ejisto.modules.factory.impl.CollectionFactory.java
private void applyExpressions(Collection<Y> in, String expression, ObjectFactory<Y> elementObjectFactory, MockedField mockedField, Collection<Y> actualValue) { if (StringUtils.isBlank(expression)) { return;//from ww w . j a va 2 s . c o m } try { final ObjectMapper mapper = new ObjectMapper(); final JsonNode root = mapper.readTree(expression.getBytes(ConfigurationManager.UTF_8)); for (JsonNode child : root) { @SuppressWarnings("unchecked") Y element = (Y) mapper.readValue(child.asText(), elementObjectFactory.getTargetClass()); in.add(element); } } catch (Exception e) { throw new ApplicationException(e); } }
From source file:com.monarchapis.driver.model.Claims.java
public boolean hasValueInClaim(String value, String... path) { Validate.notEmpty(value, "value is a required parameter"); JsonNode node = getPathNode(path); if (node.isTextual()) { return value.equals(node.asText()); } else if (node.isArray()) { ArrayNode array = (ArrayNode) node; for (Iterator<JsonNode> iter = array.iterator(); iter.hasNext();) { JsonNode item = iter.next(); if (item.isTextual() && value.equals(item.asText())) { return true; }// www .jav a 2 s . com } } return false; }
From source file:la.alsocan.jsonshapeshifter.transformations.SimpleCollectionTransformationTest.java
@Test public void partialCollectionTransformationShouldAssignDefaultValues() throws IOException { Schema source = Schema.buildSchema(new ObjectMapper().readTree(DataSet.SIMPLE_COLLECTION_SCHEMA)); Schema target = Schema.buildSchema(new ObjectMapper().readTree(DataSet.SIMPLE_COLLECTION_SCHEMA)); Transformation t = new Transformation(source, target); Iterator<SchemaNode> it = t.toBind(); it.next();/*from w w w. ja v a 2 s .c om*/ t.bind(it.next(), new ArrayNodeBinding((SchemaArrayNode) source.at("/someStringArray"))); // not binding /someIntegerArray at all (should produce empty array) JsonNode payload = new ObjectMapper().readTree(DataSet.SIMPLE_COLLECTION_PAYLOAD); JsonNode result; try { result = t.apply(payload); } catch (Exception e) { fail("Got the following exception: " + e); return; } for (int i = 0; i < 5; i++) { JsonNode node = result.at("/someStringArray/" + i); assertThat(node, is(not(nullValue()))); assertThat(node.asText(), is(equalTo(DEFAULT_STRING))); } JsonNode node = result.at("/someIntegerArray"); assertThat(node, is(not(nullValue()))); assertThat(node, is(instanceOf(ArrayNode.class))); assertThat(((ArrayNode) node).size(), is(equalTo(0))); }
From source file:com.github.jonpeterson.jackson.module.versioning.VersionedModelDeserializer.java
@Override public T deserialize(JsonParser parser, DeserializationContext context) throws IOException { JsonNode jsonNode = parser.readValueAsTree(); if (!(jsonNode instanceof ObjectNode)) throw context.mappingException("value must be a JSON object"); ObjectNode modelData = (ObjectNode) jsonNode; JsonNode modelVersionNode = modelData.remove(jsonVersionedModel.propertyName()); String modelVersion = null;//from w w w . j a va 2s. c o m if (modelVersionNode != null) modelVersion = modelVersionNode.asText(); if (modelVersion == null) modelVersion = jsonVersionedModel.defaultDeserializeToVersion(); if (modelVersion.isEmpty()) throw context.mappingException("'" + jsonVersionedModel.propertyName() + "' property was null and defaultDeserializeToVersion was not set"); // convert the model if converter specified and model needs converting if (converter != null && (jsonVersionedModel.alwaysConvert() || !modelVersion.equals(jsonVersionedModel.currentVersion()))) modelData = converter.convert(modelData, modelVersion, jsonVersionedModel.currentVersion(), context.getNodeFactory()); // set the serializeToVersionProperty value to the source model version if the defaultToSource property is true if (serializeToVersionAnnotation != null && serializeToVersionAnnotation.defaultToSource()) modelData.put(serializeToVersionProperty.getName(), modelVersion); JsonParser postInterceptionParser = new TreeTraversingParser(modelData, parser.getCodec()); postInterceptionParser.nextToken(); return delegate.deserialize(postInterceptionParser, context); }
From source file:org.lendingclub.mercator.aws.ELBScanner.java
protected void mapElbToSubnet(JsonNode subnets, String elbArn, String region) { for (JsonNode s : subnets) { String subnetName = s.asText(); String subnetArn = String.format("arn:aws:ec2:%s:%s:subnet/%s", region, getAccountId(), subnetName); String cypher = "match (x:AwsElb {aws_arn:{elbArn}}), (y:AwsSubnet {aws_arn:{subnetArn}}) " + "merge (x)-[r:AVAILABLE_IN]->(y) set r.updateTs=timestamp()"; getNeoRxClient().execCypher(cypher, "elbArn", elbArn, "subnetArn", subnetArn); }//from www .j ava2s . c o m }
From source file:com.cloudmine.api.persistance.CMJacksonModule.java
public CMJacksonModule() { super("CustomModule", new Version(1, 0, 0, null)); addSerializer(new JsonSerializer<Date>() { @Override/*from w w w. jav a2 s. co m*/ public void serialize(Date value, JsonGenerator jgen, SerializerProvider provider) throws IOException, JsonProcessingException { jgen.writeStartObject(); jgen.writeRaw(JsonUtilities.convertDateToUnwrappedJsonClass(value)); jgen.writeEndObject(); } @Override public Class<Date> handledType() { return Date.class; } }); addDeserializer(Date.class, new JsonDeserializer<Date>() { @Override public Date deserialize(JsonParser jp, DeserializationContext ctxt) throws IOException, JsonProcessingException { ObjectMapper mapper = (ObjectMapper) jp.getCodec(); ObjectNode root = (ObjectNode) mapper.readTree(jp); JsonNode classNode = root.get(JsonUtilities.CLASS_KEY); boolean isDate = classNode != null && JsonUtilities.DATE_CLASS.equals(classNode.asText()); if (isDate) { JsonNode timeNode = root.get(JsonUtilities.TIME_KEY); if (timeNode != null) { Long seconds = timeNode.asLong(); Date date = new Date(seconds * 1000); return date; } } return null; } }); addSerializer(new JsonSerializer<SimpleCMObject>() { @Override public void serialize(SimpleCMObject value, JsonGenerator jgen, SerializerProvider provider) throws IOException { jgen.writeStartObject(); String json = null; try { json = value.asUnkeyedObject(); } catch (ConversionException e) { LOG.error("Error while serializing, sending empty json", e); json = JsonUtilities.EMPTY_JSON; } jgen.writeRaw(JsonUtilities.unwrap(json)); jgen.writeEndObject(); } @Override public Class<SimpleCMObject> handledType() { return SimpleCMObject.class; } }); addSerializer(jsonSerializerForType(CMFile.class)); addSerializer(jsonSerializerForType(CMSessionToken.class)); addSerializer(jsonSerializerForType(CMType.class)); addSerializer(jsonSerializerForType(TransportableString.class)); addSerializer(jsonSerializerForType(ResponseBase.class)); }
From source file:org.forgerock.openig.migrate.action.InlineDeclarationsAction.java
@Override protected ObjectNode doMigrate(final RouteModel route, final ObjectNode configuration) { ArrayNode heap = (ArrayNode) configuration.get("heap"); // Creates references for (ObjectModel source : route.getObjects()) { for (String pointer : source.getType().getPatterns()) { PathVisitor visitor = new PathVisitor(Pattern.compile(pointer)); new NodeTraversal().traverse(source.getConfig(), visitor); for (PathVisitor.Match match : visitor.getMatches()) { JsonNode pointed = match.getNode(); if (pointed.isArray()) { int i = 0; for (JsonNode item : pointed) { bindArrayReference(source, route.findObject(item.asText()), match.getPointer(), i++); }//w ww .j a v a 2s . com } else if (pointed.isTextual()) { bindReference(source, route.findObject(pointed.asText()), match.getPointer()); } } } } // Inline references as much as possible, starting from the leafs // TODO Consider Moving all candidates at once, this is probably not useful to process them step by step List<ObjectModel> candidates = findCandidates(route); while (!candidates.isEmpty()) { for (ObjectModel candidate : candidates) { Reference ref = candidate.getReferencedBy().get(0); if (ref.isArrayRef()) { ArrayNode array = (ArrayNode) ref.getSource().getConfig().at(ref.getPointer()); array.set(ref.getIndex(), ref.getTarget().getNode()); } else { // We'll just replace in place the value ObjectNode parent = (ObjectNode) ref.getSource().getConfig().at(parentOf(ref.getPointer())); parent.replace(lastSegmentOf(ref.getPointer()), ref.getTarget().getNode()); } ref.getSource().getReferencesTo().remove(ref); ref.getTarget().getReferencedBy().remove(ref); ref.getTarget().markInlined(); } candidates = findCandidates(route); } // Remove inlined references, Java 8 style Iterator<ObjectModel> iterator = route.getObjects().stream().filter(inlined()).sorted(byReverseIndex()) .iterator(); while (iterator.hasNext()) { ObjectModel next = iterator.next(); heap.remove(next.getIndex()); } return configuration; }