Java XML JAXB String to Object converyToJavaBean(String xml, Class c)

Here you can find the source of converyToJavaBean(String xml, Class c)

Description

convery To Java Bean

License

Apache License

Declaration

@SuppressWarnings("unchecked")
public static <T> T converyToJavaBean(String xml, Class<T> c) 

Method Source Code


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

import javax.xml.bind.JAXBContext;

import javax.xml.bind.Unmarshaller;
import java.io.StringReader;

public class Main {

    @SuppressWarnings("unchecked")
    public static <T> T converyToJavaBean(String xml, Class<T> c) {
        T t = null;//from w  ww .  j  a v a  2  s  .  c o m
        try {
            JAXBContext context = JAXBContext.newInstance(c);
            Unmarshaller unmarshaller = context.createUnmarshaller();
            t = (T) unmarshaller.unmarshal(new StringReader(xml));
        } catch (Exception e) {
            e.printStackTrace();
        }

        return t;
    }
}

Related

  1. convertToObject(Class clazz, InputStream inputStream)
  2. convertToXmlFile(File file, Object source, Class... type)
  3. convertXmlFileToObject(Class clazz, String xmlPath)
  4. convertXmlToObj(Class clazz, String xmlStr)
  5. convertXMLToObject(byte[] data, Class clazz)
  6. converyToJavaBean(String xml, Class c)
  7. converyToJavaBean(String xml, Class clazz)
  8. createObject(String xml, Object type)
  9. fromFile(Class jaxbClass, String fileName)