当我尝试在 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)