Handling json response

662 views
Skip to first unread message

Sathyakumar Seshachalam

unread,
Jun 23, 2015, 7:20:11 AM6/23/15
to rest-a...@googlegroups.com
I have a legacy application that I want to test using rest-assured.

For whatever reasons, the application is coded such that the response is Json, but unforunately the content type of the response is set as text/plain;charset=UTF-8.
Now when I try to extract a json path from the response I get an exception as 
java.lang.IllegalStateException: Cannot determine which path implementation to use because the content-type text/plain;charset=UTF-8 doesn't map to a path implementation.
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:57)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.lang.reflect.Constructor.newInstance(Constructor.java:525)
at org.codehaus.groovy.reflection.CachedConstructor.invoke(CachedConstructor.java:77)
at org.codehaus.groovy.reflection.CachedConstructor.doConstructorInvoke(CachedConstructor.java:71)
at org.codehaus.groovy.runtime.callsite.ConstructorSite$ConstructorSiteNoUnwrap.callConstructor(ConstructorSite.java:81)
at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCallConstructor(CallSiteArray.java:57)
at org.codehaus.groovy.runtime.callsite.AbstractCallSite.callConstructor(AbstractCallSite.java:232)
at org.codehaus.groovy.runtime.callsite.AbstractCallSite.callConstructor(AbstractCallSite.java:244)
at com.jayway.restassured.internal.RestAssuredResponseOptionsGroovyImpl.path(RestAssuredResponseOptionsGroovyImpl.groovy:386)
at com.jayway.restassured.internal.RestAssuredResponseOptionsImpl.path(RestAssuredResponseOptionsImpl.java:189)

Is there a way to workaround this issue ?

Johan Haleby

unread,
Jun 23, 2015, 10:33:11 AM6/23/15
to rest-a...@googlegroups.com
You can register "text/plain" to be treated as JSON using "registerParser". See docs here.

Regards,
/Johan

--
You received this message because you are subscribed to the Google Groups "REST assured" group.
To unsubscribe from this group and stop receiving emails from it, send an email to rest-assured...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply all
Reply to author
Forward
0 new messages