I have applied JsonIgnore annotation on a field in class.
public class User {
private String name;
@JsonIgnore
private String id;
public String getName(){ return this.name;}
public void setName(String name){ this.name = name; }
public String getId() { return this.id; }
public void setId(String id) {this.id = id; }
}
When the class object is returned as single object, the field gets ignored.
public ResponseEntity<User> get() {.... some code to get user and return User object}
However, when the list of object is returned as response, the field is not getting ignored and still present in response.
ProjectController.java
@RequestMapping(value="/{projectId}/users", method = RequestMethod.GET, produces = "application/json")
public ResponseEntity<List<User>> list(
@ApiParam(value = "projectId")
@PathVariable UUID projectId) {
return ok(projectsService.getUsers(projectId));
}
ProjectService.java
public List<User> getUsers(UUID projectId) {
// Some code here to fetch the data from another container , so framing URI here and sending the req
String response = HttpUtils.getRequest(uri);
return new ObjectMapper().readValue(response, List.class);
}
Could you please help on how to ignore the field completely from sending in responses.