Providing custom JSON serializers in rest assured

1,232 views
Skip to first unread message

Frédéric Camblor

unread,
Feb 1, 2012, 1:46:06 PM2/1/12
to rest-a...@googlegroups.com
Hi folks !

Simple question : is there any way to provide custom JSON Serializer to rest assured ?
I am using Joda time in my project, with things like LocalTime or DateTime, and I don't want to serialize them the way jackon does by default.

In my code, I already defined custom jackson serializers for this types, but I don't think I can't reuse them in rest assured (since we cannot access underlying jackson ObjectMapper object to add custom serializers).
At least, would there be a backdoor somewhere allowing to either have access to ObjectMapper or rest assured JSON serialization ?

Thanks in advance !
Frédéric

Johan Haleby

unread,
Feb 1, 2012, 3:28:53 PM2/1/12
to rest-a...@googlegroups.com
Hi,

This is not possible right now and I doubt that it'll make it to the next version that I hope to release pretty soon. There's an issue for though and if you want to help out that would be great.

As a work-around perhaps you could create a filter that serializes the object according to your needs and set the serialized output to the request body. E.g.

given().filter(new MySerializeFilter(myJavaObject)).when().post(..);

Have a look at the documentation for more details on the filters.

Regards,
/Johan

Frédéric Camblor

unread,
Feb 2, 2012, 3:32:24 AM2/2/12
to rest-a...@googlegroups.com
Hi Johan,

In fact I didn't see there was the body(String) and body(byte[]) methods which allow to directly write body content.
I used my in-house objectmapper to serialize my json, and provided the json form of my object into the body(String) method (Jackson's ObjectMapper has a perfect writeValueAsString(Object) method for that :)).

FYI I experienced problems with the body(byte[]) method which yelled I had to use a JSONArray, whereas using the body(String) methods worked perfectly well.

Cheers,

Frédéric Camblor  
Bordeaux JUG Board member
Jenkins community member & plugin commiter

Johan Haleby

unread,
Feb 2, 2012, 3:36:02 AM2/2/12
to rest-a...@googlegroups.com
Hmm could you add an issue for the "byte[]" problems you face?

/Johan

2012/2/2 Frédéric Camblor <fcam...@gmail.com>

Frédéric Camblor

unread,
Feb 2, 2012, 5:51:22 AM2/2/12
to rest-a...@googlegroups.com
Done .. with attached unit test :)

Frédéric Camblor  
Bordeaux JUG Board member
Jenkins community member & plugin commiter

Johan Haleby

unread,
Feb 2, 2012, 6:01:51 AM2/2/12
to rest-a...@googlegroups.com
Thanks! :)

2012/2/2 Frédéric Camblor <fcam...@gmail.com>
Reply all
Reply to author
Forward
0 new messages