NullPointerException from moxy due to corrupted CycleDetectionStack [message #1108672] |
Sat, 14 September 2013 06:40 |
jason zhang Messages: 31 Registered: July 2009 |
Member |
|
|
I have one object A with a property whose type can only be decided at runtime. The only information I know is that the property can be serialized using JAXB.
So I give this property XmlAnyElement with a XmlAdapter.
<xml-any-element java-attribute="Format">
<xml-java-type-adapter value="com.flexdms.flexims.typedb.eclipselink.ObjectAdapter"/>
</xml-any-element>
public class ObjectAdapter extends XmlAdapter<Element, Object>
{
/*
*
* Class<?> relatedClasses[];
*
*
*
* public ObjectTransfomer(List<Class<?>> relatedClasses) { super();
* this.relatedClasses =relatedClasses.toArray(new Class<?>[0]); }
*/
// how to do json
@Override
public Element marshal(Object arg0) throws Exception
{
if (arg0==null)
{
return null;
}
Class<?> cls = arg0.getClass();
JAXBContext context = JAXBContext.newInstance(cls);
Marshaller marshaller = context.createMarshaller();
DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
dbf.setNamespaceAware(true);
DocumentBuilder db = dbf.newDocumentBuilder();
Document doc = db.newDocument();
Element root = doc.createElement("object");
root.setAttribute("cls", cls.getName());
doc.appendChild(root);
marshaller.setProperty("jaxb.fragment", true);
marshaller.marshal(arg0, root);
root=(Element) doc.removeChild(root);
return root;
}
}
Object A also has other relation and properties. When I marshal a single A, there is no problem. When I marshal multiple As, I got this exception
Caused by: java.lang.NullPointerException
at org.eclipse.persistence.internal.oxm.XMLCompositeObjectMappingNodeValue.marshal(XMLCompositeObjectMappingNodeValue.java:144)
at org.eclipse.persistence.internal.oxm.NodeValue.marshal(NodeValue.java:102)
at org.eclipse.persistence.internal.oxm.record.ObjectMarshalContext.marshal(ObjectMarshalContext.java:59)
at org.eclipse.persistence.internal.oxm.XPathNode.marshal(XPathNode.java:393)
at org.eclipse.persistence.internal.oxm.XPathObjectBuilder.buildRow(XPathObjectBuilder.java:238)
at org.eclipse.persistence.internal.oxm.TreeObjectBuilder.buildRow(TreeObjectBuilder.java:118)
at org.eclipse.persistence.internal.oxm.TreeObjectBuilder.buildRow(TreeObjectBuilder.java:1)
at org.eclipse.persistence.internal.oxm.XMLAnyCollectionMappingNodeValue.marshalSingleValue(XMLAnyCollectionMappingNodeValue.java:432)
at org.eclipse.persistence.internal.oxm.XMLAnyCollectionMappingNodeValue.marshal(XMLAnyCollectionMappingNodeValue.java:147)
at org.eclipse.persistence.internal.oxm.NodeValue.marshal(NodeValue.java:149)
at org.eclipse.persistence.internal.oxm.NodeValue.marshal(NodeValue.java:102)
at org.eclipse.persistence.internal.oxm.record.ObjectMarshalContext.marshal(ObjectMarshalContext.java:59)
at org.eclipse.persistence.internal.oxm.XPathNode.marshal(XPathNode.java:393)
at org.eclipse.persistence.internal.oxm.XPathObjectBuilder.buildRow(XPathObjectBuilder.java:238)
at org.eclipse.persistence.internal.oxm.TreeObjectBuilder.buildRow(TreeObjectBuilder.java:118)
at org.eclipse.persistence.internal.oxm.TreeObjectBuilder.buildRow(TreeObjectBuilder.java:1)
at org.eclipse.persistence.internal.oxm.XMLMarshaller.marshal(XMLMarshaller.java:743)
at org.eclipse.persistence.internal.oxm.XMLMarshaller.marshal(XMLMarshaller.java:1124)
at org.eclipse.persistence.internal.oxm.XMLMarshaller.marshal(XMLMarshaller.java:1027)
at org.eclipse.persistence.jaxb.JAXBMarshaller.marshal(JAXBMarshaller.java:604)
... 38 more
I traced the code to org.eclipse.persistence.internal.oxm.XMLMarshaller
line 813:NodeRecord contentHandlerRecord = new NodeRecord(node);
When the Marshaller inside of my Adapter reaches this line, the returned NodeRecord has a cycleDetectionStack with two items at stack, and currentIndex=0. The two items in the stack is from top marshaller. I just wonder how my inner/completely different marshaller can have some state from parent marshaller. Does moxy marshaller keep some information which is thread-local that can be shared by all marshaller from different JAXBContext?
I am trying to produce a simple test case, but so far I can not find a simple case to show this.
Does anyone have any suggestion on this one?
|
|
|
|
|
Powered by
FUDForum. Page generated in 0.03117 seconds