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

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

Description

xml To Object

License

Apache License

Declaration

public static Object xmlToObject(String xml, Class<?>... type) 

Method Source Code

//package com.java2s;
//License from project: Apache License 

import java.io.StringReader;

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

import javax.xml.bind.Unmarshaller;

public class Main {
    public static Object xmlToObject(String xml, Class<?>... type) {

        try {/*from w  ww.  j  a v  a 2s  .  c  o m*/

            JAXBContext jaxbContext = JAXBContext.newInstance(type);

            StringReader stringReader = new StringReader(xml);

            Unmarshaller jaxbUnmarshaller = jaxbContext
                    .createUnmarshaller();
            return jaxbUnmarshaller.unmarshal(stringReader);

        } catch (JAXBException e) {
            e.printStackTrace();
        }

        return null;
    }
}

Related

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