Here you can find the source of getMarshaller(Class
private static <T> Marshaller getMarshaller(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 getMarshaller(Class<T> clazz) throws JAXBException { Marshaller marshaller = marshallers.get(clazz); if (marshaller == null) marshaller = createMarshaller(clazz); return marshaller; }//from www. j a v a 2 s .co m private static <T> Marshaller createMarshaller(Class<T> clazz) throws JAXBException { Marshaller marshaller = createJAXBContext(clazz).createMarshaller(); marshallers.put(clazz, marshaller); return marshaller; } private static <T> JAXBContext createJAXBContext(Class<T> clazz) throws JAXBException { return JAXBContext.newInstance(clazz); } }