Here you can find the source of unmarshallXml(final String string, final Class
static <OBJECT_TYPE> OBJECT_TYPE unmarshallXml(final String string, final Class<OBJECT_TYPE> type)
//package com.java2s; import java.io.StringReader; import java.util.Map; import java.util.Map.Entry; import javax.xml.bind.JAXBContext; import javax.xml.bind.JAXBException; import javax.xml.bind.Unmarshaller; public class Main { static <OBJECT_TYPE> OBJECT_TYPE unmarshallXml(final String string, final Class<OBJECT_TYPE> type) { return unmarschall(string, type, null); }/* ww w . j a va 2 s . c o m*/ private static <OBJECT_TYPE> OBJECT_TYPE unmarschall(final String stringRepresentation, final Class<OBJECT_TYPE> type, final Map<String, Object> unmarchallerProps) { try { return unmarschallImpl(stringRepresentation, type, unmarchallerProps); } catch (final JAXBException e) { throw new RuntimeException(e); } } @SuppressWarnings("unchecked") private static <OBJECT_TYPE> OBJECT_TYPE unmarschallImpl(final String stringRepresentation, final Class<OBJECT_TYPE> type, final Map<String, Object> unmarchallerProps) throws JAXBException { final JAXBContext context = JAXBContext.newInstance(type); final Unmarshaller unmarshaller = context.createUnmarshaller(); if (unmarchallerProps != null) { for (final Entry<String, Object> property : unmarchallerProps.entrySet()) { unmarshaller.setProperty(property.getKey(), property.getValue()); } } return (OBJECT_TYPE) unmarshaller.unmarshal(new StringReader(stringRepresentation)); } }