Here you can find the source of xmlToObject(String xml, Class
Parameter | Description |
---|---|
xml | a parameter |
classe | a parameter |
public static <T> T xmlToObject(String xml, Class<T> classe) throws JAXBException
//package com.java2s; //License from project: Open Source License import javax.xml.bind.*; import javax.xml.transform.stream.StreamSource; import java.io.*; public class Main { /**//from ww w . j a v a 2 s .c o m * Transforma o String do XML em Objeto * * @param xml * @param classe * @return <T> T */ public static <T> T xmlToObject(String xml, Class<T> classe) throws JAXBException { JAXBContext context = JAXBContext.newInstance(classe); Unmarshaller unmarshaller = context.createUnmarshaller(); return unmarshaller.unmarshal(new StreamSource(new StringReader(xml)), classe).getValue(); } }