首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Android上的序列化字节码不能在PC上反序列化

Android上的序列化字节码不能在PC上反序列化
EN

Stack Overflow用户
提问于 2013-08-09 13:11:05
回答 1查看 1.1K关注 0票数 0

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

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

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

代码语言:javascript
复制
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上是不同的序列化方式。我对原型没有很深的了解,但奇怪的是,当使用独立于操作系统的JAVA时,它依赖于操作系统。

代码语言:javascript
复制
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)
EN

回答 1

Stack Overflow用户

发布于 2013-08-20 08:43:52

是否使用相同的Protostuff选项protostuff.runtime.collection_schema_on_repeated_fields序列化和反序列化?

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/18147448

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档