How can a @JsonView working with jersey

谁说胖子不能爱 提交于 2019-12-04 08:12:54

问题


I want to return different fields with different views for one object. But it always return all the fields. I created 3 different views:

public class Views {
    public static class PublicView { }
    public static class ExtendedPublicView extends PublicView { }
    public static class InternalView extends ExtendedPublicView { }
}

Then in the 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;
}

Then add @JsonView to

@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 ){

}

回答1:


ok , i fix this several days ago. I check the source code of jackson I used that time , there were nothing doing about the @json view. That version I remember is 1.8.* Now I change to a newer one . it works



来源:https://stackoverflow.com/questions/17769101/how-can-a-jsonview-working-with-jersey

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!