Java 8 Marshaller - top ranked examples from Open Source projects

These code examples were ranked by Codota’s semantic indexing as the best open source examples for Java 8 Marshaller class.

This code example shows how to use the following methods:marshal, setProperty
 
   @Test
   public void marshallAppCategories() throws Exception {
       JAXBContext jaxbContext=JAXBContext.newInstance("org.jboss.resteasy.test.providers.atom.app");
       Marshaller marshaller = jaxbContext.createMarshaller();
       marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE);
       marshaller.setProperty(Marshaller.JAXB_FRAGMENT, Boolean.FALSE);
       marshaller.setProperty(Marshaller.JAXB_ENCODING, "UTF-8");
       
       AppCategories appCategories = new AppCategories();
       appCategories.setFixed(true);
       appCategories.setScheme("http://example.com/cats/big3");
       Category category1 = new Category();
       category1.setTerm("animal");
       appCategories.getCategory().add(category1);
       Category category2 = new Category();
       category2.setTerm("vegetable");
       appCategories.getCategory().add(category2);
       Category category3 = new Category();
       category3.setTerm("mineral");

7
CodeRank
Connect your IDE to all the code out there  Get Codota for Java
This code example shows how to use the following methods:marshal, setProperty
      Marshaller marshaller = ctx.createMarshaller();
      XmlSchema xmlSchema = PurchaseOrderType.class.getPackage().getAnnotation(XmlSchema.class);
      XmlNamespacePrefixMapper mapper = new XmlNamespacePrefixMapper(xmlSchema.xmlns());
      try 
      { 
         marshaller.setProperty("com.sun.xml.bind.namespacePrefixMapper", mapper);
      } 
      catch (PropertyException e)
      { 
         logger.warn(e.getMessage(), e);
      } 
      marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true);
      ObjectFactory factory = new ObjectFactory();
      marshaller.marshal(factory.createPurchaseOrder(po), System.out);
   } 
} 
7
CodeRank
Connect your IDE to all the code out there  Get Codota for Java
This code example shows how to use the following methods:marshal, setProperty
   @Override 
   public <T> String toXML(final Object src, final Class<T> type) throws IOException {
      try { 
         JAXBContext context = JAXBContext.newInstance(type);
         Marshaller marshaller = context.createMarshaller();
         marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, prettyPrint);
         StringWriter writer = new StringWriter();
         marshaller.marshal(src, writer);
         return writer.toString();
      } catch (JAXBException ex) {
         throw new IOException("Could not marshall object", ex);
      } 
   } 
 
   @SuppressWarnings("unchecked") 
   @Override 
   public <T> T fromXML(final String xml, final Class<T> type) throws IOException {
      try { 
         StringReader reader = new StringReader(xml);
         JAXBContext context = JAXBContext.newInstance(type);
6
CodeRank
Connect your IDE to all the code out there  Get Codota for Java
This code example shows how to use the following methods:marshal, setProperty
    @Test
    public void marshallAppService() throws Exception {
        JAXBContext jaxbContext = JAXBContext
                .newInstance("org.jboss.resteasy.test.providers.atom.app");
        Marshaller marshaller = jaxbContext.createMarshaller();
        marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE);
        marshaller.setProperty(Marshaller.JAXB_FRAGMENT, Boolean.FALSE);
        marshaller.setProperty(Marshaller.JAXB_ENCODING, "UTF-8");
 
        AppService service = new AppService();
 
        AppWorkspace workspace1 = new AppWorkspace();
        workspace1.setTitle("Main Site");
        AppCollection collection1 = new AppCollection();
        collection1.setHref("http://example.org/blog/main");
        collection1.setTitle("My Blog Entries");
        AppCategories categories1 = new AppCategories();
        categories1.setHref("http://example.com/cats/forMain.cats");
        collection1.getCategories().add(categories1);
        workspace1.getCollection().add(collection1);

7
CodeRank
Connect your IDE to all the code out there  Get Codota for Java
This code example shows how to use the following methods:setProperty
            final Class elementType = getElementClass(type, genericType);
            final Charset charset = getCharset(mediaType);
            final String charsetName = charset.name();
 
            final Marshaller m = getMarshaller(elementType, mediaType);
            m.setProperty(Marshaller.JAXB_FRAGMENT, true);
            if (charset != UTF8) {
                m.setProperty(Marshaller.JAXB_ENCODING, charsetName);
            } 
            setHeader(m, annotations);
            writeList(elementType, c, mediaType, charset, m, entityStream);
        } catch (JAXBException ex) {
            throw new InternalServerErrorException(ex);
        } 
    } 
 
    /** 
     * Write a collection of JAXB objects as child elements of the root element. 
     * 
     * @param elementType  the element type in the collection. 
6
CodeRank
Connect your IDE to all the code out there  Get Codota for Java
This code example shows how to use the following methods:marshal, setProperty
    protected void persistXMLDocument(String fileName, Object xmlObject) {
 
        try { 
            JAXBContext context = JAXBContext.newInstance(xmlObject.getClass());
            Marshaller m = context.createMarshaller();
            m.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true);
            m.setProperty(Marshaller.JAXB_FRAGMENT, true);
 
            File file = new File(fileWorkArea.getFilePathLocation() + fileName);
            if (LOG.isTraceEnabled()) {
                LOG.trace("Persisting SiteMap document " + file.getAbsolutePath());
            } 
 
            if (!file.exists()) {
                file.createNewFile();
            } 
            Writer writer = new BufferedWriter(new FileWriter(file.getAbsoluteFile()));
            writer.write("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n");
            m.marshal(xmlObject, writer);
            writer.close();

6
CodeRank
Connect your IDE to all the code out there  Get Codota for Java
This code example shows how to use the following methods:marshal, setProperty
	} 
	 
	protected void writeBeans(OutputStream out, Beans beans) throws IOException {
		try { 
    	Marshaller marshaller = beansJaxbContext.createMarshaller();
    	marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE);
    	marshaller.setProperty(Marshaller.JAXB_SCHEMA_LOCATION, "http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd");
    	 
    	marshaller.marshal(beans, out);
    } catch (JAXBException jaxbe) {
    	throw new IOException(jaxbe);
    } 
	} 
	 
	protected void validateArtifactTargets(File repositoryFolder, File shareFolder) {
		if(repositoryFolder == null || shareFolder == null) {
			throw new AlfrescoSimpleWorkflowException("Both repositoryFolder and shareFolder are required."); 
		} 
		if(!repositoryFolder.exists()) {
			throw new AlfrescoSimpleWorkflowException("The repository target folder does not exist: " + repositoryFolder.getAbsolutePath());
6
CodeRank
Connect your IDE to all the code out there  Get Codota for Java
This code example shows how to use the following methods:setProperty
            OutputStream entityStream) throws IOException {
        try { 
            final Marshaller m = getMarshaller(t.getDeclaredType(), mediaType);
            final Charset c = getCharset(mediaType);
            if (c != UTF8) {
                m.setProperty(Marshaller.JAXB_ENCODING, c.name());
            } 
            setHeader(m, annotations);
            writeTo(t, mediaType, c, m, entityStream);
        } catch (JAXBException ex) {
            throw new InternalServerErrorException(ex);
        } 
    } 
 
    protected abstract void writeTo(JAXBElement<?> t, MediaType mediaType, Charset c,
                                    Marshaller m, OutputStream entityStream)
            throws JAXBException;
} 
6
CodeRank
Connect your IDE to all the code out there  Get Codota for Java
This code example shows how to use the following methods:marshal, setProperty, setSchema
This code example shows how to use the following methods:setProperty
            OutputStream entityStream) throws IOException {
        try { 
            final Marshaller m = getMarshaller(type, mediaType);
            final Charset c = getCharset(mediaType);
            if (c != UTF8) {
                m.setProperty(Marshaller.JAXB_ENCODING, c.name());
            } 
            setHeader(m, annotations);
            writeTo(t, mediaType, c, m, entityStream);
        } catch (JAXBException ex) {
            throw new InternalServerErrorException(ex);
        } 
    } 
 
    /** 
     * Marshal an instance of a JAXB type. 
     * <p> 
     * Implementing classes may override this method. 
     * 
     * @param t            the instance of the JAXB type. 
6
CodeRank
Connect your IDE to all the code out there  Get Codota for Java
See Code Examples for Java 8 Marshaller Methods: