From the course: Java: Automated API Testing with REST Assured

Unlock the full course today

Join today to access over 22,600 courses taught by industry experts or purchase this course individually.

Deserializing response body

Deserializing response body - Java Tutorial

From the course: Java: Automated API Testing with REST Assured

Start my 1-month free trial

Deserializing response body

- [Instructor] Just as we use Java classes to model the body of an API request, we can do the same for the body of a response. This is known as deserializing. Let's make a GET call to obtain a single product. So we'll make a new Test, and let's call this one getDeserializedProduct. And we'll specify our endpoint. And let's get right into the call, so we can say given. And let's use a query parameter to specify the id. So we'll say given the id is, and let's just use 2, we've used that product before. Okay, now let's make the call. So given this query parameter, when, we say get on this endpoint. Now, usually, right here we would specify then, and that would give us a response in a form that would allow us to verify the body as JSON or XML. However, in this chapter, we want to get the response returned as a Java object. So instead of calling then, we're going to make a call to a method called as. And inside of as,…

Contents