use of jakarta.xml.bind.JAXBContext in project jaxrs-api by eclipse-ee4j.
the class JAXRSClientIT method getJaxbToken.
private static String getJaxbToken() {
JAXBElement<String> element = new JAXBElement<String>(new QName("content"), String.class, plaincontent);
try {
JAXBContext context = JAXBContext.newInstance(String.class);
java.io.StringWriter writer = new java.io.StringWriter();
context.createMarshaller().marshal(element, writer);
return writer.toString();
} catch (JAXBException e) {
throw new RuntimeException(e);
}
}
use of jakarta.xml.bind.JAXBContext in project spring-framework by spring-projects.
the class AbstractJaxb2HttpMessageConverter method createMarshaller.
/**
* Create a new {@link Marshaller} for the given class.
* @param clazz the class to create the marshaller for
* @return the {@code Marshaller}
* @throws HttpMessageConversionException in case of JAXB errors
*/
protected final Marshaller createMarshaller(Class<?> clazz) {
try {
JAXBContext jaxbContext = getJaxbContext(clazz);
Marshaller marshaller = jaxbContext.createMarshaller();
customizeMarshaller(marshaller);
return marshaller;
} catch (JAXBException ex) {
throw new HttpMessageConversionException("Could not create Marshaller for class [" + clazz + "]: " + ex.getMessage(), ex);
}
}
use of jakarta.xml.bind.JAXBContext in project xades4j by luisgoncalves.
the class BaseJAXBMarshaller method doJAXBMarshalling.
private void doJAXBMarshalling(Node qualifyingPropsNode, TXml xmlProps) throws MarshalException {
try {
// Create the JAXB marshaller.
JAXBContext jaxbContext = jaxbContexts.get(xmlProps.getClass());
Marshaller marshaller = jaxbContext.createMarshaller();
// Create the root JAXBElement.
Object propsElem = createPropsXmlElem(new ObjectFactory(), xmlProps);
// Marshal the properties.
marshaller.marshal(propsElem, qualifyingPropsNode);
} catch (JAXBException ex) {
throw new MarshalException("Error on JAXB marshalling", ex);
}
}
use of jakarta.xml.bind.JAXBContext 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.JAXBContext in project litiengine by gurkenlabs.
the class ResourceBundle method save.
public String save(final String fileName, final boolean compress) {
String fileNameWithExtension = fileName;
if (!fileNameWithExtension.endsWith("." + FILE_EXTENSION)) {
fileNameWithExtension += "." + FILE_EXTENSION;
}
final File newFile = new File(fileNameWithExtension);
if (newFile.exists()) {
try {
Files.delete(newFile.toPath().toAbsolutePath());
} catch (IOException e) {
log.log(Level.WARNING, e.getMessage(), e);
}
}
Collections.sort(this.getMaps());
Collections.sort(this.getSpriteSheets());
Collections.sort(this.getTilesets());
Collections.sort(this.getEmitters());
Collections.sort(this.getBluePrints());
Collections.sort(this.getSounds());
try (FileOutputStream fileOut = new FileOutputStream(newFile, false)) {
final JAXBContext jaxbContext = XmlUtilities.getContext(ResourceBundle.class);
final Marshaller jaxbMarshaller = jaxbContext.createMarshaller();
// output pretty printed
jaxbMarshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, false);
if (compress) {
final GZIPOutputStream stream = new GZIPOutputStream(fileOut);
jaxbMarshaller.marshal(this, stream);
stream.flush();
stream.close();
} else {
final ByteArrayOutputStream out = new ByteArrayOutputStream();
// first: marshal to byte array
jaxbMarshaller.marshal(this, out);
out.flush();
// second: postprocess xml and then write it to the file
XmlUtilities.saveWithCustomIndentation(new ByteArrayInputStream(out.toByteArray()), fileOut, 1);
out.close();
}
} catch (final JAXBException | IOException e) {
log.log(Level.SEVERE, e.getMessage(), e);
}
return newFile.toString();
}
Aggregations