List of usage examples for com.fasterxml.jackson.databind JsonNode asText
public abstract String asText();
From source file:com.spotify.ffwd.json.JsonObjectMapperDecoder.java
private Object decode0(ByteBuf in, List<Object> out) throws IOException, JsonProcessingException { final JsonNode tree; try (final InputStream input = new ByteBufInputStream(in)) { tree = mapper.readTree(input);//from ww w . j a v a2 s . c om } final JsonNode typeNode = tree.get("type"); if (typeNode == null) throw new IllegalArgumentException("Missing field 'type'"); final String type = typeNode.asText(); if ("event".equals(type)) return decodeEvent(tree, out); if ("metric".equals(type)) return decodeMetric(tree, out); throw new IllegalArgumentException("Invalid metric type '" + type + "'"); }
From source file:org.pentaho.metaverse.api.Namespace.java
@Override public INamespace getParentNamespace() { if (namespace != null) { try {/*w ww .j a v a 2 s . c o m*/ JsonNode jsonObject = objectMapper.readTree(namespace); JsonNode namespaceNode = jsonObject.get(DictionaryConst.PROPERTY_NAMESPACE); if (namespaceNode == null) { return null; } String parent; if (namespaceNode.isTextual()) { parent = namespaceNode.asText(); } else { parent = namespaceNode.toString(); } return new Namespace(parent); } catch (Exception e) { return null; } } return null; }
From source file:com.googlecode.jsonschema2pojo.rules.EnumRule.java
private void addEnumConstants(JsonNode node, JDefinedClass _enum) { for (Iterator<JsonNode> values = node.elements(); values.hasNext();) { JsonNode value = values.next(); if (!value.isNull()) { JEnumConstant constant = _enum.enumConstant(getConstantName(value.asText())); constant.arg(JExpr.lit(value.asText())); }/* ww w.j ava 2 s . c om*/ } }
From source file:com.facebook.api.FacebookPostActivitySerializer.java
private void addObjectName(Activity activity, JsonNode value) { activity.getObject().setDisplayName(value.asText()); }
From source file:io.gravitee.definition.jackson.datatype.api.deser.ApiDeserializer.java
@Override public Api deserialize(JsonParser jp, DeserializationContext ctxt) throws IOException { JsonNode node = jp.getCodec().readTree(jp); Api api = new Api(); JsonNode idNode = node.get("id"); if (idNode == null) { throw ctxt.mappingException("ID property is required"); } else {//from w w w . jav a 2 s.c o m api.setId(idNode.asText()); } JsonNode nameNode = node.get("name"); if (nameNode == null) { throw ctxt.mappingException("Name property is required"); } else { api.setName(nameNode.asText()); } JsonNode versionNode = node.get("version"); if (versionNode == null) { api.setVersion("undefined"); } else { api.setVersion(versionNode.asText()); } JsonNode proxyNode = node.get("proxy"); if (proxyNode != null) { api.setProxy(proxyNode.traverse(jp.getCodec()).readValueAs(Proxy.class)); } else { logger.error("A proxy property is required for {}", api.getName()); throw ctxt.mappingException("A proxy property is required for " + api.getName()); } JsonNode servicesNode = node.get("services"); if (servicesNode != null) { Services services = servicesNode.traverse(jp.getCodec()).readValueAs(Services.class); api.getServices().set(services.getAll()); } JsonNode resourcesNode = node.get("resources"); if (resourcesNode != null && resourcesNode.isArray()) { resourcesNode.elements().forEachRemaining(resourceNode -> { try { Resource resource = resourceNode.traverse(jp.getCodec()).readValueAs(Resource.class); if (!api.getResources().contains(resource)) { api.getResources().add(resource); } else { logger.error("A resource already exists with name {}", resource.getName()); throw ctxt.mappingException("A resource already exists with name " + resource.getName()); } } catch (IOException e) { e.printStackTrace(); } }); } JsonNode pathsNode = node.get("paths"); if (pathsNode != null) { final Map<String, Path> paths = new TreeMap<>( (Comparator<String>) (path1, path2) -> path2.compareTo(path1)); pathsNode.fields().forEachRemaining(jsonNode -> { try { Path path = jsonNode.getValue().traverse(jp.getCodec()).readValueAs(Path.class); path.setPath(jsonNode.getKey()); paths.put(jsonNode.getKey(), path); } catch (IOException e) { logger.error("Path {} can not be de-serialized", jsonNode.getKey()); } }); api.setPaths(paths); } JsonNode propertiesNode = node.get("properties"); if (propertiesNode != null) { Map<String, String> properties = new TemplatedValueHashMap(); propertiesNode.fields().forEachRemaining( jsonNode -> properties.put(jsonNode.getKey(), jsonNode.getValue().textValue())); api.setProperties(properties); } JsonNode tagsNode = node.get("tags"); if (tagsNode != null && tagsNode.isArray()) { tagsNode.elements().forEachRemaining(jsonNode -> api.getTags().add(jsonNode.asText())); } return api; }
From source file:com.reprezen.swagedit.validation.ErrorProcessor.java
protected String rewriteTypeError(JsonNode error) { final JsonNode found = error.get("found"); final JsonNode expected = error.get("expected"); String expect;//from w w w .j a v a2 s . com if (expected.isArray()) { expect = expected.get(0).asText(); } else { expect = expected.asText(); } return String.format(Messages.error_typeNoMatch, found.asText(), expect); }
From source file:org.apache.logging.log4j.core.config.EDNConfiguration.java
private void processAttributes(final Node parent, final JsonNode node) { final Map<String, String> attrs = parent.getAttributes(); final Iterator<Map.Entry<String, JsonNode>> iter = node.fields(); while (iter.hasNext()) { final Map.Entry<String, JsonNode> entry = iter.next(); if (!entry.getKey().equalsIgnoreCase("type")) { final JsonNode n = entry.getValue(); if (n.isValueNode()) { attrs.put(entry.getKey(), n.asText()); }//from w w w . jav a 2 s. c o m } } }
From source file:com.facebook.api.FacebookPostActivitySerializer.java
private void addSummary(Activity activity, JsonNode value) { activity.setAdditionalProperty("summary", value.asText()); }
From source file:com.facebook.api.FacebookPostActivitySerializer.java
private void addId(Activity activity, JsonNode value) { activity.setId(getActivityId(PROVIDER_NAME, value.asText())); }
From source file:com.liferay.sync.engine.documentlibrary.handler.BaseJSONHandler.java
protected String getException(String response) { ObjectMapper objectMapper = new ObjectMapper(); JsonNode responseJsonNode = null;/* w w w . ja va 2 s . c o m*/ try { response = StringEscapeUtils.unescapeJava(response); responseJsonNode = objectMapper.readTree(response); } catch (Exception e) { return ""; } JsonNode errorJsonNode = responseJsonNode.get("error"); if (errorJsonNode == null) { JsonNode exceptionJsonNode = responseJsonNode.get("exception"); if (exceptionJsonNode == null) { return ""; } return exceptionJsonNode.asText(); } JsonNode typeJsonNode = errorJsonNode.get("type"); return typeJsonNode.asText(); }