Java XML JAXB String to Object stringToObject(String s, Class theclass)

Here you can find the source of stringToObject(String s, Class theclass)

Description

string To Object

License

Open Source License

Declaration

public static Object stringToObject(String s, Class theclass) throws JAXBException 

Method Source Code


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

import java.io.ByteArrayInputStream;

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

import javax.xml.bind.Unmarshaller;

public class Main {
    public static Object stringToObject(String s, Class theclass) throws JAXBException {
        Object o = null;// ww  w .jav  a 2  s  .  c om
        ByteArrayInputStream input = new ByteArrayInputStream(s.getBytes());
        JAXBContext jaxbContext = JAXBContext.newInstance(theclass);
        Unmarshaller jaxbUnmarshaller = jaxbContext.createUnmarshaller();
        o = theclass.cast(jaxbUnmarshaller.unmarshal(input));
        return o;
    }
}

Related

  1. fromXml(String responseBody, Class c)
  2. fromXml(String xml, Class clazz)
  3. fromXml(String xml, Class type)
  4. fromXML(String xml, Class valueType)
  5. getXmlObject(String xml, Class cls)
  6. toObject(Class className, String strXml)
  7. toObject(String xml, Class c)
  8. toObject(String xml, Class clazz)
  9. xml2obj(final Class cls, final String xml)