在Android上序列化的Prototstuff字节码无法在PC上反序列化



当我试图在PC上反序列化我的序列化模型时,我在底部看到了一个奇怪的错误。反序列化在Android上有效,就像我在PC上序列化同一个模型并在PC上反序列化一样。因此,这似乎是一个互操作性问题。

我能做些什么来确保它以相同的方式序列化?

我必须序列化的模型有以下POJOS和集合:

ExplicitIdStrategy.Registry reg = new ExplicitIdStrategy.Registry();
    reg.registerPojo(EntityData.class, 1);
    reg.registerPojo(ProbabilityModel.class, 2);
    reg.registerPojo(ProbabilityModelEntryList.class, 3);
    reg.registerCollection(CollectionSchema.MessageFactories.valueOf("ArrayList"), 4);
    reg.registerMap(MapSchema.MessageFactories.valueOf("HashMap"), 5);
    reg.registerEnum(ProbabilityModel.OtherCounted.class, 6);
    reg.registerCollection(CollectionSchema.MessageFactories.valueOf("HashSet"), 7);

似乎地图在Android和Windows PC上的序列化方式不同。我对protostuff没有深入的了解,但很奇怪的是,当使用独立于操作系统的JAVA时,它依赖于操作系统。。。

com.dyuproject.protostuff.ProtostuffException: The map was incorrectly serialized.
    at com.dyuproject.protostuff.MapSchema.mergeFrom(MapSchema.java:316)
    at com.dyuproject.protostuff.MapSchema.mergeFrom(MapSchema.java:31)
    at com.dyuproject.protostuff.GraphCodedInput.mergeFrom(GraphCodedInput.java:153)
    at com.dyuproject.protostuff.CodedInput.mergeObjectEncodedAsGroup(CodedInput.java:271)
    at com.dyuproject.protostuff.CodedInput.mergeObject(CodedInput.java:239)
    at com.dyuproject.protostuff.GraphCodedInput.mergeObject(GraphCodedInput.java:108)
    at com.dyuproject.protostuff.runtime.RuntimeMapFieldFactory$5.mergeFrom(RuntimeMapFieldFactory.java:463)
    at com.dyuproject.protostuff.runtime.MappedSchema.mergeFrom(MappedSchema.java:188)
    at com.dyuproject.protostuff.GraphIOUtil.mergeFrom(GraphIOUtil.java:76)
    at com.android.diabetesmodel.ModelEntity.deserialize(ModelEntity.java:185)
    at com.android.diabetesmodel.test.VersionManagerEntityTest.from1to2Upgrade(VersionManagerEntityTest.java:47)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
    at java.lang.reflect.Method.invoke(Unknown Source)
    at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:45)
    at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:15)
    at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:42)
    at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:20)
    at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:263)
    at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:68)
    at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:47)
    at org.junit.runners.ParentRunner$3.run(ParentRunner.java:231)
    at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:60)
    at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:229)
    at org.junit.runners.ParentRunner.access$000(ParentRunner.java:50)
    at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:222)
    at org.junit.runners.ParentRunner.run(ParentRunner.java:300)
    at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:50)
    at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:467)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197)

您是否使用相同的Prototstuff JVM选项进行序列化和反序列化Protostuff.runtime.collection_schema_on_repeated_fields

最新更新