Created
November 1, 2012 05:45
-
-
Save dagvadorj/3992076 to your computer and use it in GitHub Desktop.
JSF converter for serializable objects; can be used for h:selectOneMenu etc
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.io.ByteArrayInputStream; | |
import java.io.ByteArrayOutputStream; | |
import java.io.IOException; | |
import java.io.ObjectInputStream; | |
import java.io.ObjectOutputStream; | |
import java.io.Serializable; | |
import biz.source_code.base64Coder.Base64Coder; | |
public class ObjectSerializer { | |
public static Object fromString(String s) throws IOException, | |
ClassNotFoundException { | |
byte[] data = Base64Coder.decode(s); | |
ObjectInputStream ois = new ObjectInputStream(new ByteArrayInputStream( | |
data)); | |
Object o = ois.readObject(); | |
ois.close(); | |
return o; | |
} | |
public static String toString(Serializable o) throws IOException { | |
ByteArrayOutputStream baos = new ByteArrayOutputStream(); | |
ObjectOutputStream oos = new ObjectOutputStream(baos); | |
oos.writeObject(o); | |
oos.close(); | |
return new String(Base64Coder.encode(baos.toByteArray())); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment