use of javax.xml.bind.Marshaller in project cloudstack by apache.
the class BrocadeVcsApi method convertToString.
protected <T> String convertToString(T object) throws BrocadeVcsApiException {
final StringWriter stringWriter = new StringWriter();
try {
final JAXBContext context = JAXBContext.newInstance(object.getClass());
final Marshaller marshaller = context.createMarshaller();
marshaller.marshal(object, stringWriter);
} catch (final JAXBException e) {
s_logger.error("Failed to convert object to string : " + e.getMessage());
throw new BrocadeVcsApiException("Failed to convert object to string : " + e.getMessage());
}
final String str = stringWriter.toString();
s_logger.info(str);
return str;
}
use of javax.xml.bind.Marshaller in project asterixdb by apache.
the class ConfigureConfig method execCommand.
@Override
protected void execCommand() throws Exception {
configureCluster("local", "local.xml");
configureCluster("local", "local_chained_declustering_rep.xml");
configureCluster("local", "local_metadata_only_rep.xml");
configureCluster("demo", "demo.xml");
String installerConfPath = InstallerDriver.getManagixHome() + File.separator + InstallerDriver.MANAGIX_CONF_XML;
JAXBContext ctx = JAXBContext.newInstance(Configuration.class);
Unmarshaller unmarshaller = ctx.createUnmarshaller();
Configuration configuration = (Configuration) unmarshaller.unmarshal(new File(installerConfPath));
configuration.setConfigured(true);
configuration.getBackup().setBackupDir(InstallerDriver.getManagixHome() + File.separator + "backup");
configuration.getZookeeper().setHomeDir(InstallerDriver.getManagixHome() + File.separator + InstallerDriver.MANAGIX_INTERNAL_DIR + File.separator + "zookeeper_home");
configuration.getZookeeper().getServers().setJavaHome(System.getProperty("java.home"));
Marshaller marshaller = ctx.createMarshaller();
marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true);
marshaller.marshal(configuration, new FileOutputStream(installerConfPath));
}
use of javax.xml.bind.Marshaller 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 javax.xml.bind.Marshaller in project spring-framework by spring-projects.
the class Jaxb2RootElementHttpMessageConverter method writeToResult.
@Override
protected void writeToResult(Object o, HttpHeaders headers, Result result) throws IOException {
try {
Class<?> clazz = ClassUtils.getUserClass(o);
Marshaller marshaller = createMarshaller(clazz);
setCharset(headers.getContentType(), marshaller);
marshaller.marshal(o, result);
} catch (MarshalException ex) {
throw new HttpMessageNotWritableException("Could not marshal [" + o + "]: " + ex.getMessage(), ex);
} catch (JAXBException ex) {
throw new HttpMessageConversionException("Could not instantiate JAXBContext: " + ex.getMessage(), ex);
}
}
use of javax.xml.bind.Marshaller in project spring-framework by spring-projects.
the class Jaxb2XmlEncoder method encode.
@Override
protected Flux<DataBuffer> encode(Object value, DataBufferFactory dataBufferFactory, ResolvableType type, MimeType mimeType, Map<String, Object> hints) {
try {
DataBuffer buffer = dataBufferFactory.allocateBuffer(1024);
OutputStream outputStream = buffer.asOutputStream();
Class<?> clazz = ClassUtils.getUserClass(value);
Marshaller marshaller = jaxbContexts.createMarshaller(clazz);
marshaller.setProperty(Marshaller.JAXB_ENCODING, StandardCharsets.UTF_8.name());
marshaller.marshal(value, outputStream);
return Flux.just(buffer);
} catch (JAXBException ex) {
return Flux.error(ex);
}
}
Aggregations