xml Encode Java Bean - Java Reflection

Java examples for Reflection:Java Bean

Description

xml Encode Java Bean

Demo Code


//package com.java2s;

import java.beans.XMLEncoder;
import java.io.*;

public class Main {

    public static byte[] xmlEncode(Object bean) {

        ByteArrayOutputStream os = new ByteArrayOutputStream(16384);
        try (XMLEncoder e = new XMLEncoder(os)) {
            e.writeObject(bean);// ww  w.  j  a  va  2 s  .  co m
        }
        return os.toByteArray();
    }
}

Related Tutorials