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

I would like don't display some fields #20

Open
katiaSouza opened this issue Jun 12, 2013 · 7 comments
Open

I would like don't display some fields #20

katiaSouza opened this issue Jun 12, 2013 · 7 comments

Comments

@katiaSouza
Copy link

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
Copy link
Author

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
Copy link
Author

@dilipkrish Could help me?

@dilipkrish
Copy link
Collaborator

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

@katiaSouza
Copy link
Author

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

@dilipkrish
Copy link
Collaborator

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
Copy link
Author

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
Copy link
Collaborator

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

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