Java XML JAXB String to Object xmlToObject(String xml, Class classe)

Here you can find the source of xmlToObject(String xml, Class classe)

Description

Transforma o String do XML em Objeto

License

Open Source License

Parameter

Parameter Description
xml a parameter
classe a parameter

Return

T

Declaration

public static <T> T xmlToObject(String xml, Class<T> classe) throws JAXBException 

Method Source Code


//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();
    }
}

Related

  1. Xml2Object(String xmlString, Class clazz)
  2. xmlToJavaBean(String xml, Class c)
  3. xmlToJaxb(Class xmlClass, String xml)
  4. xmlToJaxb(Class xmlClass, String xml)
  5. xmlToObject(String xml, Class... type)
  6. XmlToObject(String xml, Class type)
  7. xmlToXhtml(T catalog, StreamSource xslt, StreamResult result)