Java XML JAXB Marshaller createJAXBMarshaller(JAXBContext jaxbContext)

Here you can find the source of createJAXBMarshaller(JAXBContext jaxbContext)

Description

create JAXB Marshaller

License

Apache License

Declaration

private static Marshaller createJAXBMarshaller(JAXBContext jaxbContext) throws JAXBException 

Method Source Code

//package com.java2s;
/**/*ww  w  .ja va 2 s .c o  m*/
 * Copyright 2014 SAP AG
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

import javax.xml.bind.JAXBContext;

import javax.xml.bind.JAXBException;
import javax.xml.bind.Marshaller;

public class Main {
    private static final String XML_HEADER = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>";

    private static Marshaller createJAXBMarshaller(JAXBContext jaxbContext) throws JAXBException {
        Marshaller jaxbMarshaller = jaxbContext.createMarshaller();

        // configure JAXB
        jaxbMarshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true);
        jaxbMarshaller.setProperty(Marshaller.JAXB_FRAGMENT, true);
        jaxbMarshaller.setProperty("com.sun.xml.bind.xmlHeaders", XML_HEADER);

        return jaxbMarshaller;
    }
}

Related

  1. createMarshall(String pkgName)
  2. createMarshaller()
  3. createMarshaller(Class clazz, Map settings)
  4. createMarshaller(Class clazz)