我想为一个对象返回具有不同视图的不同字段。但它总是返回所有字段。我创建了 3 个不同的视图:
public class Views {
public static class PublicView { }
public static class ExtendedPublicView extends PublicView { }
public static class InternalView extends ExtendedPublicView { }
}
然后在 User.java
@XmlRootElement()
public class User {
@JsonView(Views.PublicView.class)
private String username;
@JsonView(Views.PublicView.class)
private String employeeName;
@JsonView(Views.ExtendedPublicView.class)
private Date birthday;
@JsonView(Views.ExtendedPublicView.class)
private String mobile;
}
然后将@JsonView 添加到
@POST
@Consumes(MediaType.APPLICATION_FORM_URLENCODED)
@Produces(MediaType.APPLICATION_JSON)
@JsonView(Views.PublicView.class)
public GenericResponse auth(@FormParam("username") String username, @FormParam("password") String password ){
}