List of usage examples for com.fasterxml.jackson.databind JsonNode asText
public abstract String asText();
From source file:org.walkmod.conf.providers.yml.AddModulesYMLAction.java
@Override public void doAction(JsonNode node) throws Exception { ArrayNode aux = null;//ww w . j av a 2 s .c o m HashSet<String> modulesToAdd = new HashSet<String>(modules); if (node.has("modules")) { JsonNode list = node.get("modules"); Iterator<JsonNode> it = list.iterator(); while (it.hasNext()) { JsonNode next = it.next(); modulesToAdd.remove(next.asText().trim()); } if (!modulesToAdd.isEmpty()) { if (list.isArray()) { aux = (ArrayNode) list; } } } else { aux = new ArrayNode(provider.getObjectMapper().getNodeFactory()); } if (!modulesToAdd.isEmpty()) { for (String moduleToAdd : modulesToAdd) { TextNode prov = new TextNode(moduleToAdd); aux.add(prov); } ObjectNode auxNode = (ObjectNode) node; auxNode.set("modules", aux); provider.write(node); } }
From source file:com.forgerock.wisdom.oauth2.info.internal.OpenAmIntrospectionService.java
@Override public TokenInfo introspect(final String token) { String tokenInfoRequest = format("%s/oauth2/tokeninfo?access_token=%s&realm=%s", baseUrl, token, realm); try {//w w w .ja v a2s.c o m HttpURLConnection connection = (HttpURLConnection) new URL(tokenInfoRequest).openConnection(); int code = connection.getResponseCode(); if (code != 200) { return TokenInfo.INVALID; } try (InputStream stream = connection.getInputStream()) { JsonNode node = mapper.readTree(stream); List<String> scopes = new ArrayList<>(); for (JsonNode scope : node.get("scope")) { scopes.add(scope.asText()); } long expiresIn = node.get("expires_in").asLong(); return new TokenInfo(true, expiresIn, scopes); } } catch (IOException e) { return TokenInfo.INVALID; } }
From source file:com.redhat.lightblue.util.test.AbstractJsonNodeTest.java
public boolean textNodesHaveSameValue(JsonNode expected, JsonNode actual) { return expected.asText().equals(actual.asText()); }
From source file:com.aol.one.patch.testobj.PatchTestObject.java
public void addStrField(JsonNode node) { this.strField = strField + node.asText(); }
From source file:com.sg2net.utilities.ListaCAP.json.ComuneDeserializer.java
@Override public Comune deserialize(JsonParser jsonParser, DeserializationContext deserializationContext) throws IOException, JsonProcessingException { ObjectMapper mapper = (ObjectMapper) jsonParser.getCodec(); ObjectNode root = (ObjectNode) mapper.readTree(jsonParser); JsonNode codiceIstatNode = root.get("codiceIstat"); String codiceIstat = codiceIstatNode.asText(); JsonNode codiceCatastaleNode = root.get("codiceCatastale"); String codiceCatastale = codiceCatastaleNode.asText(); JsonNode nomeNode = root.get("nome"); String nome = nomeNode.asText(); JsonNode provinciaNode = root.get("provincia"); String provincia = provinciaNode.asText(); JsonNode codiciCapNode = root.get("codiciCap"); Collection<String> codiciCap = new ArrayList<>(); Iterator<JsonNode> capNodes = codiciCapNode.elements(); while (capNodes.hasNext()) { JsonNode codiceCapNode = capNodes.next(); String codiceCap = codiceCapNode.asText(); codiciCap.add(codiceCap);//from ww w. j a va 2s . c o m } Comune comune = new Comune(codiceIstat, codiceCatastale, nome, provincia); comune.setCodiciCap(codiciCap); logger.trace("comune =" + comune + " deserializzato from json"); return comune; }
From source file:io.gravitee.definition.jackson.datatype.api.deser.HttpProxyDeserializer.java
private String readStringValue(JsonNode rootNode, String fieldName) { JsonNode fieldNode = rootNode.get(fieldName); if (fieldNode != null) { return fieldNode.asText(); }//from w w w . ja v a2 s .co m return null; }
From source file:la.alsocan.jsonshapeshifter.transformations.HandlebarsBindingTransformationTest.java
@Test public void staticHandlebarsBindingShouldProduceRightResult() 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); String template = "Hello {{world}}"; Map<String, Binding> params = new HashMap<>(); params.put("world", new StringConstantBinding("world")); Iterator<SchemaNode> it = t.toBind(); t.bind(it.next(), new StringHandlebarsBinding(template, params)); JsonNode payload = new ObjectMapper().readTree(DataSet.SIMPLE_COLLECTION_PAYLOAD); JsonNode result = t.apply(payload);/* w w w . j a va 2 s . c o m*/ JsonNode node = result.at("/someString"); assertThat(node.asText(), is(equalTo("Hello world"))); }
From source file:com.redhat.lightblue.metadata.types.StringType.java
@Override public Object fromJson(JsonNode node) { if (node.isValueNode()) { return node.asText(); } else {/*from w w w. j a va 2 s . c o m*/ throw Error.get(NAME, MetadataConstants.ERR_INCOMPATIBLE_VALUE, node.toString()); } }
From source file:io.appform.jsonrules.expressions.string.EmptyExpression.java
@Override protected boolean evaluate(ExpressionEvaluationContext context, String path, JsonNode evaluatedNode) { if (!evaluatedNode.isTextual()) { return false; }/*from w w w . j a va2 s. com*/ final String data = evaluatedNode.asText(); return null == data || data.isEmpty(); }
From source file:io.appform.jsonrules.expressions.string.NotEmptyExpression.java
@Override protected boolean evaluate(ExpressionEvaluationContext context, String path, JsonNode evaluatedNode) { if (!evaluatedNode.isTextual()) { return false; }/* w w w .j a va2 s .com*/ final String data = evaluatedNode.asText(); return null != data && !data.isEmpty(); }