Java tutorial
//package com.java2s; import java.io.ByteArrayInputStream; import java.io.InputStream; import java.nio.charset.StandardCharsets; import javax.xml.bind.JAXBContext; import javax.xml.bind.JAXBException; import javax.xml.bind.Unmarshaller; public class Main { public static Object convertToPojoUsingString(String xml, Class... type) { Object result; try { JAXBContext context = JAXBContext.newInstance(type); Unmarshaller unmarshaller = context.createUnmarshaller(); InputStream stream = new ByteArrayInputStream(xml.getBytes(StandardCharsets.UTF_8)); result = unmarshaller.unmarshal(stream); } catch (JAXBException e) { throw new RuntimeException(e); } return result; } }