Search code examples
apiautomated-testsjson-deserializationrest-assuredpojo

Why do we need to use POJO class and serialization in RestAssured, when we can directly send request body in the form of String?


What is the realtime use case for serialization in RestAssured? Even though we can send request body(JSON) as String. I tried googling but did not get satisfying results.


Solution

  • There are few advantages that come up as your code logic becames more complicated:

    1. You might want to send the same object to different endpoint which might not support json but xml content type. So you can simply have one pojo and RestAssured would take care of all conversions.

    2. Your object might change in runtime. So you will have to introduce changes to your string accordingly. This is quite an error-prone way. Serializer would assure that you send somewhat what is a proper json considering syntax stuff, escaping what needs to be escaped and so on.

    3. There might be the case when you fetch object from one endpoint and send it to another. Hence you would be able to use class for deserialization and further serialization in runtime.