2

我正在尝试在 Android 中使用Protostuff 1.7.2 版来序列化和反序列化一些用户定义的类。我正在使用该RuntimeSchema.getSchema()方法在运行时生成 Protostuff 的模式。但是,当我调用此方法时,我遇到了 RuntimeException。

我已经确定这个问题sun.reflect.ReflectionFactory在 Android 中不存在。Protostuff 尝试在此处加载此类,但在 Android 上似乎无法这样做,导致此处的返回值为null,这会触发 RuntimeException。我尝试在 Ubuntu/Windows 上运行相同的代码(见下文),我的代码运行良好,因为安装的 Java 运行时包括sun.reflect.ReflectionFactory.

final DefaultIdStrategy STRATEGY = new DefaultIdStrategy(IdStrategy.DEFAULT_FLAGS
                | IdStrategy.ALLOW_NULL_ARRAY_ELEMENT
                | IdStrategy.MORPH_COLLECTION_INTERFACES
                | IdStrategy.MORPH_MAP_INTERFACES
                | IdStrategy.MORPH_NON_FINAL_POJOS);
schema = RuntimeSchema.getSchema(clazz, STRATEGY);

我尝试使用protostuff-runtime-md,它应该可以在 Android 上运行,但没有运气。

谁能告诉我如何让它在Android上运行?

4

0 回答 0