Here you can find the source of marshall(Class
@SuppressWarnings("unchecked") public static <T> T marshall(Class<T> c, String xml) throws JAXBException
//package com.java2s; //License from project: Open Source License import java.io.StringReader; import javax.xml.bind.JAXBContext; import javax.xml.bind.JAXBException; import javax.xml.bind.Unmarshaller; public class Main { @SuppressWarnings("unchecked") public static <T> T marshall(Class<T> c, String xml) throws JAXBException { T res;/*from w w w. ja va 2 s. co m*/ if (c == xml.getClass()) { res = (T) xml; } else { JAXBContext ctx = JAXBContext.newInstance(c); Unmarshaller unmarshaller = ctx.createUnmarshaller(); res = (T) unmarshaller.unmarshal(new StringReader(xml)); } return res; } }