Here you can find the source of createJaxbContextFor(Object obj, Class>[] classes)
private static JAXBContext createJaxbContextFor(Object obj, Class<?>[] classes) throws JAXBException
//package com.java2s; //License from project: Open Source License import java.util.Arrays; import java.util.HashSet; import java.util.Set; import javax.xml.bind.JAXBContext; import javax.xml.bind.JAXBException; public class Main { private static JAXBContext createJaxbContextFor(Object obj, Class<?>[] classes) throws JAXBException { Set<Class<?>> classSet = new HashSet<>(); classSet.addAll(Arrays.asList(classes)); classSet.add(obj.getClass());/*from w w w . j av a 2s . co m*/ return JAXBContext.newInstance(classSet.toArray(new Class<?>[0])); } }