All,
I am receiving a ClassCastException when attempting to marshall a JAXME (version 0.4) generated object to a string. The exception is:
java.lang.RuntimeException: java.lang.ClassCastException
at org.apache.ws.jaxme.impl.JMMarshallerImpl.marshal(JMMarshallerImpl.java:358)
at org.apache.ws.jaxme.impl.JMMarshallerImpl.marshal(JMMarshallerImpl.java:390)
The exception is thrown when attempting to marshall a JAXME generated object into a string. The snippet below shows the problem.
com.mycompany.myproject.jaxme.data.ObjectFactory factory = new com.mycompany.myproject.jaxme.data.ObjectFactory();
com.mycompany.myproject.jaxme.data.MyTestClass o = factory.createMyTestClass();
//set properties etc.
//etc.
//etc.
String result;
StringWriter writer = new StringWriter();
JAXBContext context = JAXBContext.newInstance("com.mycompany.myproject.jaxme.data");
Marshaller marshaller = context.createMarshaller();
marshaller.marshal(o, writer); //exception is thrown here
result = writer.toString();
Looking at the JMMarshallerImpl class implementation it appears the exception is caused when the marshaller tries to cast the MyTestClass instance as a JMElement. The classes I have generated are fairly standard and I’m following the documentation for marshalling objects into a string so I’m uncertain about the source of this error. Any ideas are very much appreciated. Also, if there is an alternative way I should be marshalling objects into a string please advise.
Thanks in advance for your help!
Jason