如何序列化函数返回的 rx.Single 的对象?

How to Serialize an object of rx.Single returned by a function?

我正在使用 Spring 框架并尝试缓存使用 @Cacheable 注释的方法返回的结果。 方法 returns rx.Single class 的一个对象。尝试缓存结果时出现以下错误,

Caused by: org.springframework.core.serializer.support.SerializationFailedException: Failed to serialize object using DefaultSerializer; nested exception is java.lang.IllegalArgumentException: DefaultSerializer requires a Serializable payload but received an object of type [rx.Single]

如何继续缓存结果?要么 如何序列化 rx.Single class 的对象?

答案是:你不能

您可以创建自己的 class,它将保存所有必需的信息并使其成为 Serializable