Skip to content

@JsonView not working with Resources [SPR-12552] #17154

Closed
@spring-projects-issues

Description

@spring-projects-issues

David Harrigan opened SPR-12552 and commented

Hi,

Spring 4.1.3
Jackson 2.4.4

I have a class that looks something like this:

public class Foo {

 public interface Summary{}

 @JsonView(Foo.Summary.class)
 private String name;

 private String password;

}

and a controller that looks something like this:

@JsonView(Foo.Summary.class)
public ResponseEntity<PagedResources<Resource<Foo>>> getFoos() {
    final Page<Foo> foos =  serviceLayer.getFoos();
    return new ResponseEntity<>(pagedResourcesAssember.toResource(foos), HttpStatus.OK);
}

However, when I get the values returned, they include everything:

{
 "links": {
     .....
     .....
 },
 "content" : [
    {
    "name": "billy",
    "password": "sssh"
    },
    {
    "name": "goat",
    "password": "drowssap"
    }
  ],
  "pages": {
     ....
     ....
   }
}

As you can see, the @JsonView is not being honoured during the serialization of the Content data as the "password" field is being included in the serialization.

Thank you.

-=david=-


Affects: 4.1.3

Metadata

Metadata

Assignees

Labels

in: webIssues in web modules (web, webmvc, webflux, websocket)status: declinedA suggestion or change that we don't feel we should currently apply

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions