/** * Instantiate a new JsonPath instance. * * @param stream The stream containing the Object document */ public static JsonPath with(InputStream stream) { return new JsonPath(stream); }
/** * Instantiate a new JsonPath instance. * * @param url The url containing the Object document */ public JsonPath(URL url) { jsonParser = parseURL(url); }
/** * Instantiate a new JsonPath instance. * * @param stream The stream containing the Object document */ public JsonPath(InputStream stream) { jsonParser = parseInputStream(stream); }
/** * Get the result of an Object path expression as a list. * * @param path The Object path. * @param <T> The list type * @return The object matching the Object path. A {@link java.lang.ClassCastException} will be thrown if the object * cannot be casted to the expected type. */ public <T> List<T> getList(String path) { return get(path); }
/** * Get the result of an Object path expression as a boolean. * * @param path The Object path. * @return The object matching the Object path. This may be any primitive type, a List or a Map. A {@link java.lang.ClassCastException} will be thrown if the object * cannot be casted to the expected type. */ public <T> T get(String path) { final JSONAssertion jsonAssertion = createJsonAssertion(path, params); final Object json = jsonParser.parseWith(createConfigurableJsonSlurper()); return (T) jsonAssertion.getResult(json, null); }
public final Object parseWith(ConfigurableJsonSlurper slurper) { if (json == null) { json = doParseWith(slurper); } return json; }
@Override public Object doParseWith(final ConfigurableJsonSlurper slurper) { return new ExceptionCatcher() { protected Object method() throws Exception { return slurper.parse(toReader(stream)); } }.invoke(); } };
@Override public Object doParseWith(final ConfigurableJsonSlurper slurper) { return new ExceptionCatcher() { protected Object method() throws Exception { return slurper.parseText(text); } }.invoke(); } };
@Override public Object doParseWith(final ConfigurableJsonSlurper slurper) { return new ExceptionCatcher() { protected Object method() throws Exception { return slurper.parse(new FileReader(file)); } }.invoke(); } };
/** * Get the result of an Object path expression as a map. * * @param path The Object path. * @param <K> The type of the expected key * @param <V> The type of the expected value * @return The map matching the Object path. A {@link java.lang.ClassCastException} will be thrown if the object * cannot be casted to the expected type. */ public <K, V> Map<K, V> getMap(String path) { return get(path); }
public <T> T getJsonObject(String path) { final JSONAssertion jsonAssertion = createJsonAssertion(path, params); final Object json = jsonParser.parseWith(createConfigurableJsonSlurper()); return (T) jsonAssertion.getAsJsonObject(json); }
/** * Instantiate a new JsonPath instance. * * @param file The file containing the Object document */ public static JsonPath from(File file) { return new JsonPath(file); }
/** * Instantiate a new JsonPath instance. * * @param reader The reader containing the Object document */ public static JsonPath from(Reader reader) { return new JsonPath(reader); }
/** * Instantiate a new JsonPath instance. * * @param text The text containing the Object document */ public static JsonPath given(String text) { return new JsonPath(text); }
/** * Instantiate a new JsonPath instance. * * @param text The text containing the Object document */ public static JsonPath with(String text) { return new JsonPath(text); }
/** * Instantiate a new JsonPath instance. * * @param url The URI containing the Object document */ public static JsonPath with(URL url) { return new JsonPath(url); }
/** * Instantiate a new JsonPath instance. * * @param stream The stream containing the Object document */ public static JsonPath from(InputStream stream) { return new JsonPath(stream); }
/** * Instantiate a new JsonPath instance. * * @param url The URI containing the Object document */ public static JsonPath from(URL url) { return new JsonPath(url); }
/** * Instantiate a new JsonPath instance. * * @param file The file containing the Object document */ public static JsonPath with(File file) { return new JsonPath(file); }
/** * Instantiate a new JsonPath instance. * * @param text The text containing the Object document */ public static JsonPath from(String text) { return new JsonPath(text); }