我正在使用 Spring Roo 1.2.1 和 Jackson 1.9.7。在使用 json 序列化我的类 QueueOut 时,我得到一个 JsonMappingException。
我阅读了以下帖子,但没有找到适合我的解决方案:
我不知道为什么 JsonIgnore 不在属性 QueueOuts 的类队列中工作。我也试过 JsonManagedReference 但同样的错误。使用 Jackson 2.0.0 不是解决方案,因为 Spring 3.1 不支持它
有什么建议么?
这是我的堆栈跟踪的一部分:
Caused by: org.springframework.amqp.support.converter.MessageConversionException: Failed to convert Message content
at org.springframework.amqp.support.converter.JsonMessageConverter.createMessage(JsonMessageConverter.java:181)
at org.springframework.amqp.support.converter.AbstractMessageConverter.toMessage(AbstractMessageConverter.java:51)
at org.springframework.amqp.rabbit.core.RabbitTemplate.convertMessageIfNecessary(RabbitTemplate.java:482)
at org.springframework.amqp.rabbit.core.RabbitTemplate.convertAndSend(RabbitTemplate.java:358)
at org.springframework.amqp.rabbit.core.RabbitTemplate.convertAndSend(RabbitTemplate.java:346)
at de.company.prs.admin.server.amqp.AdminQueueConsumer.onMessage(AdminQueueConsumer.java:52)
at org.springframework.amqp.rabbit.listener.adapter.MessageListenerAdapter.onMessage(MessageListenerAdapter.java:328)
at org.springframework.amqp.rabbit.listener.AbstractMessageListenerContainer.doInvokeListener(AbstractMessageListenerContainer.java:505)
... 10 more
Caused by: org.codehaus.jackson.map.JsonMappingException: Infinite recursion (StackOverflowError) (through reference chain: de.company.prs.admin.server.domain.Queue["queueOuts"]->org.hibernate.collection.PersistentSet[0]->de.company.prs.admin.server.domain.QueueOut["queue"]->de.company.prs.admin.server.domain.Queue["queueOuts"]->org.hibernate.collection.PersistentSet[0]->de.company.prs.admin.server.domain.QueueOut["queue"]->de.company.prs.admin.server.domain.Queue["queueOuts"]->org.hibernate.collection.PersistentSet[0]->de.company.prs.admin.server.domain.QueueOut["queue"]->de.company.prs.admin.server.domain.Queue["queueOuts"]->org.hibernate.collection.PersistentSet[0]->de.company.prs.admin.server.domain.QueueOut["queue"]->de.company.prs.admin.server.domain.Queue["queueOuts"]->org.hibernate.collection.PersistentSet[0]->de.company.prs.admin.server.domain.QueueOut["queue"]->de.company.prs.admin.server.domain.Queue["queueOuts"]->org.hibernate.collection.PersistentSet[0]->de.company.prs.admin.server.domain.QueueOut["queue"]->de.company.prs.admin.server.domain.Queue["queueOuts"]->org.hibernate.collection.PersistentSet[0]->de.company.prs.admin.server.domain.QueueOut["queue"]->de.company.prs.admin.server.domain.Queue["queueOuts"]->org.hibernate.collection.PersistentSet[0]
at org.codehaus.jackson.map.ser.std.BeanSerializerBase.serializeFields(BeanSerializerBase.java:164)
at org.codehaus.jackson.map.ser.BeanSerializer.serialize(BeanSerializer.java:112)
at org.codehaus.jackson.map.ser.BeanPropertyWriter.serializeAsField(BeanPropertyWriter.java:446)
at org.codehaus.jackson.map.ser.std.BeanSerializerBase.serializeFields(BeanSerializerBase.java:150)
at org.codehaus.jackson.map.ser.BeanSerializer.serialize(BeanSerializer.java:112)
这是我的课:第一
@RooJavaBean
@RooToString
public class QueueOut {
private String name;
private String description;
@JsonIgnore
@ManyToOne
private GenericQueue genericQueue;
@ManyToOne (fetch = FetchType.EAGER)
private Queue queue;
}
第二
@RooJavaBean
@RooToString
@RooJpaActiveRecord
public class Queue {
private String name;
private String description;
@JsonIgnore
@OneToMany(cascade = CascadeType.ALL, mappedBy = "queue", fetch = FetchType.EAGER)
private Set<QueueOut> QueueOuts = new HashSet<QueueOut>();
}