Java XML JAXB String to Object toObject(Class className, String strXml)

Here you can find the source of toObject(Class className, String strXml)

Description

to Object

License

Apache License

Declaration

public static Object toObject(Class className, String strXml) 

Method Source Code


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

import java.io.*;

import javax.xml.bind.JAXBContext;

import javax.xml.bind.Unmarshaller;

public class Main {

    public static Object toObject(Class className, String strXml) {
        Object object = null;//from   w  ww.  j  av a2 s. c  o m
        StringReader reader = null;
        try {
            reader = new StringReader(strXml);
            JAXBContext context = JAXBContext.newInstance(className);
            Unmarshaller unmarshaller = context.createUnmarshaller();
            object = unmarshaller.unmarshal(reader);
        } catch (Exception e) {
        } finally {
            if (reader != null) {
                reader.close();
                reader = null;
            }
        }
        return object;
    }
}

Related

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