Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;
import java.io.StringReader;

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

import javax.xml.bind.Unmarshaller;
import org.xml.sax.InputSource;

public class Main {
    public static <T> Object generateXML2Object(String str, Class cls) throws JAXBException {

        InputSource is;
        Object obj = null;

        is = new InputSource(new StringReader(str));
        JAXBContext jaxbContext = JAXBContext.newInstance(cls);
        Unmarshaller jaxbUnmarshaller = jaxbContext.createUnmarshaller();
        obj = cls.cast(jaxbUnmarshaller.unmarshal(is));

        return obj;
    }
}