Java MicroStream序列化,类型不可持久化: “class java.lang.Throwable”

huangapple go评论120阅读模式
英文:

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 &quot;main&quot; one.microstream.persistence.exceptions.PersistenceExceptionTypeNotPersistable: Type not persistable: &quot;class java.lang.Throwable&quot;.
	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: &quot;class java.lang.Throwable&quot;.

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&lt;?&gt; foundation = SerializerFoundation.New()
                .registerEntityTypes(ObjectToSerialize.class);
        final Serializer&lt;byte[]&gt; serializer = TypedSerializer.Bytes(foundation);
        byte[] data = serializer.serialize(objectToSerialize);

        ObjectToSerialize restored = serializer.deserialize(data);

    }
}

The result I get is this:

Exception in thread &quot;main&quot; one.microstream.persistence.exceptions.PersistenceExceptionTypeNotPersistable: Type not persistable: &quot;class java.lang.Throwable&quot;.
	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.&lt;init&gt;(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

huangapple
  • 本文由 发表于 2023年7月18日 01:22:37
  • 转载请务必保留本文链接:https://go.coder-hub.com/76706775.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定