Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;
//License from project: Open Source License 

import javax.xml.bind.JAXBContext;
import javax.xml.bind.JAXBElement;

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

public class Main {
    public static <T> T unmarshall(String file, Class<T> desiredClass, Class context) throws Exception {
        JAXBContext ctx = JAXBContext.newInstance(context);
        Unmarshaller unMarshaller = ctx.createUnmarshaller();
        JAXBElement<T> object = (JAXBElement<T>) unMarshaller.unmarshal(new File(file));
        return object.getValue();
    }
}