Hibernate / JPA友好的Jackson Serializer支持Jackson 1.8 [英] Hibernate / JPA friendly Jackson Serializer supporting Jackson 1.8
问题描述
http:// kyrill007中的自定义 BeanSerializerFactory
.livejournal.com / 2577.html 是我发现的允许通过Spring 3.0直接向JSON抛出持久性bean的唯一定制解决方案,并且它可以工作,它仅序列化非初始化(懒惰)属性/集合(这允许我将实体POJO用作DTO,因为我只初始化了我想要的东西,还没有初始化,没有被序列化为JSON)
但是,这很有效与杰克逊1.6,我想升级到杰克逊1.8,以解决Java泛型(希望)的问题,现在的定制解决方案不编译。
所以我的问题是
之外,还有官方的Hibernate Aware Jackson BeanSerializerFactory
要解决的问题是
$ b $ ul
有什么吗?是否必须为每个实体手动编写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屋!