use of jakarta.xml.bind.Unmarshaller in project litiengine by gurkenlabs.
the class ResourceBundle method getResourceBundle.
private static ResourceBundle getResourceBundle(URL file) throws JAXBException, IOException {
final JAXBContext jaxbContext = XmlUtilities.getContext(ResourceBundle.class);
final Unmarshaller um = jaxbContext.createUnmarshaller();
try (InputStream inputStream = Resources.get(file)) {
// try to get compressed game file
final GZIPInputStream zipStream = new GZIPInputStream(inputStream);
return (ResourceBundle) um.unmarshal(zipStream);
} catch (final ZipException e) {
// if it fails to load the compressed file, get it from plain XML
return XmlUtilities.read(ResourceBundle.class, file);
}
}
use of jakarta.xml.bind.Unmarshaller in project litiengine by gurkenlabs.
the class XmlUtilities method read.
public static <T> T read(Class<T> cls, URL path) throws JAXBException {
final JAXBContext jaxbContext = getContext(cls);
if (jaxbContext == null) {
return null;
}
final Unmarshaller um = jaxbContext.createUnmarshaller();
um.setAdapter(new URLAdapter(path));
return cls.cast(um.unmarshal(path));
}
use of jakarta.xml.bind.Unmarshaller in project spring-framework by spring-projects.
the class AbstractJaxb2HttpMessageConverter method createUnmarshaller.
/**
* Create a new {@link Unmarshaller} for the given class.
* @param clazz the class to create the unmarshaller for
* @return the {@code Unmarshaller}
* @throws HttpMessageConversionException in case of JAXB errors
*/
protected final Unmarshaller createUnmarshaller(Class<?> clazz) {
try {
JAXBContext jaxbContext = getJaxbContext(clazz);
Unmarshaller unmarshaller = jaxbContext.createUnmarshaller();
customizeUnmarshaller(unmarshaller);
return unmarshaller;
} catch (JAXBException ex) {
throw new HttpMessageConversionException("Could not create Unmarshaller for class [" + clazz + "]: " + ex.getMessage(), ex);
}
}
use of jakarta.xml.bind.Unmarshaller in project spring-framework by spring-projects.
the class Jaxb2XmlDecoder method unmarshal.
private Object unmarshal(List<XMLEvent> events, Class<?> outputClass) {
try {
Unmarshaller unmarshaller = initUnmarshaller(outputClass);
XMLEventReader eventReader = StaxUtils.createXMLEventReader(events);
if (outputClass.isAnnotationPresent(XmlRootElement.class)) {
return unmarshaller.unmarshal(eventReader);
} else {
JAXBElement<?> jaxbElement = unmarshaller.unmarshal(eventReader, outputClass);
return jaxbElement.getValue();
}
} catch (UnmarshalException ex) {
throw new DecodingException("Could not unmarshal XML to " + outputClass, ex);
} catch (JAXBException ex) {
throw new CodecException("Invalid JAXB configuration", ex);
}
}
Aggregations