I’m making a rest api using resteasy, and testing it with rest-assured.
Let’s say that I have a class, message, with a property text.
@XmlRootElement
public class message {
@XmlElement
public String text;
}
The following test will try to post this object to a given url:
message msg = new message();
msg.text = "some message";
expect()
.statusCode(200)
.given()
.contentType("application/json")
.body(msg)
.when()
.post("/message");
The msg object is serialized to json and posted, but not in the way that I want – not in the way resteasy need, that is.
What’s posted:
{ "text": "some message" }
What’s working:
{ "message": { "text": "some message" } }
Does anyone have any clue on how I can make this work as expected?
You are probably using the built in Jettison JSON serializer with RestEasy. Jettison uses the XML-> Json convention (also known as BadgerFish). Replace Jettison with Jackson or GSon to get a JSon format compatible with RestAssured.