XML Serialization in Java – when you have a CLOB data type in DB

import java.beans.XMLDecoder;
import java.beans.XMLEncoder;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;

public class MyBean
  private String name;

  public void setName( String name )
    this.name = name;

  public String getName()
    return name;

  public static void main( String[] args )
    MyBean b=new MyBean();
    b.setName( "Hello World" );
    ByteArrayOutputStream out=new ByteArrayOutputStream( 200 );
    XMLEncoder enc=new XMLEncoder( out );
    enc.writeObject( b );
    ByteArrayInputStream in=new ByteArrayInputStream( out.toString().getBytes() );
    XMLDecoder dec=new XMLDecoder( in );
    MyBean b2=(MyBean)dec.readObject();

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: