If I use @JsonView
on a POJO and on a controller in Spring, my HATEOAS links are hidden. I can understand why this happens, because the _links
property isn't annotated with the correct view class, but it's not the behaviour I need in this case. Is there a way to always include the _links
property, regardless of using a view class or not?
My POJO looks something like:
@Entity(name = "groups")
@SequenceGenerator(name = "groups_groupid_seq", sequenceName = "groups_groupid_seq")
public class Group extends ResourceSupport {
@Id
@GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "groups_groupid_seq")
@JsonView(Views.Summary.class)
private long groupID;
@JsonView(Views.Full.class)
private String name;
/*
Getters & setters ...
*/
}
And my controller looks something like:
@RestController
@RequestMapping(path = "/group")
@ExposesResourceFor(Group.class)
public class GroupApiController {
@JsonView(Views.Summary.class)
@RequestMapping(path = "/", method = RequestMethod.GET)
public Iterable getPermittedGroups(
Authentication authentication) {
// load groups...
}
}
My HATEOAS configuration:
@Configuration
@EnableAspectJAutoProxy
@EnableEntityLinks
@EnableHypermediaSupport(type = EnableHypermediaSupport.HypermediaType.HAL)
public class HateoasConfig {
//
}
I don't have to use @JsonView
, so I'm happy to use an alternative. But I do need to be able to return different views on the same class, from different controller methods, otherwise I could use @JsonIgnore
.