Converts a String containing a JSON document into a {@link JsonNode}.

@param paramName Param name to use in exception message.
@param val String JSON document.
@return JsonNode representing document.
175340
public static JsonNode stringToJsonNode(String paramName, String val) {
        if (val == null) {
            return null;
        }
        try {
            return MAPPER.readTree(val);
        } catch (IOException e) {
            throw new SdkClientException(paramName + " must be a valid JSON document", e);
        }
    }
14441
private function string2jsonArray($doc, $val, $space){
        list($name, $value) =  explode(":", trim($val));
        $json = "";
        if(strpos($value, "@!") != false){
            $json .= $space.'"'.$name.'":{//'.str_replace('@!','',$value).'<br/>';
        }else{
            $json .= $space.'"'.$name.'":[{//'.str_replace('@','',$value).'<br/>';
        }
        $return = isset($doc[$name]) ? $doc[$name] : [];
        if(preg_match_all('/(\w+):(.*?)[\s\n]/s', $return." ", $meatchs)){
            foreach ($meatchs[0] as $key=>$v){
                if(strpos($meatchs[2][$key],'@') != false){
                    $json .= $this->string2jsonArray($doc,$v,$space.'&nbsp;&nbsp;');
                } else{
                    $json .= $space.'&nbsp;&nbsp;'. $this->string2json(trim($meatchs[1][$key]), $meatchs[2][$key]);
                }
            }
        }
        if(strpos($value, "@!") != false){
            $json .= $space."}<br/>";
        }else{
            $json .= $space."}]<br/>";
        }
        return $json;
    }
205212
@SuppressWarnings("unchecked")
    public static <T> T convertValue(JsonNode node, Class<T> clazz) {
        if (node instanceof POJONode) {
            return convertValue(DPathUtils.extractValue((POJONode) node), clazz);
        }
        if (clazz == null) {
            throw new NullPointerException("Class parameter is null!");
        }
        if (node == null || node instanceof NullNode || node instanceof MissingNode) {
            return null;
        }
        if (node instanceof POJONode) {
            return convertValue(DPathUtils.extractValue((POJONode) node), clazz);
        }
        if (Number.class.isAssignableFrom(clazz) || byte.class == clazz || short.class == clazz
                || int.class == clazz || long.class == clazz || float.class == clazz
                || double.class == clazz) {
            return convertNumber(node, clazz);
        }
        if (clazz == Boolean.class || clazz == boolean.class) {
            return (T) convertBoolean(node);
        }
        if (clazz == Character.class || clazz == char.class) {
            return (T) convertChar(node);
        }
        if (Date.class.isAssignableFrom(clazz)) {
            return (T) convertDate(node);
        }
        if (Object[].class.isAssignableFrom(clazz) || List.class.isAssignableFrom(clazz)) {
            return (T) convertArrayOrList(node);
        }
        if (clazz.isAssignableFrom(node.getClass())) {
            return (T) node;
        }
        if (clazz == String.class) {
            return (T) (node.isTextual() ? node.asText() : node.toString());
        }
        throw new IllegalArgumentException(
                "Cannot convert an object of type [" + node.getClass() + "] to [" + clazz + "]!");
    }
543819
public static Object getElement(final JsonNode json, final String name) {
        if (json != null && name != null) {
            JsonNode node = json;
            for (String nodeName : name.split("\\.")) {
                if (node != null) {
                    if (nodeName.matches("\\d+")) {
                        node = node.get(Integer.parseInt(nodeName));
                    } else {
                        node = node.get(nodeName);
                    }
                }
            }
            if (node != null) {
                if (node.isNumber()) {
                    return node.numberValue();
                } else if (node.isBoolean()) {
                    return node.booleanValue();
                } else if (node.isTextual()) {
                    return node.textValue();
                } else if (node.isNull()) {
                    return null;
                } else {
                    return node;
                }
            }
        }
        return null;
    }
633594
public Map<String, Object> jsonStringToMap(String jsonString) {
        if (StringUtils.isEmpty(jsonString)) {
            return null;
        }
        JSONObject jsonObject;
        try {
            jsonObject = new JSONObject(jsonString);
            return jsonObjectToMap(jsonObject);
        } catch (JSONException e) {
            throw new RuntimeException("Unable to convert string to map: " + jsonString, e);
        }
    }
441322
private static JsonNode toJson(AggregatedHttpMessage res, @Nullable JsonNodeType expectedNodeType) {
        final String content = toString(res);
        final JsonNode node;
        try {
            node = Jackson.readTree(content);
        } catch (JsonParseException e) {
            throw new CentralDogmaException("failed to parse the response JSON", e);
        }

        if (expectedNodeType != null && node.getNodeType() != expectedNodeType) {
            throw new CentralDogmaException(
                    "invalid server response; expected: " + expectedNodeType +
                    ", actual: " + node.getNodeType() + ", content: " + content);
        }
        return node;
    }
405218
private static String getName(JsonProperty jsonProperty, XmlNode xmlNode, Field field) {
        String name;
        if (jsonProperty != null) {
            name = jsonProperty.value();
        } else if (xmlNode != null) {
            name = xmlNode.name();
        } else {
            name = field.getName();
        }
        return name;
    }
95285
@SuppressWarnings("unchecked")
	public static<X> Map<String, X> toMap(String json, Class<X> valClass) {
		Map<String, X> map = new HashMap<String, X>();
		try {
			JsonFactory f = new JsonFactory();
			JsonParser jp = f.createJsonParser(json);
			jp.nextToken(); // will return JsonToken.START_OBJECT (verify?)
			while (jp.nextToken() != JsonToken.END_OBJECT) {
				JsonToken token = jp.getCurrentToken();
				if(token.equals(JsonToken.FIELD_NAME)) {
					jp.nextToken();// to value token
					if(valClass.equals(Integer.class) || valClass.equals(int.class) ) {
						map.put(jp.getCurrentName(), (X) Integer.valueOf(jp.getIntValue()));
					} else if (valClass.equals(String.class)) {
						map.put(jp.getCurrentName(), (X) jp.getText());
					} else if (valClass.equals(Boolean.class) || valClass.equals(boolean.class)) {
						map.put(jp.getCurrentName(), (X) Boolean.valueOf(jp.getBooleanValue()));
					}
				}
			}
			jp.close();
		} catch (Exception e) {
			throw new RuntimeException(e);
		}
		return map;
	}
625149
public String stringify(JsonNode json) {
        try {
            return mapper().writerWithDefaultPrettyPrinter().writeValueAsString(json);
        } catch (JsonProcessingException e) {
            throw new RuntimeException("Cannot stringify the input json node", e);
        }
    }
167263
private String getTextField(JsonNode json, String fieldName) {
        if (!json.has(fieldName)) {
            return null;
        }
        return json.get(fieldName).asText();
    }
757744
public JSONArray toJSONArray(Collection<String> names) throws JSONException {
		if (CollectionUtil.isEmpty(names)) {
			return null;
		}
		final JSONArray ja = new JSONArray();
		Object value;
		for (String name : names) {
			value = this.get(name);
			if (null != value) {
				ja.put(value);
			}
		}
		return ja;
	}
124562
protected JsonNode getValue(JsonNode node, String property) {
		if(node==null) {
			throw new MissingNodeException(property + " is missing");
		}
		
		if(property==null) {
			return node;
		}
		
		JsonNode value = node.at(formatPropertyName(property));
		if (value.isMissingNode()) {
			throw new MissingNodeException(property + " is missing");
		}
		return value;	
	}
1080278
public static String jsonToString(JsonNode node) {
        try {
            return node == null ? null : MAPPER.writeValueAsString(node);
        } catch (JsonProcessingException e) {
            throw new SdkClientException("Could not serialize JSON", e);
        }
    }
740828
public final JsonElement toJsonTree(T value) {
    try {
      JsonTreeWriter jsonWriter = new JsonTreeWriter();
      write(jsonWriter, value);
      return jsonWriter.get();
    } catch (IOException e) {
      throw new JsonIOException(e);
    }
  }
138608
@Override
    public JsonNode evaluate(List<JsonNode> evaluatedArgs) throws InvalidTypeException {
        JsonNode arg = evaluatedArgs.get(0);
        if (arg.isTextual()) {
            return getStringLength(arg);
        } else if (arg.isArray() || arg.isObject()) {
            return new IntNode(arg.size());
        }
        throw new InvalidTypeException("Type mismatch. Expecting a string or an array or an object.");
    }
1231241
protected final JsonNode getRequiredNode(JsonNode tree, String fieldName) {
		Assert.notNull(tree, "Tree must not be null");
		JsonNode node = tree.get(fieldName);
		Assert.state(node != null && !(node instanceof NullNode),
				() -> "Missing JSON field '" + fieldName + "'");
		return node;
	}
51230
public static JsonNode toJson(final Object data) {
        if (data == null) {
            return newObject();
        }

        try {
            return createObjectMapper().valueToTree(data);
        } catch (Exception e) {
            throw new ParseException(e);
        }
    }