Java XML JAXB String to Object convertXmlToObj(Class clazz, String xmlStr)

Here you can find the source of convertXmlToObj(Class clazz, String xmlStr)

Description

convert Xml To Obj

License

Open Source License

Declaration

public static Object convertXmlToObj(Class clazz, String xmlStr) 

Method Source Code


//package com.java2s;
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 convertXmlToObj(Class clazz, String xmlStr) {
        try {/* www . jav a  2  s .  c om*/
            JAXBContext context = JAXBContext.newInstance(clazz);
            Unmarshaller unmarshaller = context.createUnmarshaller();
            return unmarshaller.unmarshal(new StringReader(xmlStr));
        } catch (JAXBException e) {
            e.printStackTrace();
        }
        return null;
    }
}

Related

  1. convertStringToJAXB(String str)
  2. convertToJAXBException(String msg, Throwable e)
  3. convertToObject(Class clazz, InputStream inputStream)
  4. convertToXmlFile(File file, Object source, Class... type)
  5. convertXmlFileToObject(Class clazz, String xmlPath)
  6. convertXMLToObject(byte[] data, Class clazz)
  7. converyToJavaBean(String xml, Class c)
  8. converyToJavaBean(String xml, Class c)
  9. converyToJavaBean(String xml, Class clazz)