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;

public class Main {
    /**
     * 
     * @param xmlData
     * @return
     * @return
     * @return
     * @throws JAXBException
     */
    @SuppressWarnings("unchecked")
    public static <T> T xmlStringToPojo(String xmlData, Class<T> targetClass) throws JAXBException {

        JAXBContext context = JAXBContext.newInstance(targetClass);
        StringReader reader = new StringReader(xmlData);
        Unmarshaller unmarshaller = context.createUnmarshaller();
        return (T) unmarshaller.unmarshal(reader);
    }
}