use of javax.xml.bind.Marshaller in project hadoop by apache.
the class TestRMWebServicesDelegationTokenAuthentication method getMarshalledAppInfo.
static String getMarshalledAppInfo(ApplicationSubmissionContextInfo appInfo) throws Exception {
StringWriter writer = new StringWriter();
JAXBContext context = JAXBContext.newInstance(ApplicationSubmissionContextInfo.class);
Marshaller m = context.createMarshaller();
m.marshal(appInfo, writer);
return writer.toString();
}
use of javax.xml.bind.Marshaller in project elastic-job by dangdangdotcom.
the class AbstractXmlRepositoryImpl method save.
@Override
public synchronized void save(final E entity) {
try {
Marshaller marshaller = jaxbContext.createMarshaller();
marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true);
marshaller.marshal(entity, file);
} catch (final JAXBException ex) {
throw new JobConsoleException(ex);
}
}
use of javax.xml.bind.Marshaller in project Mycat-Server by MyCATApache.
the class XmlProcessBase method baseParseAndWriteToXml.
/**
* 默认将bean序列化为xml对象信息并写入文件
* 方法描述
* @param user 用户对象
* @param inputPath
* @param name 当前的转换xml的dtd文件的信息
* @创建日期 2016年9月15日
*/
public void baseParseAndWriteToXml(Object user, String inputPath, String name) throws IOException {
try {
Marshaller marshaller = this.jaxContext.createMarshaller();
marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE);
marshaller.setProperty(Marshaller.JAXB_FRAGMENT, Boolean.TRUE);
if (null != name) {
marshaller.setProperty("com.sun.xml.internal.bind.xmlHeaders", String.format("<!DOCTYPE mycat:%1$s SYSTEM \"%1$s.dtd\">", name));
}
Path path = Paths.get(inputPath);
OutputStream out = Files.newOutputStream(path, StandardOpenOption.CREATE, StandardOpenOption.TRUNCATE_EXISTING, StandardOpenOption.WRITE);
marshaller.marshal(user, out);
} catch (JAXBException e) {
lOG.error("ZookeeperProcessListen parseToXml error:Exception info:", e);
} catch (IOException e) {
lOG.error("ZookeeperProcessListen parseToXml error:Exception info:", e);
}
}
use of javax.xml.bind.Marshaller in project feign by OpenFeign.
the class JAXBContextFactoryTest method buildsMarshallerWithFragmentProperty.
@Test
public void buildsMarshallerWithFragmentProperty() throws Exception {
JAXBContextFactory factory = new JAXBContextFactory.Builder().withMarshallerFragment(true).build();
Marshaller marshaller = factory.createMarshaller(Object.class);
assertTrue((Boolean) marshaller.getProperty(Marshaller.JAXB_FRAGMENT));
}
use of javax.xml.bind.Marshaller in project feign by OpenFeign.
the class JAXBContextFactoryTest method buildsMarshallerWithFormattedOutputProperty.
@Test
public void buildsMarshallerWithFormattedOutputProperty() throws Exception {
JAXBContextFactory factory = new JAXBContextFactory.Builder().withMarshallerFormattedOutput(true).build();
Marshaller marshaller = factory.createMarshaller(Object.class);
assertTrue((Boolean) marshaller.getProperty(Marshaller.JAXB_FORMATTED_OUTPUT));
}
Aggregations