Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;
import java.io.ByteArrayInputStream;

import java.io.InputStream;

import javax.xml.bind.JAXBContext;
import javax.xml.bind.JAXBException;

import javax.xml.bind.Unmarshaller;

public class Main {
    public static Object xml2Bean(Class<?> zClass, String xml) {
        Object obj = null;
        JAXBContext context = null;
        if (null == xml || "".equals(xml) || "null".equalsIgnoreCase(xml) || xml.length() < 1)
            return obj;
        try {
            context = JAXBContext.newInstance(zClass);
            InputStream iStream = new ByteArrayInputStream(xml.getBytes());
            Unmarshaller um = context.createUnmarshaller();
            obj = (Object) um.unmarshal(iStream);
            return obj;
        } catch (JAXBException e) {
            e.printStackTrace();
        }
        return obj;
    }
}