Util { public static String serialize(Serializable s) { byte[] data; ObjectOutputStream objOut = null; try { ByteArrayOutputStream byteOut = new ByteArrayOutputStream(); objOut = new ObjectOutputStream(byteOut); objOut.writeObject(s); objOut.flush(); data = byteOut.toByteArray(); } catch (IOException e) { throw new RuntimeException(e); } finally { IOUtils.closeQuietly(objOut); } return Base64.encodeBase64String(data).replaceAll("[\\r\\n]", StringUtils.EMPTY); } private  Util(); static String toRealPagePath(String pagePath); static String toUrlPagePath(String pagePath); static String simplifyForUrl(String text); static String join(Object o, String delimiter); static void deleteQuietly(File f); static RuntimeException toRuntimeException(Throwable t); static File toFile(File baseDir, String path); static void closeQuietly(Closeable c); static Map<String, String> parseParameters(String params); static String serialize(Serializable s); static T deserialize(String s, Class<T> clazz);  }
@Test public void serialize() { String serialized = Util.serialize(Long.valueOf(123)); assertEquals("rO0ABXNyAA5qYXZhLmxhbmcuTG9uZzuL5JDMjyPfAgABSgAFdmFsdWV4cgAQamF2YS5sYW5nLk51bWJlcoaslR0LlOCLAgAAeHAAAAAAAAAAew==", serialized); }