Hibernate / JPA 友好的 Jackson 序列化器支持 Jackson 1.8
但这在 Jackson 1.6 中运行良好,我想升级到 Jackson 1.8 以解决 Java 泛型的问题(希望如此),现在该自定义解决方案无法编译。
所以我的问题是,
- 在不需要 DTO 的情况下自动将实体序列化为 JSON 的推荐方法是什么?
- 除了上述之外,是否还有官方的 Hibernate Aware Jackson
BeanSerializerFactory
- 我开始担心如果有那么难发现,也许我的做法不是最好的一种,
- 那么使用 Spring 3.0 MVC 和 JSON 进行 RESTful Ajax 的推荐方法是什么?
要解决的问题是
- 不自动序列化惰性属性/集合(如上面的自定义代码所做的那样)
- 支持 Java 泛型和某种客户端对象模式/验证
- 在 get 上起作用的应该在 save 上起作用,并允许部分对象图安全回来了
有什么事吗?我必须为每个实体手动编写 DTO 吗?这太低效了
The custom BeanSerializerFactory
in http://kyrill007.livejournal.com/2577.html is the only custom solution I found to allow directly throwing persistent beans to JSON via Spring 3.0, and it works, it only serializes non initialized (lazy) attributes / collections (this allows me to use the entity Pojo as a DTO, as I initialize only what I want, and what is not initialized, doesn't get serialized to JSON)
But this worked well with Jackson 1.6, and I wanted to upgrade to Jackson 1.8 to solve the issue with Java Generics (hopefully) and now that custom solution is not compiling.
So my questions are
- What is the recomended way to auto serialize Entities to JSON without the need of DTOs
- Is there an official Hibernate Aware Jackson
BeanSerializerFactory
besides the above - I'm starting to fear that if it's that hard to find, maybe my practice is not the best one
- What is the recommended way to do RESTful Ajax then with Spring 3.0 MVC and JSON?
The problems to solve are
- Not serializing lazy attributes / collections automatially (as the custom code above does)
- Supporting Java Generics and some kind of a client side object schema / validation
- What works on get should work on save, and allow partial objects graphs to be returned safely
Is there Anything? do I have to manually write DTOs for every Entity?, this is so non productive
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
虽然 SO 有很多专家,但您也可以考虑询问 Jackson 用户列表。基里尔(博客文章的作者)反应敏捷,而且还有其他专家。
While SO has lots of experts, you might consider also asking on Jackson users list. Kirill (author of the blog entry) is responsive, and there are other experts there as well.