Hibernate / JPA友好的Jackson Serializer支持Jackson 1.8 [英] Hibernate / JPA friendly Jackson Serializer supporting Jackson 1.8

查看:211
本文介绍了Hibernate / JPA友好的Jackson Serializer支持Jackson 1.8的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

http:// kyrill007中的自定义 BeanSerializerFactory .livejournal.com / 2577.html 是我发现的允许通过Spring 3.0直接向JSON抛出持久性bean的唯一定制解决方案,并且它可以工作,它仅序列化非初始化(懒惰)属性/集合(这允许我将实体POJO用作DTO,因为我只初始化了我想要的东西,还没有初始化,没有被序列化为JSON)

但是,这很有效与杰克逊1.6,我想升级到杰克逊1.8,以解决Java泛型(希望)的问题,现在的定制解决方案不编译。



所以我的问题是


  • 什么是推荐的方式来自动序列化实体到JSON而不需要DTO

  • 除了上面的

  • 之外,还有官方的Hibernate Aware Jackson BeanSerializerFactory
  • 我开始害怕,如果这很难找到,也许我的做法不是最好的。
  • 建议使用Spring 3.0 MVC做REST风格的Ajax的方式是什么和JSON?


要解决的问题是
$ b $ ul

  • 不自动序列化懒惰属性/集合(如上面的自定义代码所做的那样)

  • 支持Java泛型和某种类型的客户端对象模式/验证
  • get的作用应该在保存时工作,并允许部分对象图被安全地返回



  • 有什么吗?是否必须为每个实体手动编写DTO?,这是非常有用的

    解决方案

    虽然SO拥有许多专家,但您可能会考虑在杰克逊用户名单上提问。 Kirill(博客作者)很有反应,并且还有其他专家。

    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

    解决方案

    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.

    这篇关于Hibernate / JPA友好的Jackson Serializer支持Jackson 1.8的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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