How to Serialize Objects with JBoss Serialization

1) Create the JBossSerializationSample.java file:

import org.jboss.serial.io.JBossObjectInputStream;
import org.jboss.serial.io.JBossObjectOutputStream;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;

import static java.lang.System.out;

public final class JBossSerializationSample {

  public static void main(final String[] args) throws Exception {
    final File file = new File("Sample.ser");

    final ObjectOutputStream oos = new JBossObjectOutputStream(new FileOutputStream(file));

    oos.writeObject("Hello World!");

    oos.close();

    final ObjectInputStream ois = new JBossObjectInputStream(new FileInputStream(file));

    out.println(ois.readObject());

    ois.close();
  }

}

2) Compile the JBossSerializationSample.java file.

3) Launch the JBossSerializationSample class.

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 )

Twitter picture

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

Facebook photo

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

Google+ photo

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

Connecting to %s