Search in sources :

Example 6 with Marshaller

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();
}
Also used : Marshaller(javax.xml.bind.Marshaller) StringWriter(java.io.StringWriter) JAXBContext(javax.xml.bind.JAXBContext)

Example 7 with Marshaller

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);
    }
}
Also used : Marshaller(javax.xml.bind.Marshaller) JAXBException(javax.xml.bind.JAXBException) JobConsoleException(com.dangdang.ddframe.job.lite.console.exception.JobConsoleException)

Example 8 with Marshaller

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);
    }
}
Also used : Path(java.nio.file.Path) Marshaller(javax.xml.bind.Marshaller) OutputStream(java.io.OutputStream) JAXBException(javax.xml.bind.JAXBException) IOException(java.io.IOException)

Example 9 with Marshaller

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));
}
Also used : Marshaller(javax.xml.bind.Marshaller) Test(org.junit.Test)

Example 10 with Marshaller

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));
}
Also used : Marshaller(javax.xml.bind.Marshaller) Test(org.junit.Test)

Aggregations

Marshaller (javax.xml.bind.Marshaller)214 JAXBContext (javax.xml.bind.JAXBContext)129 JAXBException (javax.xml.bind.JAXBException)75 StringWriter (java.io.StringWriter)73 ByteArrayOutputStream (java.io.ByteArrayOutputStream)22 File (java.io.File)22 Test (org.junit.Test)21 IOException (java.io.IOException)19 FileOutputStream (java.io.FileOutputStream)18 Unmarshaller (javax.xml.bind.Unmarshaller)18 JAXBElement (javax.xml.bind.JAXBElement)16 ByteArrayInputStream (java.io.ByteArrayInputStream)12 Writer (java.io.Writer)11 Document (org.w3c.dom.Document)8 InputStream (java.io.InputStream)7 QName (javax.xml.namespace.QName)7 Schema (javax.xml.validation.Schema)7 Diff (org.custommonkey.xmlunit.Diff)7 ArrayList (java.util.ArrayList)6 SchemaFactory (javax.xml.validation.SchemaFactory)6