martypitt / swagger-springmvc-example

Sample project for SpringMVC Swagger intergration
57 stars 51 forks source link

I would like don't display some fields #20

Open katiaSouza opened 11 years ago

katiaSouza commented 11 years ago

My new problem is: I would like don't display some fields in the object, example: My Json request is this: { "id": "long", "oneClick": "boolean", "ddd": "string", "email": "string", "name": "string",
"telephone": "string", "password": "string" }

but I would want it is this:

{
"oneClick": "boolean", "ddd": "string", "email": "string", "name": "string",
"telephone": "string", "password": "string" }

I call a POST action and id field is populated by my application. Can you help me?

katiaSouza commented 11 years ago

Hi guys I succeeded hide my id field, I used the annotation @JsonIgnore. But now when I make request http Get this field not return.

Can somebody help me?

katiaSouza commented 11 years ago

@dilipkrish Could help me?

dilipkrish commented 11 years ago

@katiaSouza have you tried adding the @jsonignore annotation to just the setter. That should work

katiaSouza commented 11 years ago

@dilipkrish yes, and when I make a request http Get the field not return.

dilipkrish commented 11 years ago

Could you share your annotated class (or something that is close to it) as an example please?

Better still could you fork the example project and add in your specific example that show cases your problem

katiaSouza commented 11 years ago

Follows below:

Model: public class Customer { private String id; private String name; private String email; public String getId() { return id; } @JSonIgnore public void setId(String id) { this.id = id; } public String getName() { return name; } public void setName(String name) { this.name = name; } public String getEmail() { return email; } public void setEmail(String email) { this.email = email; } }

Classe controller:

@Controller @RequestMapping(value="/api/customer") @Api(value="Customer operations", listingClass="CustomerController", basePath="/api/customer", description="All operation for customer") public class CustomerController { CustomerData customerData = new CustomerData();

@ApiOperation(value="Create customer", notes="Return token parameter and user identification", httpMethod="POST", multiValueResponse=false) @ApiErrors(errors={@ApiError(code=400,reason="Bad Request"),
@ApiError(code=500,reason="Internal Error")}) @RequestMapping(method=RequestMethod.POST,produces="application/json")
public @ResponseBody String createCustomer(@ApiParam(value="Customer", name="Customer",required=true) @RequestBody Customer customer,
@ApiParam(value="ID API",required=true,name="apiKey") @RequestParam(value="apiKey", required=true) String apiKey){

    CustomerResponse newCustomer = customerData.createCustomer(customer);

    return "{\"id\":\""+newCustomer.getId()+"\"}";
}

@ApiOperation(value="Find customer", notes="Return details of the customer", httpMethod="GET", responseClass="Customer",multiValueResponse=false) @ApiErrors(errors={@ApiError(code=400,reason="Bad Request"),
@ApiError(code=500,reason="Internal Error")}) @RequestMapping(value="/{ID}",method=RequestMethod.GET,produces="application/json") public @ResponseBody CustomerResponse findCustomer(@ApiParam(name="ID",required=true,value="Customer's ID")@PathVariable String ID, @ApiParam(name="token",required=true,value="token") @RequestParam(value="token", required=true) String token, @ApiParam(value="ID API",required=true,name="apiKey") @RequestParam(value="apiKey", required=true) String apiKey){

    return customerData.findCustomer(ID);
}

}

dilipkrish commented 11 years ago

@katiaSouza let me take a look at this and i'll let you know