How to Serialize Hibernate Collections Properly?

后端 未结 3 2068
时光取名叫无心
时光取名叫无心 2020-12-17 06:37

I\'m trying to serialize objects from a database that have been retrieved with Hibernate, and I\'m only interested in the objects\' actual data in its entirety (cycles inclu

3条回答
  •  天命终不由人
    2020-12-17 07:02

    What generally seems to be the best way to do it, and the way I am currently doing it is to have another layer of DTO objects. This way you can exclude data that you don't want to go over the channel as well as limit the depth to which the graph is serialized. I use Dozer for my current DTO (Data Transfer Object) from Hibernate objects to the Flex client.

    It works great, with a few caveats:

    • It's not fast, in fact it's downright slow. If you send a lot of data, Dozer will not perform very well. This is mostly because of the Reflection involved in performing its magic.
    • In a few cases you'll have to write custom converters for special behavior. These work very well, but they are bi-directional. I personally had to hack the Dozer source to allow uni-directional custom converters.

提交回复
热议问题