Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public static String serializeObject(Object obj) {
- String out = null;
- if (obj != null) {
- try {
- ByteArrayOutputStream baos = new ByteArrayOutputStream();
- ObjectOutputStream oos = new ObjectOutputStream(baos);
- oos.writeObject(obj);
- oos.close();
- out = new String(baos.toByteArray(), "UTF8");
- } catch (IOException e) {
- return null;
- }
- }
- return out;
- }
- public static Object deserializeObject(String str) {
- Object out = null;
- if (str != null) {
- try {
- byte[] bytes = str.getBytes();
- ByteArrayInputStream bios = new ByteArrayInputStream(bytes);
- ObjectInputStream ois = new ObjectInputStream(bios);
- out = ois.readObject();
- ois.close();
- } catch (IOException e) {
- return null;
- }catch (ClassNotFoundException e) {
- return null;
- }
- }
- return out;
- }
Add Comment
Please, Sign In to add comment