1

I have a field in my Entity with @JsonView annotation:

@JsonView(View.Secure.class)
private String password;

Inside my controller:

@RequestMapping(method = RequestMethod.GET, produces = "application/json")
    @JsonView(View.Secure.class)
    public ResponseEntity<?> getAllUsers(){
        return createUserListResponse();
    }

My View class:

public class View {

    public static class Secure {}
}

I've expected that response will contain only "password" field, but instead it contains nothing. When i remove annotation @JsonView(View.Secure.class) from Controller - it works as usual and returns all fields. What am i doing wrong? Is it required to add some additional configuration into Spring config?

I used this tutorial: https://spring.io/blog/2014/12/02/latest-jackson-integration-improvements-in-spring

ivan_ochc
  • 392
  • 5
  • 22
  • What if your method returns a List of Entity objects instead of the ResponseEntity? – Cristian Greco Mar 29 '15 at 16:30
  • 1
    Hi. I've figured out in what was a problem. This method: `public ResponseEntity> getAllUsers(){ return createUserListResponse(); }` calls another method which returns list of Entity objects and then create new ResponseEntity: `return new ResponseEntity(users, HttpStatus.OK);` I just annotate field in UserListVO class: `public class UserListVO { @JsonView(View.Secure.class) private List users; }` And it worked. – ivan_ochc Mar 29 '15 at 17:14

0 Answers0