@Test @Override @SuppressWarnings("unchecked") public void unmarshalPartialStaxSourceXmlStreamReader() throws Exception { XMLInputFactory inputFactory = XMLInputFactory.newInstance(); XMLStreamReader streamReader = inputFactory.createXMLStreamReader(new StringReader(INPUT_STRING)); streamReader.nextTag(); // skip to flights streamReader.nextTag(); // skip to flight Source source = StaxUtils.createStaxSource(streamReader); JAXBElement<FlightType> element = (JAXBElement<FlightType>) unmarshaller.unmarshal(source); FlightType flight = element.getValue(); testFlight(flight); }
@Test public void unmarshalStaxSourceXmlStreamReader() throws Exception { XMLInputFactory inputFactory = XMLInputFactory.newInstance(); XMLStreamReader streamReader = inputFactory.createXMLStreamReader(new StringReader(INPUT_STRING)); Source source = StaxUtils.createStaxSource(streamReader); Object flights = unmarshaller.unmarshal(source); testFlight(flights); }
@Test public void unmarshalStaxSourceXmlEventReader() throws Exception { XMLInputFactory inputFactory = XMLInputFactory.newInstance(); XMLEventReader eventReader = inputFactory.createXMLEventReader(new StringReader(INPUT_STRING)); Source source = StaxUtils.createStaxSource(eventReader); Object flights = unmarshaller.unmarshal(source); testFlights(flights); }
@Test public void unmarshalStaxSourceXmlStreamReader() throws Exception { XMLInputFactory inputFactory = XMLInputFactory.newInstance(); XMLStreamReader streamReader = inputFactory.createXMLStreamReader(new StringReader(INPUT_STRING)); Source source = StaxUtils.createStaxSource(streamReader); Object flights = unmarshaller.unmarshal(source); testFlights(flights); }
@Test public void unmarshalPartialStaxSourceXmlStreamReader() throws Exception { XMLInputFactory inputFactory = XMLInputFactory.newInstance(); XMLStreamReader streamReader = inputFactory.createXMLStreamReader(new StringReader(INPUT_STRING)); streamReader.nextTag(); // skip to flights assertEquals("Invalid element", new QName("http://samples.springframework.org/flight", "flights"), streamReader.getName()); streamReader.nextTag(); // skip to flight assertEquals("Invalid element", new QName("http://samples.springframework.org/flight", "flight"), streamReader.getName()); Source source = StaxUtils.createStaxSource(streamReader); Object flight = unmarshaller.unmarshal(source); testFlight(flight); }
/** * Creates a StAX {@link Source} for the given {@link XMLStreamReader}. Returns a {@link StAXSource} under JAXP 1.4 * or higher, or a {@link StaxSource} otherwise. * * @param streamReader the StAX stream reader * @return a source wrapping <code>streamReader</code> */ public static Source createStaxSource(XMLStreamReader streamReader) { if (JaxpVersion.isAtLeastJaxp14()) { return Jaxp14StaxHandler.createStaxSource(streamReader); } else { return new StaxSource(streamReader); } }