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.Unmarshaller;

public class Main {
    public static Object xml2BeanUtf8(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("UTF-8"));
            Unmarshaller um = context.createUnmarshaller();
            obj = (Object) um.unmarshal(iStream);
            return obj;
        } catch (Exception e) {
            e.printStackTrace();
        }
        return obj;
    }
}