Dear all,
I just have some practice with SPring documentation example on StaxEventItemReader and XStream unmarshalling
cf doc §6.7.1 StaxEventItemReader
It doesn't seem to work and i receive the following exception:
Below the bloc of code i've tested:Code:ava.lang.UnsupportedOperationException: XStreamMarshaller does not support unmarshalling using SAX XMLReaders at org.springframework.oxm.xstream.XStreamMarshaller.unmarshalSaxReader(XStreamMarshaller.java:460)
Unfortunately, this code doesn't work because inside the read method, StaxEventItemReader initializes a Source of type org.springframework.xml.transform.StaxSource which implements SAXSourceCode:@SuppressWarnings("unchecked") @Test public void testStaxReader () throws Exception { StaxEventItemReader xmlStaxEventItemReader = new StaxEventItemReader(); Resource resource = new FileSystemResource("src/test/resources/data/input/spring.xml.customer.xml") ; Map aliases = new HashMap(); aliases.put("customer","com.natixis.aws.customer.CustomerCredit"); XStreamMarshaller marshaller = new XStreamMarshaller(); marshaller.setAliases(aliases); xmlStaxEventItemReader.setUnmarshaller(marshaller); xmlStaxEventItemReader.setResource(resource); xmlStaxEventItemReader.setFragmentRootElementName("customer"); xmlStaxEventItemReader.open(new ExecutionContext()); boolean hasNext = true; CustomerCredit credit = null; while (hasNext) { credit = (CustomerCredit)xmlStaxEventItemReader.read(); if (credit == null) { hasNext = false; } else { System.out.println(credit); } } xmlStaxEventItemReader.close(); }
and the XStreamMarshaller doesn't support this operation:Code:protected T doRead() throws Exception { if (noInput) { return null; } T item = null; if (moveCursorToNextFragment(fragmentReader)) { fragmentReader.markStartFragment(); @SuppressWarnings("unchecked") T mappedFragment = (T) unmarshaller.unmarshal(new StaxSource(fragmentReader)); item = mappedFragment; fragmentReader.markFragmentProcessed(); } return item; }
Any help would be very appreciated...Code:@Override protected Object unmarshalSaxReader(XMLReader xmlReader, InputSource inputSource) throws XmlMappingException, IOException { throw new UnsupportedOperationException( "XStreamMarshaller does not support unmarshalling using SAX XMLReaders"); }
Thanks in advance


Reply With Quote