Java XML JAXB String to Object fromXml(@SuppressWarnings("rawtypes") Class clazz, String stringXml)

Here you can find the source of fromXml(@SuppressWarnings("rawtypes") Class clazz, String stringXml)

Description

from Xml

License

Open Source License

Declaration

public static Object fromXml(@SuppressWarnings("rawtypes") Class clazz, String stringXml) 

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.JAXBException;

import javax.xml.bind.Unmarshaller;

import javax.xml.transform.stream.StreamSource;

public class Main {
    public static Object fromXml(@SuppressWarnings("rawtypes") Class clazz, String stringXml) {
        JAXBContext context = null;
        try {//  w w  w . j a v  a  2  s . c om
            context = JAXBContext.newInstance(clazz);
            Unmarshaller unmarshaller = context.createUnmarshaller();
            return unmarshaller.unmarshal(new StreamSource(new StringReader(stringXml)));
        } catch (JAXBException e) {
            e.printStackTrace();
        }
        return null;
    }
}

Related

  1. converyToJavaBean(String xml, Class clazz)
  2. createObject(String xml, Object type)
  3. fromFile(Class jaxbClass, String fileName)
  4. fromStream(Class jaxbClass, InputStream is)
  5. fromStringToObject(String xmlString, Class xmlObjClass)
  6. fromXML(Class clazz, InputStream is)
  7. fromXml(Class tClass, InputStream inputStream)
  8. fromXml(File xmlPath, Class type)
  9. fromXML(final byte[] data, final Class type)