@JsonView如何使用泽西 [英] How can a @JsonView working with jersey

查看:135
本文介绍了@JsonView如何使用泽西的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想为一个对象返回不同视图的不同视图。但它总是返回所有领域。
我创建了3个不同的视图:

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 { }
}

然后在User.java中

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;
}

然后将@JsonView添加到

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

}


推荐答案

好的,几天前我解决了这个问题。
我检查了那个时候使用的jackson的源代码,没有关于@json视图的事情。我记得那个版本是1.8。*
现在我换成了新版本。它的工作原理

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

这篇关于@JsonView如何使用泽西的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆