Here you can find the source of unmarshal(JAXBContext context, Class
public static <T> T unmarshal(JAXBContext context, Class<T> clazz, String source) throws JAXBException
//package com.java2s; //License from project: Apache License import javax.xml.bind.JAXBContext; import javax.xml.bind.JAXBException; import javax.xml.bind.Unmarshaller; import java.io.StringReader; public class Main { public static <T> T unmarshal(JAXBContext context, Class<T> clazz, String source) throws JAXBException { if (source == null) { return null; }//from w w w . j av a 2 s . c o m StringReader reader = new StringReader(source); if (context == null) { context = JAXBContext.newInstance(clazz); } Unmarshaller un = context.createUnmarshaller(); return (T) un.unmarshal(reader); } public static <T> T unmarshal(Class<T> clazz, String source) throws JAXBException { return unmarshal(null, clazz, source); } }