List of usage examples for com.fasterxml.jackson.databind JsonNode textValue
public String textValue()
From source file:org.apache.olingo.fit.utils.JSONUtilities.java
@Override public Map.Entry<String, List<String>> extractLinkURIs(final InputStream is) throws IOException { final ObjectNode srcNode = (ObjectNode) mapper.readTree(is); IOUtils.closeQuietly(is);/*from ww w .jav a 2 s.c om*/ final List<String> links = new ArrayList<String>(); JsonNode uris = srcNode.get("value"); if (uris == null) { final JsonNode url = srcNode.get("url"); if (url != null) { links.add(url.textValue()); } } else { final Iterator<JsonNode> iter = ((ArrayNode) uris).iterator(); while (iter.hasNext()) { links.add(iter.next().get("url").textValue()); } } final JsonNode next = srcNode.get(Constants.get(ConstantKey.JSON_NEXTLINK_NAME)); return new SimpleEntry<String, List<String>>(next == null ? null : next.asText(), links); }
From source file:com.sitewhere.server.asset.scim.Wso2ScimAssetModule.java
/** * Parse the JSON branch that holds a SCIM resource. * //from w w w .j a va 2 s.c o m * @param resource * @return */ protected PersonAsset parse(JsonNode resource) throws SiteWhereException { PersonAsset asset = new PersonAsset(); JsonNode id = resource.get(IScimFields.ID); if (id == null) { throw new SiteWhereException("SCIM resource does not have an id."); } asset.setProperty(IWso2ScimFields.PROP_ASSET_ID, id.textValue()); JsonNode username = resource.get(IScimFields.USERNAME); if (username != null) { asset.setProperty(IWso2ScimFields.PROP_USERNAME, username.textValue()); } JsonNode profileUrl = resource.get(IScimFields.PROFILE_URL); if (profileUrl != null) { asset.setProperty(IWso2ScimFields.PROP_PROFILE_URL, profileUrl.textValue()); } parseName(resource, asset); parseEmail(resource, asset); asset.setId(IWso2ScimFields.PROP_ASSET_ID); asset.setName(IWso2ScimFields.PROP_NAME); asset.setEmailAddress(IWso2ScimFields.PROP_EMAIL_ADDRESS); asset.setUserName(IWso2ScimFields.PROP_USERNAME); asset.setPhotoUrl(IWso2ScimFields.PROP_PROFILE_URL); return asset; }
From source file:com.collaborne.jsonschema.generator.pojo.PojoStringGenerator.java
@Override protected void generateType(PojoCodeGenerationContext context, SchemaTree schema, JavaWriter writer) throws IOException, CodeGenerationException { JsonNode enumValues = schema.getNode().get("enum"); if (!enumValues.isArray()) { throw new CodeGenerationException(context.getType(), "Expected 'array' for 'enum', but have " + enumValues); }/* ww w . jav a 2 s . co m*/ ClassName wantedGeneratedClassName = context.getMapping().getGeneratedClassName(); EnumGenerator enumGenerator; Kind enumStyle = context.getMapping().getEnumStyle(); if (enumStyle == null) { enumStyle = context.getGenerator().getFeature(PojoGenerator.FEATURE_ENUM_STYLE); } switch (enumStyle) { case CLASS: enumGenerator = new ClassEnumGenerator(wantedGeneratedClassName); break; case ENUM: enumGenerator = new EnumEnumGenerator(wantedGeneratedClassName); break; default: throw new CodeGenerationException(context.getType(), new IllegalArgumentException("Invalid enum style: " + enumStyle)); } enumGenerator.generateImports(writer); writeSchemaDocumentation(schema, writer); writer.writeClassStart(wantedGeneratedClassName, context.getMapping().getExtends(), context.getMapping().getImplements(), enumStyle, Visibility.PUBLIC); try { for (JsonNode enumValue : enumValues) { if (!enumValue.isTextual()) { throw new CodeGenerationException(context.getType(), "Expected textual 'enum' values, but have " + enumValue); } String value = enumValue.textValue(); enumGenerator.generateEnumValue(value, writer); } enumGenerator.generateAdditionalCode(writer); } finally { writer.writeClassEnd(); } }
From source file:com.qwazr.crawler.web.driver.BrowserDriver.java
public String getErrorMessage(Exception error) { if (error == null) return null; String msg = error.getMessage(); if (msg == null) msg = error.toString();/* www. j a v a 2 s . c om*/ if (msg == null) return error.getClass().getName(); if (!msg.startsWith("{")) return msg; try { JsonNode json = JsonMapper.MAPPER.readTree(msg); JsonNode jsonMsg = json.get("errorMessage"); if (jsonMsg != null && jsonMsg.isTextual()) return jsonMsg.textValue(); jsonMsg = json.get("error"); if (jsonMsg != null && jsonMsg.isTextual()) return jsonMsg.textValue(); return msg; } catch (IOException e) { return msg; } }
From source file:org.apache.olingo.fit.utils.AbstractJSONUtilities.java
@Override public Map.Entry<String, List<String>> extractLinkURIs(final InputStream is) throws Exception { final ObjectMapper mapper = new ObjectMapper(); final ObjectNode srcNode = (ObjectNode) mapper.readTree(is); IOUtils.closeQuietly(is);/*from w ww. j a v a 2 s .c o m*/ final List<String> links = new ArrayList<String>(); JsonNode uris = srcNode.get("value"); if (uris == null) { final JsonNode url = srcNode.get("url"); if (url != null) { links.add(url.textValue()); } } else { final Iterator<JsonNode> iter = ((ArrayNode) uris).iterator(); while (iter.hasNext()) { links.add(iter.next().get("url").textValue()); } } final JsonNode next = srcNode.get(JSON_NEXTLINK_NAME); return new SimpleEntry<String, List<String>>(next == null ? null : next.asText(), links); }
From source file:de.dfki.kiara.jsonrpc.JsonRpcMessage.java
public JsonRpcMessage(JsonRpcProtocol protocol, JsonNode node) throws IOException { this.body = node; if (this.body == null) { throw new IOException("Not a jsonrpc protocol"); }//from w w w. ja va 2s. c o m JsonNode jsonrpcNode = body.get("jsonrpc"); if (jsonrpcNode == null || !jsonrpcNode.isTextual()) { throw new IOException("Not a jsonrpc protocol"); } if (!"2.0".equals(jsonrpcNode.textValue())) { throw new IOException("Not a jsonrpc 2.0"); } JsonNode methodNode = body.get("method"); if (methodNode != null) { if (!methodNode.isTextual()) { throw new IOException("Member 'method' in request object is not a string"); } this.kind = Message.Kind.REQUEST; this.methodName = methodNode.textValue(); this.params = body.get("params"); this.id = parseMessageId(body); } else { JsonNode resultNode = body.get("result"); JsonNode errorNode = body.get("error"); if (resultNode == null && errorNode == null) { throw new IOException("Neither 'method' nor 'error' nor 'result' member in the object"); } this.methodName = null; if (resultNode != null) { this.kind = Kind.RESPONSE; this.params = resultNode; this.error = null; } else { this.kind = Kind.EXCEPTION; this.error = errorNode; this.params = errorNode.get("data"); JsonRpcError jsonRpcError = protocol.getObjectReader().treeToValue(errorNode, JsonRpcError.class); this.response = new Message.ResponseObject(new GenericRemoteException(jsonRpcError.getMessage(), jsonRpcError.getCode(), jsonRpcError.getData()), true); } this.id = parseMessageId(body); } this.requestMessage = null; this.protocol = protocol; }
From source file:org.apache.usergrid.android.sdk.entities.Entity.java
/** * Gets the String value of the specified Entity property. * @param name the name of the property * @return the property value. Returns null if the property has no value *///from ww w.j a v a 2 s .c o m public String getStringProperty(String name) { JsonNode val = this.properties.get(name); return val != null ? val.textValue() : null; }
From source file:com.github.fge.jsonschema.core.keyword.syntax.checkers.SyntaxCheckersTest.java
@DataProvider protected final Iterator<Object[]> getValueTests() { if (valueTests.isMissingNode()) return Iterators.emptyIterator(); final List<Object[]> list = Lists.newArrayList(); String msg;/* ww w. j a v a 2 s . co m*/ JsonNode msgNode; JsonNode msgParams; JsonNode msgData; for (final JsonNode node : valueTests) { msgNode = node.get("message"); msgParams = node.get("msgParams"); msgData = node.get("msgData"); msg = msgNode == null ? null : buildMessage(msgNode.textValue(), msgParams, msgData); list.add(new Object[] { node.get("schema"), msg, node.get("valid").booleanValue(), msgData }); } return list.iterator(); }