xml Decode Java Bean - Java Reflection

Java examples for Reflection:Java Bean

Description

xml Decode Java Bean

Demo Code


//package com.java2s;
import java.beans.XMLDecoder;

import java.io.*;

public class Main {

    public static Object xmlDecode(byte[] bytes) {

        Object obj;//from   w  w w . j av  a2  s .com
        InputStream is = new ByteArrayInputStream(bytes);
        try (XMLDecoder d = new XMLDecoder(is)) {
            obj = d.readObject();
        }
        return obj;
    }

    public static <T> T xmlDecode(byte[] bytes, Class<T> clazz) {
        return (T) xmlDecode(bytes);
    }
}

Related Tutorials