Java Code Examples for com.jayway.jsonpath.DocumentContext#json()
The following examples show how to use
com.jayway.jsonpath.DocumentContext#json() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ScriptValue.java From karate with MIT License | 5 votes |
public List getAsList() { switch (type) { case LIST: return getValue(List.class); case JSON: DocumentContext doc = (DocumentContext) value; return doc.json(); default: throw new RuntimeException("cannot convert to list: " + this); } }
Example 2
Source File: FieldLevelEncryption.java From client-encryption-java with MIT License | 4 votes |
private static Object readJsonElement(DocumentContext context, String jsonPathString) { Object payloadJsonObject = context.json(); JsonPath jsonPath = JsonPath.compile(jsonPathString); return jsonPath.read(payloadJsonObject, jsonPathConfig); }
Example 3
Source File: Json.java From karate with MIT License | 4 votes |
private Json(DocumentContext doc) { this.doc = doc; array = (doc.json() instanceof List); prefix = array ? "$" : "$."; }
Example 4
Source File: ScriptValue.java From karate with MIT License | 4 votes |
public ScriptValue(Object value, String source) { // pre-process and convert any nashorn js objects into vanilla Map / List if (value instanceof ScriptObjectMirror) { ScriptObjectMirror som = (ScriptObjectMirror) value; if (!som.isFunction()) { value = JsonUtils.toJsonDoc(value).read("$"); // results in Map or List if (value instanceof Map) { Map map = (Map) value; retainRootKeyValuesWhichAreFunctions(som, map, true); } } } this.value = value; this.source = source; if (value == null) { type = Type.NULL; } else if (value instanceof DocumentContext) { DocumentContext doc = (DocumentContext) value; listLike = doc.json() instanceof List; mapLike = !listLike; type = Type.JSON; } else if (value instanceof Node) { mapLike = true; type = Type.XML; } else if (value instanceof List) { listLike = true; type = Type.LIST; } else if (value instanceof ScriptObjectMirror) { // has to be before Map type = Type.JS_FUNCTION; } else if (value instanceof Map) { mapLike = true; type = Type.MAP; } else if (value instanceof String) { type = Type.STRING; } else if (value instanceof byte[]) { type = Type.BYTE_ARRAY; } else if (value instanceof InputStream) { type = Type.INPUT_STREAM; } else if (Script.isPrimitive(value.getClass())) { type = Type.PRIMITIVE; } else if (value instanceof Feature) { type = Type.FEATURE; } else if (value instanceof Function) { type = Type.JAVA_FUNCTION; } else { type = Type.UNKNOWN; } }