如何序列化不可序列化的对象?

时间:2017-03-09 02:32:57

标签: java android serialization

我正在使用AWS Cognito,并且遇到了维护必要的“延续”对象以在潜在应用关闭之间重置密码的问题。我想使用序列化和反序列化将continuation对象存储到sharedPrefs或SQLite。 continuation对象是不可序列化的。是否仍然可以序列化它?这是我的尝试

                String serializedObject = "";
                // serialize the object
                try {
                    ByteArrayOutputStream bo = new ByteArrayOutputStream();
                    ObjectOutputStream so = new ObjectOutputStream(bo);
                    so.writeObject(continuation);
                    so.flush();
                    serializedObject = bo.toString();
                } catch (Exception e) {
                    System.out.println(e);
                }
                sharedPref.setPref("Test", serializedObject);


                // deserialize the object
                try {
                    byte b[] = json.getBytes();
                    ByteArrayInputStream bi = new ByteArrayInputStream(b);
                    ObjectInputStream si = new ObjectInputStream(bi);
                    ForgotPasswordContinuation obj = (ForgotPasswordContinuation) si.readObject();
                } catch (Exception e) {
                    System.out.println(e);
                }

我收到以下错误:

  

java.io.NotSerializableException:   com.amazonaws.mobileconnectors.cognitoidentityprovider.continuations.ForgotPasswordContinuation

这甚至可以吗?提前谢谢。

0 个答案:

没有答案