您好, 欢迎来到 !    登录 | 注册 | | 设为首页 | 收藏本站

在我的Json中返回一些对象

在我的Json中返回一些对象

您可以@JsonView用来控制渲染的内容。您可以在此Spring博客文章https://spring.io/blog/2014/12/02/latest- jackson-integration-improvements-in- spring中找到更多详细信息

假设您有View带有接口的此类Summary

public class View {
    interface Summary {}
}

然后,您可以像这样注释属性

@JsonView(View.Summary.class)
private String name;

@JsonView(View.Summary.class)
private String firstname;

然后您的请求映射:

@JsonView(View.Summary.class)
@RequestMapping(value = "/user", method = RequestMethod.GET)

这只会返回name并返回firstname结果JSON。

其他 2022/1/1 18:18:02 有445人围观

撰写回答


你尚未登录,登录后可以

和开发者交流问题的细节

关注并接收问题和回答的更新提醒

参与内容的编辑和改进,让解决方法与时俱进

请先登录

推荐问题


联系我
置顶