Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;
import javax.xml.bind.JAXBContext;
import javax.xml.bind.JAXBException;

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

public class Main {

    @SuppressWarnings("unchecked")
    public static Object convertXmlPathToObject(String xmlPath, Class clazz) {
        Object object = null;
        try {
            JAXBContext context = JAXBContext.newInstance(clazz);
            Unmarshaller unmarshaller = context.createUnmarshaller();
            FileReader xmlReader = null;
            try {
                xmlReader = new FileReader(xmlPath);
            } catch (FileNotFoundException e) {
                e.printStackTrace();
            }
            object = unmarshaller.unmarshal(xmlReader);
        } catch (JAXBException e) {
            e.printStackTrace();
        }
        return object;
    }
}