Here you can find the source of createMarshaller(Class
private static <T> Marshaller createMarshaller(Class<T> clazz) throws JAXBException
//package com.java2s; //License from project: Apache License import java.util.HashMap; import javax.xml.bind.JAXBContext; import javax.xml.bind.JAXBException; import javax.xml.bind.Marshaller; public class Main { private static HashMap<Class<?>, Marshaller> marshallers = new HashMap<>(); private static <T> Marshaller createMarshaller(Class<T> clazz) throws JAXBException { Marshaller marshaller = createJAXBContext(clazz).createMarshaller(); marshallers.put(clazz, marshaller); return marshaller; }//w w w. j a v a 2 s . c om private static <T> JAXBContext createJAXBContext(Class<T> clazz) throws JAXBException { return JAXBContext.newInstance(clazz); } }