Hmm, seems like some clash of JDK internals vs the jaxb repackaged
classes. Would you please file issue with reproducible testcase so that
we can evaluate? Thanks,
MartiNG
On 10/13/2011 04:13 PM, Vyacheslav Zholudev wrote:
> Hi,
>
> I want to unmarshal second level XML elements using JAXB 2, and I'm using
> Stax API to parse an XML document.
> My code is:
> XMLInputFactory factory = XMLInputFactory.newInstance();
> FileReader fr = new FileReader(fileName);
> XMLEventReader xmler = factory.createXMLEventReader(fr);
> EventFilter filter = new EventFilter() {
> public boolean accept(XMLEvent event) {
> return event.isStartElement();
> }
> };
>
> XMLEventReader reader = factory.createFilteredReader(xmler, filter);
> reader.nextEvent(); //skipping the root element
>
> JAXBContext ctx = JAXBContext.newInstance(Foo.class);
> Unmarshaller um = ctx.createUnmarshaller();
> while (reader.peek() != null) {
> Object o = um.unmarshal(xmler);
> if (o instance of Foo) {...}
> }
> fr.close();
>
> I'm getting the following exception:
>
> Exception in thread "main" java.lang.ClassCastException:
> com.sun.xml.internal.stream.events.EntityReferenceEvent cannot be cast to
> javax.xml.stream.events.Characters
> at
> com.sun.xml.internal.stream.events.DummyEvent.asCharacters(DummyEvent.java:117)
> at
> com.sun.xml.internal.bind.v2.runtime.unmarshaller.StAXEventConnector.handleCharacters(StAXEventConnector.java:196)
> at
> com.sun.xml.internal.bind.v2.runtime.unmarshaller.StAXEventConnector.bridge(StAXEventConnector.java:127)
> at
> com.sun.xml.internal.bind.v2.runtime.unmarshaller.UnmarshallerImpl.unmarshal0(UnmarshallerImpl.java:392)
> at
> com.sun.xml.internal.bind.v2.runtime.unmarshaller.UnmarshallerImpl.unmarshal(UnmarshallerImpl.java:368)
> .....
>
> And a problematic XML element contains an entity in one of text nodes that
> is defined in the included DTD.
>
> How can I solve the problem? (Unmarshaling using SAX API works just fine)
>
> Thanks in advance!
--
Martin Grebac, GlassFish/Metro/JAXWS/JAXB/Tooling at Oracle
http://blogs.oracle.com/mgrebac
ICQ: 93478885