Set default output format to json

17 views
Skip to first unread message

Arian Kuschki

unread,
Jul 21, 2016, 4:13:27 PM7/21/16
to Swagger
Hi,
I use swagger-inflector and swagger-codegen to create a java jersey2 app. All my unimplemented methods are mocked by inflector and return json. But the methods I implement return xml by default. The "@Produces" annotation seems to be ignored. The only way to make them return json is to set the "Accept" header with every request. 

How can I set the output format of all controller methods to json?

Cheers,
Arian

tony tam

unread,
Jul 21, 2016, 4:21:21 PM7/21/16
to swagger-sw...@googlegroups.com
I think you’re talking about in the browser only?  Or are you talking about when calling via curl, etc?

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

Arian Kuschki

unread,
Jul 21, 2016, 4:28:07 PM7/21/16
to Swagger

Hi Tony,

curl and browser are the same:


Method I implemented:

curl -s -H "Accept: application/json" http://104.155.88.210:8085/v1/customers/1/campaigns

returns

{"name":"dodo","callouts":[],"negativeKeywords":[]}

but

returns 

<Campaign><id/><name>dodo</name><dailyBudget/><callouts/><startDate/><endDate/><partnerRadius/><negativeKeywords/><active/></Campaign>


Mocked method returns json even without "Accept" header:

returns

{"id":0,"name":"string","dailyBudget":0,"callouts":["string"],"startDate":"2015-07-20","endDate":"2015-07-20","partnerRadius":1.1,"negativeKeywords":["id"0,"text","string"],"active":true}
To unsubscribe from this group and stop receiving emails from it, send an email to swagger-swaggersocket+unsub...@googlegroups.com.

tony tam

unread,
Jul 21, 2016, 4:40:53 PM7/21/16
to swagger-sw...@googlegroups.com
Please open an issue in the inflector project—I can’t reply to this now but can shortly.

To unsubscribe from this group and stop receiving emails from it, send an email to swagger-swaggers...@googlegroups.com.

Arian Kuschki

unread,
Jul 22, 2016, 4:56:58 AM7/22/16
to Swagger
Reply all
Reply to author
Forward
0 new messages