Java XML JAXB String to Object toObject(String xml, Class clazz)

Here you can find the source of toObject(String xml, Class clazz)

Description

to Object

License

Open Source License

Declaration

public static <T> T toObject(String xml, Class<T> clazz) throws JAXBException 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

import java.io.StringReader;

import javax.xml.bind.JAXBContext;
import javax.xml.bind.JAXBElement;
import javax.xml.bind.JAXBException;

import javax.xml.bind.Unmarshaller;

import javax.xml.transform.stream.StreamSource;

public class Main {
    public static <T> T toObject(String xml, Class<T> clazz) throws JAXBException {
        JAXBContext jc = JAXBContext.newInstance(clazz);
        Unmarshaller um = jc.createUnmarshaller();
        StringReader reader = new StringReader(xml);
        StreamSource source = new StreamSource(reader);
        JAXBElement<T> elem = um.unmarshal(source, clazz);
        return elem.getValue();
    }/*  www.j a va2 s.  c om*/
}

Related

  1. fromXML(String xml, Class valueType)
  2. getXmlObject(String xml, Class cls)
  3. stringToObject(String s, Class theclass)
  4. toObject(Class className, String strXml)
  5. toObject(String xml, Class c)
  6. xml2obj(final Class cls, final String xml)
  7. xml2Object(String content, Class valueType)
  8. Xml2Object(String xmlString, Class clazz)
  9. xmlToJavaBean(String xml, Class c)