Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//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;
        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;
    }
}