com.jayway.restassured.response.ResponseBodyExtractionOptions Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of rest-assured Show documentation
Show all versions of rest-assured Show documentation
Java DSL for easy testing of REST services
package com.jayway.restassured.response;
import com.jayway.restassured.internal.mapper.ObjectMapperType;
import com.jayway.restassured.mapper.ObjectMapper;
import com.jayway.restassured.path.json.JsonPath;
import com.jayway.restassured.path.json.config.JsonPathConfig;
import com.jayway.restassured.path.xml.XmlPath;
import com.jayway.restassured.path.xml.config.XmlPathConfig;
public interface ResponseBodyExtractionOptions extends ResponseBodyData {
/**
* Get the body and map it to a Java object. For JSON responses this requires that you have either
*
* - Jackson, or
* - Gson
*
* in the classpath or for XML responses it requires JAXB to be in the classpath.
*
* It also requires that the response content-type is either JSON or XML or that a default parser has been been set.
* You can also force a specific object mapper using {@link #as(Class, com.jayway.restassured.mapper.ObjectMapper)}.
*
* @return The object
*/
T as(Class cls);
/**
* Get the body and map it to a Java object using a specific object mapper type. It will use the supplied
* mapper regardless of the response content-type.
*
* @return The object
*/
T as(Class cls, ObjectMapperType mapperType);
/**
* Get the body and map it to a Java object using a specific object mapper. It will use the supplied
* mapper regardless of the response content-type.
*
* @return The object
*/
T as(Class cls, ObjectMapper mapper);
/**
* Get a JsonPath view of the response body. This will let you use the JsonPath syntax to get values from the response.
* Example:
*
* Assume that the GET request (to http://localhost:8080/lotto) returns JSON as:
*
* {
* "lotto":{
* "lottoId":5,
* "winning-numbers":[2,45,34,23,7,5,3],
* "winners":[{
* "winnerId":23,
* "numbers":[2,45,34,23,3,5]
* },{
* "winnerId":54,
* "numbers":[52,3,12,11,18,22]
* }]
* }
* }
*
*
* You can the make the request and get the winner id's by using JsonPath:
*
* List winnerIds = get("/lotto").jsonPath().getList("lotto.winnders.winnerId");
*
*/
JsonPath jsonPath();
/**
* Get a JsonPath view of the response body using the specified configuration.
*
* @param config The configuration to use
* @see #jsonPath()
*/
JsonPath jsonPath(JsonPathConfig config);
/**
* Get an XmlPath view of the response body. This will let you use the XmlPath syntax to get values from the response.
* Example:
*
* Imagine that a POST request to http://localhost:8080/greetXML returns:
*
* <greeting>
* <firstName>John</firstName>
* <lastName>Doe</lastName>
* </greeting>
*
*
*
* You can the make the request and get the winner id's by using JsonPath:
* * String firstName = get("/greetXML").xmlPath().getString("greeting.firstName"); **/ XmlPath xmlPath(); /** * Get an XmlPath view of the response body with a given configuration. * * @param config The configuration of the XmlPath * @see #xmlPath() */ XmlPath xmlPath(XmlPathConfig config); /** * Get an XmlPath view of the response body but also pass in a {@link com.jayway.restassured.path.xml.XmlPath.CompatibilityMode}. * This is mainly useful if you want to parse HTML documents. * * @param compatibilityMode The compatibility mode to use * @see #htmlPath() * @see #xmlPath() */ XmlPath xmlPath(XmlPath.CompatibilityMode compatibilityMode); /** * Get an XmlPath view of the response body that uses {@link com.jayway.restassured.path.xml.XmlPath.CompatibilityMode}
HTML
.
* This is mainly useful when parsing HTML documents.
*
* Note that this is the same as calling {@link #xmlPath(com.jayway.restassured.path.xml.XmlPath.CompatibilityMode)} with CompatibilityMode
HTML
.
*
* Note that you can also also supply arguments, for example: *
* String z = get("/x").path("x.y.%s", "z"); ** * The path and arguments follows the standard formatting syntax of Java. * * * @param path The json- or xml path * @param
© 2015 - 2025 Weber Informatics LLC | Privacy Policy