Details
-
Type:
Bug
-
Status:
Resolved
-
Priority:
Minor
-
Resolution: Fixed
-
Affects Version/s: 1.9
-
Fix Version/s: 2.0.0
-
Component/s: JAXB annotation handler
-
Labels:None
-
Environment:Java 1.7 with Jackson 1.9.2.
-
Number of attachments :
Description
I have a project using hibernate for its domain classes, and I'm now implementing marshalling for these (both JSON and XML). To avoid cyclic references, I have an XmlAdapter that downcasts the object to its superclass. This works fine for JAXB, and solves my problem with XML.
When I try to do the same in Jackson (with the JAXB annotation introspector) it does not see the actual Set<T>, but instead it sees the PersistenceSet from hibernate.
Right now I'm using a introspector pair where Jackson is the primary, so if I add @JsonProperty and @JsonSerialize (with a serializer that write out my downcasted version) it works fine. The serializer gets the correct object.
Is this the intended behavior ? It feels like a bug.
I am seeing the same problem, though with a PersistentBag instead of a PersistentSet. Relevant stacktrace:
org.codehaus.jackson.map.JsonMappingException: Unable to marshal: org.hibernate.collection.PersistentBag cannot be cast to Document (through reference chain: Document["documents"])
at org.codehaus.jackson.xc.XmlAdapterJsonSerializer.serialize(XmlAdapterJsonSerializer.java:40)
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)
at org.codehaus.jackson.map.ser.StdSerializerProvider._serializeValue(StdSerializerProvider.java:610)
at org.codehaus.jackson.map.ser.StdSerializerProvider.serializeValue(StdSerializerProvider.java:256)
at org.codehaus.jackson.map.ObjectMapper.writeValue(ObjectMapper.java:1604)
at XmlMappingTest.test(XmlMappingTest.java:82)
Property in question:
{ return documents; }@XmlElementWrapper(name = "documents")
@XmlElement(name = "document")
@XmlJavaTypeAdapter(DocumentReference.class)
@OneToMany(mappedBy = "parent", cascade = CascadeType.ALL)
@OrderBy("index asc")
public List<Document> getDocuments()