Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Set default output format to json for implemented methods #135

Closed
hni opened this issue Jul 22, 2016 · 1 comment
Closed

Set default output format to json for implemented methods #135

hni opened this issue Jul 22, 2016 · 1 comment
Assignees

Comments

@hni
Copy link

hni commented Jul 22, 2016

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 on my implemented controller methods seems to be ignored. The only way to make them return json is to set the "Accept" header with every request.

Controller class:

[...]
import javax.ws.rs.GET;
import javax.ws.rs.Produces;

public class CampaignController {

    @GET
    @Produces({"application/json"})
    public Campaign listCampaigns(RequestContext context, Long customerId){
        final Campaign campaign = new Campaign();
        campaign.setName("dodo");
        return campaign;
    }

}

Example requests:

Method I implemented, returns xml per default:


curl -s -H "Accept: application/json" http://104.155.88.210:8085/v1/customers/1/campaigns 
{"name":"dodo","callouts":[],"negativeKeywords":[]}



curl -s   http://104.155.88.210:8085/v1/customers/1/campaigns
<Campaign><id/><name>dodo</name><dailyBudget/><callouts/><startDate/><endDate/><partnerRadius/><negativeKeywords/><active/></Campaign>


Mocked method, returns json even without "Accept" header:

curl -s   http://104.155.88.210:8085/v1/customers/1/campaigns/1

{"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}
@fehguy fehguy self-assigned this Jul 29, 2016
fehguy added a commit that referenced this issue Jul 30, 2016
@fehguy
Copy link
Contributor

fehguy commented Jul 30, 2016

I cannot reproduce this. Could you please see this test:

86bc923#diff-89a0c8077283ca65b420bbd7a195c5d2R103

And report back as to what is different?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants