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.

Serializing request body

Serializing request body - Java Tutorial

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

Start my 1-month free trial

Serializing request body

- [Instructor] When creating large bodies as part of a request, having a huge text block in your code may not be ideal. You can define this data in a more structured way by serializing it as part of a Java class. Let's create a new package, and we'll call this package Models. And under the Models package, we'll create a new Java class, and we'll call this one Product. Now this Product class will represent a serialized object form of the request body. So in order to do that, we're going to need to include the fields that are represented in the request. So let's go ahead and make those fields. We can make an ID. We know that we need the name of the product. We need a description. We need a price. And we need the category ID. It's really important to name these variables exactly as they're named in the API, because this is how it will bind our variable with the respective API body field. Okay, let's go ahead and…

Contents