swagger-springmvc-example icon indicating copy to clipboard operation
swagger-springmvc-example copied to clipboard

I would like don't display some fields

Open katiaSouza opened this issue 11 years ago • 7 comments

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 avatar Jun 12 '13 19:06 katiaSouza

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 avatar Jun 14 '13 19:06 katiaSouza

@dilipkrish Could help me?

katiaSouza avatar Jun 17 '13 13:06 katiaSouza

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

dilipkrish avatar Jun 17 '13 13:06 dilipkrish

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

katiaSouza avatar Jun 17 '13 14:06 katiaSouza

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

dilipkrish avatar Jun 18 '13 04:06 dilipkrish

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);
}

}

katiaSouza avatar Jun 18 '13 13:06 katiaSouza

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

dilipkrish avatar Jun 20 '13 04:06 dilipkrish