1

I'm currently trying to serialize data that I've previously loaded via Hibernate. To recover type information I enabled default typing like this:

objectMapper.enableDefaultTyping(DefaultTyping.NON_CONCRETE_AND_ARRAYS,As.PROPERTY);

I also added identity-info to my entities via this anotation:

@JsonIdentityInfo(generator = ObjectIdGenerators.IntSequenceGenerator.class, property = "@id")

However when I deserialize @OneToMany-relations that I have, deserialization fails because the PersistentBag does not have a session at this point. Because my programm is running without a container I can not fix this issue easily.

I'm also aware of the fact that there is this hibernate-datatype module for jackson but this doesn't solve the problem (I guess that module is primaliry used for respecting the LAZY_LOADING-hibernate-property).

So my idea to fix this was to not serialize a PersistentBag but an ArrayList instead. Is there an easy way to do this or do I have to write my own serializer (which I tried but without beeing successful)?

4

1 回答 1

1

我通过将类型信息通过注释添加到我想要序列化的类并删除默认类型行来解决这个问题:

objectMapper.enableDefaultTyping(DefaultTyping.NON_CONCRETE_AND_ARRAYS,As.PROPERTY);

于 2013-08-12T09:47:45.920 回答