英文:
Java MicroStream Serialization, Type not persistable: "class java.lang.Throwable"
问题
当序列化包含类型为Throwable的字段的对象时,我得到以下结果:
one.microstream.persistence.exceptions.PersistenceExceptionTypeNotPersistable: Type not persistable: "class java.lang.Throwable".
使用Serializer或TypedSerializer如下所示:
class ObjectToSerialize {
Throwable throwable;
}
public class Main {
public static void main(String[] args) {
ObjectToSerialize objectToSerialize = new ObjectToSerialize();
final SerializerFoundation<?> foundation = SerializerFoundation.New()
.registerEntityTypes(ObjectToSerialize.class);
final Serializer<byte[]> serializer = TypedSerializer.Bytes(foundation);
byte[] data = serializer.serialize(objectToSerialize);
ObjectToSerialize restored = serializer.deserialize(data);
}
}
结果如下:
Exception in thread "main" one.microstream.persistence.exceptions.PersistenceExceptionTypeNotPersistable: Type not persistable: "class java.lang.Throwable".
at one.microstream.persistence.binary.internal.BinaryHandlerUnpersistable.guaranteeSubTypeInstanceViablity(BinaryHandlerUnpersistable.java:98)
at one.microstream.persistence.types.PersistenceTypeHandlerManager$Default.lambda$recursiveEnsureTypeHandlers$0(PersistenceTypeHandlerManager.java:278)
at one.microstream.persistence.binary.internal.AbstractBinaryHandlerReflective.iterateMemberTypes(AbstractBinaryHandlerReflective.java:591)
at one.microstream.persistence.types.PersistenceTypeHandlerManager$Default.recursiveEnsureTypeHandlers(PersistenceTypeHandlerManager.java:271)
at one.microstream.persistence.types.PersistenceTypeHandlerManager$Default.registerTypeHandler(PersistenceTypeHandlerManager.java:639)
at one.microstream.persistence.types.PersistenceTypeHandlerManager$Default.internalEnsureTypeHandler(PersistenceTypeHandlerManager.java:616)
at one.microstream.persistence.types.PersistenceTypeHandlerManager$Default.ensureTypeHandler(PersistenceTypeHandlerManager.java:384)
at java.base/java.lang.Iterable.forEach(Iterable.java:75)
at one.microstream.persistence.binary.util.SerializerFoundation$Default.createPersistenceManager(SerializerFoundation.java:211)
at one.microstream.persistence.binary.util.TypedSerializer$Default.initialize(TypedSerializer.java:372)
at one.microstream.persistence.binary.util.TypedSerializer$Default.<init>(TypedSerializer.java:262)
at one.microstream.persistence.binary.util.TypedSerializer.New(TypedSerializer.java:145)
at one.microstream.persistence.binary.util.TypedSerializer.Bytes(TypedSerializer.java:117)
at com.testing.Main.main(Main.java:19)
我看过这个,但在我的情况下,我需要进行序列化而不是存储,也许我理解有误?
如何序列化包含Throwable的对象?如果可能的话,请指向说明如何执行此操作的文档或示例。非常感谢!
英文:
When serializing an object containing a field of type Throwable I get
one.microstream.persistence.exceptions.PersistenceExceptionTypeNotPersistable: Type not persistable: "class java.lang.Throwable".
Using the Serializer or TypedSerializer like this:
class ObjectToSerialize {
Throwable throwable;
}
public class Main {
public static void main(String[] args) {
ObjectToSerialize objectToSerialize = new ObjectToSerialize();
final SerializerFoundation<?> foundation = SerializerFoundation.New()
.registerEntityTypes(ObjectToSerialize.class);
final Serializer<byte[]> serializer = TypedSerializer.Bytes(foundation);
byte[] data = serializer.serialize(objectToSerialize);
ObjectToSerialize restored = serializer.deserialize(data);
}
}
The result I get is this:
Exception in thread "main" one.microstream.persistence.exceptions.PersistenceExceptionTypeNotPersistable: Type not persistable: "class java.lang.Throwable".
at one.microstream.persistence.binary.internal.BinaryHandlerUnpersistable.guaranteeSubTypeInstanceViablity(BinaryHandlerUnpersistable.java:98)
at one.microstream.persistence.types.PersistenceTypeHandlerManager$Default.lambda$recursiveEnsureTypeHandlers$0(PersistenceTypeHandlerManager.java:278)
at one.microstream.persistence.binary.internal.AbstractBinaryHandlerReflective.iterateMemberTypes(AbstractBinaryHandlerReflective.java:591)
at one.microstream.persistence.types.PersistenceTypeHandlerManager$Default.recursiveEnsureTypeHandlers(PersistenceTypeHandlerManager.java:271)
at one.microstream.persistence.types.PersistenceTypeHandlerManager$Default.registerTypeHandler(PersistenceTypeHandlerManager.java:639)
at one.microstream.persistence.types.PersistenceTypeHandlerManager$Default.internalEnsureTypeHandler(PersistenceTypeHandlerManager.java:616)
at one.microstream.persistence.types.PersistenceTypeHandlerManager$Default.ensureTypeHandler(PersistenceTypeHandlerManager.java:384)
at java.base/java.lang.Iterable.forEach(Iterable.java:75)
at one.microstream.persistence.binary.util.SerializerFoundation$Default.createPersistenceManager(SerializerFoundation.java:211)
at one.microstream.persistence.binary.util.TypedSerializer$Default.initialize(TypedSerializer.java:372)
at one.microstream.persistence.binary.util.TypedSerializer$Default.<init>(TypedSerializer.java:262)
at one.microstream.persistence.binary.util.TypedSerializer.New(TypedSerializer.java:145)
at one.microstream.persistence.binary.util.TypedSerializer.Bytes(TypedSerializer.java:117)
at com.testing.Main.main(Main.java:19)
I have seen this but in my case I need to do serialization not storing, maybe I'm wrong?
How do I serialize an object containing Throwable? If you can please point me to documentation or an example explaining how to do this.
Many Thanks!
答案1
得分: 0
使用Java序列化和Serializable接口来序列化一个包含Throwable类型字段的对象是可行的。MicroStream 声称可以"序列化任何对象",但MicroStream目前尚不支持Throwable和派生类型的序列化,这是一个重要的信息应该被注意到。
答案在这里:https://github.com/microstream-one/microstream/issues/613
英文:
Serializing an object containing a field of type Throwable using Java serialization with Serializable interface is doable. MicroStream claims to "Serialize any object" but MicroStream doesn't yet support serialization of Throwable and derived types, this is an important information that should be noted.
Answered Here: https://github.com/microstream-one/microstream/issues/613
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论