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 javax.xml.bind.JAXBContext;
import javax.xml.bind.JAXBException;

import javax.xml.bind.Unmarshaller;

import java.io.StringReader;

public class Main {

    public static <T> T unmarshal(JAXBContext context, Class<T> clazz, String source) throws JAXBException {

        if (source == null) {
            return null;
        }

        StringReader reader = new StringReader(source);
        if (context == null) {
            context = JAXBContext.newInstance(clazz);
        }
        Unmarshaller un = context.createUnmarshaller();
        return (T) un.unmarshal(reader);
    }

    public static <T> T unmarshal(Class<T> clazz, String source) throws JAXBException {
        return unmarshal(null, clazz, source);
    }
}