List of usage examples for com.fasterxml.jackson.databind JsonNode asText
public abstract String asText();
From source file:com.vmware.admiral.closures.util.ClosureUtils.java
private static JsonElement getPrimitiveJsonElement(JsonNode node) { if (node.isNull()) { return JsonNull.INSTANCE; } else if (node.isNumber()) { return new JsonPrimitive(node.numberValue()); }/*from www. java 2 s.c om*/ com.google.gson.JsonParser parser = new com.google.gson.JsonParser(); return parser.parse(node.asText()); }
From source file:com.helger.wsdlgen.exchange.InterfaceReader.java
@Nonnull private static WGTypeDef _readTypeDef(final WGInterface aInterface, final String sTypeChildName, final JsonNode aTypeChildNode) { if (aTypeChildNode.isTextual()) { // type only - no details final String sChildTypeName = aTypeChildNode.asText(); final IWGType aChildType = aInterface.getTypeOfName(sChildTypeName); if (aChildType == null) throw new IllegalArgumentException( "Property '" + sTypeChildName + "' has invalid type '" + sChildTypeName + "'"); return new WGTypeDef(aChildType); }//from www .jav a 2 s. c o m // All details final ObjectNode aType = (ObjectNode) aTypeChildNode; final String sChildTypeName = _getChildAsText(aType, "$type"); final IWGType aChildType = aInterface.getTypeOfName(sChildTypeName); if (aChildType == null) throw new IllegalArgumentException( "Property '" + sTypeChildName + "' has invalid type '" + sChildTypeName + "'"); final WGTypeDef aTypeDef = new WGTypeDef(aChildType); aTypeDef.setDocumentation(_getDocumentation(_getChildAsText(aType, "$doc"))); aTypeDef.setMin(_getChildAsText(aType, "$min")); aTypeDef.setMax(_getChildAsText(aType, "$max")); aTypeDef.setDefault(_getChildAsText(aType, "$default")); aTypeDef.setOptional(_getTriState(aType, "$optional")); return aTypeDef; }
From source file:com.gsma.mobileconnect.utils.AndroidJsonUtils.java
/** * Parse the UserInfo object./*from w ww. j a v a 2 s . com*/ * @param response * @return */ public static UserInfo parseUserInfo(String response) { UserInfo userInfo = new UserInfo(); ObjectMapper objectMapper = new ObjectMapper(); JsonNode jsonDoc = null; try { jsonDoc = objectMapper.readTree(response); Log.d(TAG, jsonDoc.asText()); } catch (IOException e) { e.printStackTrace(); } ErrorResponse errorResponse = getErrorResponse(jsonDoc); if (null != errorResponse) { return null; } return userInfo; }
From source file:org.waarp.common.json.JsonHandler.java
/** * //from w w w . jav a2s .c o m * @param node * @param field * @param defValue * @return the String if the field exists, else defValue */ public final static String getValue(ObjectNode node, String field, String defValue) { JsonNode elt = node.get(field); if (elt != null) { String val = elt.asText(); if (val.equals("null")) { return defValue; } return val; } return defValue; }
From source file:com.baasbox.controllers.Root.java
@With({ RootCredentialWrapFilter.class, ConnectToDBFilter.class }) public static Result resetAdminPassword() { Http.RequestBody body = request().body(); JsonNode bodyJson = body.asJson();//from ww w . ja v a 2s .c o m if (BaasBoxLogger.isDebugEnabled()) BaasBoxLogger.debug("resetAdminPassword bodyJson: " + bodyJson); //check and validate input if (bodyJson == null) return badRequest("The body payload cannot be empty."); if (!bodyJson.has("password")) return badRequest("The 'password' field is missing into the body"); JsonNode passwordNode = bodyJson.findValue("password"); if (passwordNode == null) return badRequest("The body payload doesn't contain password field"); String password = passwordNode.asText(); try { UserService.changePassword("admin", password); } catch (SqlInjectionException e) { return badRequest("The password is not valid"); } catch (UserNotFoundException e) { BaasBoxLogger.error("User 'admin' not found!"); return internalServerError("User 'admin' not found!"); } catch (OpenTransactionException e) { BaasBoxLogger.error(ExceptionUtils.getFullStackTrace(e)); throw new RuntimeException(e); } return ok("Admin password reset"); }
From source file:com.msopentech.odatajclient.testservice.utils.JSONUtilities.java
public static 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 w w. j a va 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:com.bbva.kltt.apirest.core.util.parser.ParserUtil.java
/** * @param nodeName with the node name//from w ww. j a v a 2 s . co m * @param node with the node to search the field * @param fieldName with the field name to be searched * @param isRequired true if the field is required * @return the field value * @throws APIRestGeneratorException with an occurred exception */ public static String getNodeValueField(final String nodeName, final JsonNode node, final String fieldName, final boolean isRequired) throws APIRestGeneratorException { String outcome = null; final boolean hasField = node.has(fieldName); if (hasField) { final JsonNode attributeNode = node.get(fieldName); if (attributeNode.isNull() && isRequired) { ParserUtil.generateExceptionRequiredNodeContent(nodeName, fieldName); } outcome = attributeNode.asText(); } else if (!hasField && isRequired) { ParserUtil.generateExceptionRequiredField(nodeName, fieldName); } return outcome; }
From source file:com.baasbox.service.storage.FileService.java
private static void setAcl(ODocument doc, JsonNode aclJson) throws UserNotFoundException, RoleNotFoundException, FileNotFoundException, SqlInjectionException, InvalidModelException, AclNotValidException { Iterator<Entry<String, JsonNode>> itAction = aclJson.fields(); //read,update,delete while (itAction.hasNext()) { Entry<String, JsonNode> nextAction = itAction.next(); String action = nextAction.getKey(); Permissions actionPermission = null; if (action.equalsIgnoreCase("read")) actionPermission = Permissions.ALLOW_READ; else if (action.equalsIgnoreCase("update")) actionPermission = Permissions.ALLOW_UPDATE; else if (action.equalsIgnoreCase("delete")) actionPermission = Permissions.ALLOW_DELETE; else if (action.equalsIgnoreCase("all")) actionPermission = Permissions.FULL_ACCESS; if (actionPermission == null) throw new AclNotValidException(Type.ACL_KEY_NOT_VALID, "'" + action + "' is not a valid permission to set. Allowed ones are: read, update, delete, all"); Iterator<Entry<String, JsonNode>> itUsersRoles = nextAction.getValue().fields(); while (itUsersRoles.hasNext()) { Entry<String, JsonNode> usersOrRoles = itUsersRoles.next(); JsonNode listOfElements = usersOrRoles.getValue(); if (listOfElements.isArray()) { for (final JsonNode element : listOfElements) { if (usersOrRoles.getKey().equalsIgnoreCase("users")) grantPermissionToUser((String) doc.field("id"), actionPermission, element.asText()); else grantPermissionToRole((String) doc.field("id"), actionPermission, element.asText()); }//from w w w.j av a 2 s . c o m } } } //set permissions }
From source file:au.org.ands.vocabs.toolkit.db.AccessPointUtils.java
/** Get the Toolkit's uri setting for a sesameDownload access point. * @param ap the access point//from w w w . j a v a 2 s . c o m * @return the access point's Toolkit uri setting, if it has one, * or null otherwise. */ public static String getToolkitUri(final AccessPoint ap) { if (!AccessPoint.SESAME_DOWNLOAD_TYPE.equals(ap.getType())) { // Not the right type. return null; } JsonNode dataJson = TaskUtils.jsonStringToTree(ap.getToolkitData()); JsonNode uri = dataJson.get("uri"); if (uri == null) { return null; } return uri.asText(); }
From source file:au.org.ands.vocabs.toolkit.db.AccessPointUtils.java
/** Get the portal's uri setting for an apiSparql or sissvoc access point. * @param ap the access point/*from www . j a v a 2 s. c o m*/ * @return the access point's portal uri setting, if it has one, * or null otherwise. */ public static String getPortalUri(final AccessPoint ap) { if (!(AccessPoint.API_SPARQL_TYPE.equals(ap.getType()) || (AccessPoint.SISSVOC_TYPE.equals(ap.getType())))) { // Not the right type. return null; } JsonNode dataJson = TaskUtils.jsonStringToTree(ap.getPortalData()); JsonNode uri = dataJson.get("uri"); if (uri == null) { return null; } return uri.asText(); }