@Test public void testVersioning() { Versioning v = new Versioning(); FSTConfiguration conf = getTestConfiguration(); conf.registerClass(Versioning.class); byte[] bytes = conf.asByteArray(v); Versioning res = (Versioning) conf.asObject(bytes); assertTrue(DeepEquals.deepEquals(v, res)); FSTConfiguration old = getTestConfiguration(); old.registerClass(VersioningOld.class); VersioningOld vold = new VersioningOld(); vold.originalMap.put("uz", "aspdokasd"); bytes = old.asByteArray(vold); Versioning newReadFromOld = (Versioning) conf.asObject(bytes); assertTrue(newReadFromOld.originalOne.equals("OOPASDKAPSODKPASODKBla")); FSTConfiguration oldv4 = getTestConfiguration(); oldv4.registerClass(VersioningV4.class); VersioningV4 oldv4Inst = new VersioningV4(); oldv4Inst.veryNew.put("uz", "aspdokasd"); bytes = oldv4.asByteArray(oldv4Inst); Versioning newReadFromV4 = (Versioning) conf.asObject(bytes); assertTrue(newReadFromV4.veryNew.get("uz").equals("aspdokasd")); }
// fails if objenesis is used @Test public void testNotSerializable() { FSTConfiguration conf = getTestConfiguration().setForceSerializable(true); NotSer ser = new NotSer(11, 12); assertTrue(DeepEquals.deepEquals(ser, conf.asObject(conf.asByteArray(ser)))); NotSerSub sersub = new NotSerSub(11, 12); final Object deser = conf.asObject(conf.asByteArray(sersub)); assertTrue(DeepEquals.deepEquals(sersub, deser)); assertTrue(((NotSerSub) deser).pubConsCalled); }
public void writeSession(HttpServletRequest request, HttpServletResponse response) throws NoSuchPaddingException, NoSuchAlgorithmException, InvalidKeyException, BadPaddingException, IllegalBlockSizeException { SparkHttpRequestWrapper sparkRequest = (SparkHttpRequestWrapper) request; if (!sparkRequest.sessionAccessed()) return; CookieSession session = (CookieSession) request.getSession(); // serialize session byte[] sessionBytes = conf.asByteArray(session); // encrypt content final Cipher symmetricalCipher = Cipher.getInstance(symmetricEncryptionAlgorithm); symmetricalCipher.init(Cipher.ENCRYPT_MODE, this.symmetricEncryptionKey); byte[] encryptedBytes = symmetricalCipher.doFinal(sessionBytes); // sign content byte[] signature = sign(encryptedBytes); byte[] cookieContent = new byte[encryptedBytes.length + signature.length]; System.arraycopy(encryptedBytes, 0, cookieContent, 0, encryptedBytes.length); System.arraycopy( signature, 0, cookieContent, cookieContent.length - signature.length, signature.length); String base64CookieContent = Base64.getEncoder().encodeToString(cookieContent); addCookie(base64CookieContent, response); }
@Test public void testExternalizableOverride() { FSTConfiguration conf = getTestConfiguration(); Object original[] = { "A", new SubClassedAList().$("A").$("B").$("C"), "Ensure stream not corrupted" }; Object deser = conf.asObject(conf.asByteArray(original)); assertTrue(DeepEquals.deepEquals(original, deser)); }
@Test public void testNestedSerializers() { FSTConfiguration conf = getTestConfiguration(); conf.registerSerializer(T.class, new TSer(), true); conf.registerSerializer(T1.class, new T1Ser(), true); Object p = new T(1); byte[] bytes = conf.asByteArray(p); Object deser = conf.asObject(bytes); assertTrue(DeepEquals.deepEquals(p, deser)); }