Java XML JAXB String to Object createObject(String xml, Object type)

Here you can find the source of createObject(String xml, Object type)

Description

create Object

License

LGPL

Declaration

public static Object createObject(String xml, Object type) throws Exception 

Method Source Code


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

import java.io.ByteArrayInputStream;
import java.io.InputStream;

import javax.xml.bind.JAXBContext;

import javax.xml.bind.Unmarshaller;

public class Main {
    public static Object createObject(String xml, Object type) throws Exception {

        JAXBContext jc = JAXBContext.newInstance(type.getClass());
        //JAXBContext jc = JAXBContext.newInstance(className);
        Unmarshaller unmarshaller = jc.createUnmarshaller();

        InputStream stream = new ByteArrayInputStream(xml.getBytes("UTF-8"));
        Object obcj = unmarshaller.unmarshal(stream);

        return obcj;
    }//from   w  ww.  ja  v a  2s  . c o  m
}

Related

  1. convertXmlToObj(Class clazz, String xmlStr)
  2. convertXMLToObject(byte[] data, Class clazz)
  3. converyToJavaBean(String xml, Class c)
  4. converyToJavaBean(String xml, Class c)
  5. converyToJavaBean(String xml, Class clazz)
  6. fromFile(Class jaxbClass, String fileName)
  7. fromStream(Class jaxbClass, InputStream is)
  8. fromStringToObject(String xmlString, Class xmlObjClass)
  9. fromXml(@SuppressWarnings("rawtypes") Class clazz, String stringXml)