我想为一个对象返回不同视图的不同视图。但它总是返回所有领域。 我创建了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 ){
}
答案 0 :(得分:1)