mardi 29 novembre 2016

Realm java, how to access RealmObject property by string (reflection)

I wanted to access the property of model by string via reflection like

Object o = ...; // The object you want to inspect
Class<?> c = o.getClass();

Field f = c.getDeclaredField("myColor");
f.setAccessible(true);

String valueOfMyColor = (String) f.get(o);

But i was still getting error that the property doesn't exist. Then i found that RealmModel objects are wrapped with RealmProxy class so that could be the reason.

So question is, how to access RealmModel properties by string? Via reflection or another way.





Aucun commentaire:

Enregistrer un commentaire