use of jakarta.xml.bind.JAXBElement in project xades4j by luisgoncalves.
the class DefaultQualifyingPropertiesUnmarshaller method unmarshalProperties.
@Override
public void unmarshalProperties(Element qualifyingProps, QualifyingPropertiesDataCollector propertyDataCollector) throws UnmarshalException {
XmlQualifyingPropertiesType xmlQualifyingProps = null;
try {
// Create the JAXB unmarshaller and unmarshalProperties the root JAXB element
Unmarshaller unmarshaller = jaxbContext.createUnmarshaller();
JAXBElement<XmlQualifyingPropertiesType> qualifPropsElem = (JAXBElement<XmlQualifyingPropertiesType>) unmarshaller.unmarshal(qualifyingProps);
xmlQualifyingProps = qualifPropsElem.getValue();
} catch (jakarta.xml.bind.UnmarshalException ex) {
throw new UnmarshalException("Cannot bind XML elements to Java classes", ex);
} catch (JAXBException ex) {
throw new UnmarshalException("Cannot unmarshall properties. Error on JAXB unmarshalling.", ex);
}
// Iterate the modules to convert the different types of properties.
for (UnmarshallerModule module : modules) {
module.convertProperties(xmlQualifyingProps, qualifyingProps, propertyDataCollector);
}
}
use of jakarta.xml.bind.JAXBElement in project spring-framework by spring-projects.
the class Jaxb2UnmarshallerTests method unmarshalPartialStaxSourceXmlStreamReader.
@Test
@Override
@SuppressWarnings("unchecked")
public void unmarshalPartialStaxSourceXmlStreamReader() throws Exception {
XMLInputFactory inputFactory = XMLInputFactory.newInstance();
XMLStreamReader streamReader = inputFactory.createXMLStreamReader(new StringReader(INPUT_STRING));
// skip to flights
streamReader.nextTag();
// skip to flight
streamReader.nextTag();
Source source = StaxUtils.createStaxSource(streamReader);
JAXBElement<FlightType> element = (JAXBElement<FlightType>) unmarshaller.unmarshal(source);
FlightType flight = element.getValue();
testFlight(flight);
}
use of jakarta.xml.bind.JAXBElement in project spring-framework by spring-projects.
the class Jaxb2UnmarshallerTests method unmarshalAnXmlReferingToAWrappedXmlElementDecl.
@Test
@SuppressWarnings("unchecked")
public void unmarshalAnXmlReferingToAWrappedXmlElementDecl() throws Exception {
// SPR-10714
unmarshaller = new Jaxb2Marshaller();
unmarshaller.setPackagesToScan(new String[] { "org.springframework.oxm.jaxb" });
unmarshaller.afterPropertiesSet();
Source source = new StreamSource(new StringReader("<brand-airplane><name>test</name></brand-airplane>"));
JAXBElement<Airplane> airplane = (JAXBElement<Airplane>) unmarshaller.unmarshal(source);
assertThat(airplane.getValue().getName()).as("Unmarshalling via explicit @XmlRegistry tag should return correct type").isEqualTo("test");
}
use of jakarta.xml.bind.JAXBElement in project spring-framework by spring-projects.
the class StandardClasses method standardClassDataHandler.
public JAXBElement<DataHandler> standardClassDataHandler() {
DataSource dataSource = new URLDataSource(getClass().getResource("spring-ws.png"));
DataHandler dataHandler = new DataHandler(dataSource);
return new JAXBElement<>(NAME, DataHandler.class, dataHandler);
}
use of jakarta.xml.bind.JAXBElement in project jaxrs-api by eclipse-ee4j.
the class JaxbLinkTest method testSerializationOfJaxbLink.
@Test
public void testSerializationOfJaxbLink() throws Exception {
JAXBContext jaxbContext = JAXBContext.newInstance(Link.JaxbLink.class);
final Marshaller marshaller = jaxbContext.createMarshaller();
final Unmarshaller unmarshaller = jaxbContext.createUnmarshaller();
Map<QName, Object> expectedParams = new HashMap<QName, Object>();
final QName qName = new QName("http://example.ns", "foo");
expectedParams.put(qName, "test");
final URI expectedUri = URI.create("/foo/bar");
Link.JaxbLink expected = new Link.JaxbLink(expectedUri, expectedParams);
final StringWriter writer = new StringWriter();
JAXBElement<Link.JaxbLink> jaxbLinkJAXBElement = new JAXBElement<Link.JaxbLink>(new QName("", "link"), Link.JaxbLink.class, expected);
marshaller.marshal(jaxbLinkJAXBElement, writer);
final Link.JaxbLink actual = unmarshaller.unmarshal(new StreamSource(new StringReader(writer.toString())), Link.JaxbLink.class).getValue();
assertEquals(expected, actual, "Unmarshalled JaxbLink instance not equal to the marshalled one.");
assertEquals(expectedUri, actual.getUri(), "Unmarshalled JaxbLink instance URI not equal to original.");
assertEquals(expectedParams, actual.getParams(), "Unmarshalled JaxbLink instance params not equal to original.");
}
Aggregations