TransWikia.com

Using Protostuff on Android causes RuntimeException because of missing sun.reflect.ReflectionFactory

Stack Overflow Asked by Daan on December 15, 2020

I’m trying to use Protostuff version 1.7.2 in Android to serialize and deserialize some user-defined classes. I’m generating the Protostuff’s schema’s during runtime with the RuntimeSchema.getSchema() method. However, I’m running into a RuntimeException when I call this method.

I’ve pinned down the issue to sun.reflect.ReflectionFactory not existing in Android. Protostuff tries to load this class here, but appearently can’t do so on Android, causing the return value here to be null, which triggers the RuntimeException. I tried to run the same code (see below) on Ubuntu/Windows, there my code runs fine because the installed Java runtime includes 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);

I tried to use protostuff-runtime-md, which should work on Android, but no luck.

Can anyone tell me how to get this to work on Android?

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP