cancel
Showing results for 
Search instead for 
Did you mean: 

json response is 'plain/text' type. Anyway to change type to 'application/json'?

Community Hero

json response is 'plain/text' type. Anyway to change type to 'application/json'?

Hey

A 3rd party's webservice response payload is a wellformed json fragment (wellformed json confirmed by doing a wellformed check in xmlspy),but the Content-Type header on response is 'plain/text' rather than 'application/json' meaning the payload in the response is represented as a single string of text in the response's Outline tab making creating assertions difficult.

Before now when i wanted to change the type of the response (say from xml to json), i'd add an Accept header (value = application/json) to the request.

However adding the Accept header to the request did NOT change the response's type from text to json.

Would anyone have any ideas how i could get the response to be treated as json in ReadyAPI!s Outline tab?

Could an event handler do this? i.e. not actually change the type of the response, but change how its represented in the Outline tab?

Cheers!

Rich
if this helped answer the post, could you please mark it as 'solved'? Also if you consider whether the title of your post is relevant? Perhaps if the post is solved, it might make sense to update the Subject header field of the post to something more descriptive? This will help people when searching for problems. Ta
10 REPLIES 10
Community Hero

Re: json response is 'plain/text' type. Anyway to change type to 'application/json'?

Can't it possible to request the service provider to make it change?


Regards,
Rao.
Community Hero

Re: json response is 'plain/text' type. Anyway to change type to 'application/json'?

Hey Rao,

Nah...it's an external 3rd party's webservice. Smiley Sad


Cheers,

Rich
if this helped answer the post, could you please mark it as 'solved'? Also if you consider whether the title of your post is relevant? Perhaps if the post is solved, it might make sense to update the Subject header field of the post to something more descriptive? This will help people when searching for problems. Ta
Community Hero

Re: json response is 'plain/text' type. Anyway to change type to 'application/json'?

3rd Party services? So what, if there is defect or issue arises, it must be addressed. Not sure what is obstructing not to make a request.


Regards,
Rao.
Contributor

Re: json response is 'plain/text' type. Anyway to change type to 'application/json'?

If you don't mind doing assertions through code, you could use JsonSlurper to take the response string and make it into an object like:

 

import groovy.json.JsonSlurper

String responseStr = "" // wherever you get the response from
def response = new JsonSlurper().parseText(responseStr)

// Perform assertions here (just making this stuff up)
assert response.employees[0].id == 12345

response.employees.each {
assert it.salary > 0
}

 

Provided you're not trying to assert on some crazy complex stuff, this could work. 

Community Hero

Re: json response is 'plain/text' type. Anyway to change type to 'application/json'?

@JustinM89  - cheers fella - I'll check this out

 

@nmrao - it's a defect from the perspective that the type specified doesn't reflect the payload content - but this doesn't change the payload content itself - so the API 'works successfully'. The requirements for this API only specifies the headers on the request - not the response.  Furthermore - Its a well known 3rd party in use by lots of companies - the impact of changing the 'type' to what it should be won't make any difference to the API itself from a functional perspective - it will just make testing easier.

 

Hence the reason there's no point raising it with the 3rd party.  The API successfully responds with a .json fragment - its just hte Content-Type header that is 'incorrect'.  Lots of other companies use this and haven't raised it as a ticket because excepting impacting performance sending as text/plain rather than application/json wont make any difference - or these other companies haven't noticed the issue - as I say - there's no functional impact - only a slight performance one.

 

Cheers,

 

rich

 

 

 

if this helped answer the post, could you please mark it as 'solved'? Also if you consider whether the title of your post is relevant? Perhaps if the post is solved, it might make sense to update the Subject header field of the post to something more descriptive? This will help people when searching for problems. Ta
Community Hero

Re: json response is 'plain/text' type. Anyway to change type to 'application/json'?

If I were you, not acceptable getting incorrect header value and still request for change/fix.

Worth reading
https://stackoverflow.com/questions/4350753/advantages-of-using-application-json-over-text-plain


Regards,
Rao.
Moderator

Re: json response is 'plain/text' type. Anyway to change type to 'application/json'?

Thanks everyone for your replies!

 

@richie, have you found a solution? Did any of the replies above help?


Olga Terentieva
SmartBear Assistant Community Manager

Community Hero

Re: json response is 'plain/text' type. Anyway to change type to 'application/json'?

Hey @Olga_T

Nah....we didn't find a way around the defect.
Typically youd use the Accept header value=application/json on the request, but this doesnt work in this instance, so i can't really marked this as "answered".

Cheers,

Rich
if this helped answer the post, could you please mark it as 'solved'? Also if you consider whether the title of your post is relevant? Perhaps if the post is solved, it might make sense to update the Subject header field of the post to something more descriptive? This will help people when searching for problems. Ta
Community Hero

Re: json response is 'plain/text' type. Anyway to change type to 'application/json'?

This doesn't appear to be an issue with SmartBear tool. Isn't it?


Regards,
Rao.