Thursday, 15 July 2010

android - Making GSON & Realm play nice -



android - Making GSON & Realm play nice -

i'm trying utilize realm + gson. if work well, match made in heaven.

however, when extend model objects "extends realmobject" this:

10-08 17:00:19.578 12492-12492/appwise.be.gsontestproject e/androidruntime﹕ fatal exception: main process: appwise.be.gsontestproject, pid: 12492 java.lang.stackoverflowerror @ com.google.gson.internal.$gson$types.resolve($gson$types.java:372) @ com.google.gson.internal.$gson$types.resolve($gson$types.java:376) @ com.google.gson.internal.$gson$types.resolve($gson$types.java:381) @ com.google.gson.internal.$gson$types.resolve($gson$types.java:376) @ com.google.gson.internal.$gson$types.resolve($gson$types.java:381) @ com.google.gson.internal.$gson$types.resolve($gson$types.java:376) @ com.google.gson.internal.$gson$types.resolve($gson$types.java:381) @ com.google.gson.internal.$gson$types.resolve($gson$types.java:376) @ com.google.gson.internal.$gson$types.resolve($gson$types.java:381) @ com.google.gson.internal.$gson$types.resolve($gson$types.java:376) @ com.google.gson.internal.$gson$types.resolve($gson$types.java:381) @ com.google.gson.internal.$gson$types.resolve($gson$types.java:376) @ com.google.gson.internal.$gson$types.resolve($gson$types.java:381) @ com.google.gson.internal.$gson$types.resolve($gson$types.java:376) @ com.google.gson.internal.$gson$types.resolve($gson$types.java:381) @ com.google.gson.internal.$gson$types.resolve($gson$types.java:376) @ com.google.gson.internal.$gson$types.resolve($gson$types.java:381) @ com.google.gson.internal.$gson$types.resolve($gson$types.java:376) @ com.google.gson.internal.$gson$types.resolve($gson$types.java:381) @ com.google.gson.internal.$gson$types.resolve($gson$types.java:376) @ com.google.gson.internal.$gson$types.resolve($gson$types.java:381) @ com.google.gson.internal.$gson$types.resolve($gson$types.java:376) @ com.google.gson.internal.$gson$types.resolve($gson$types.java:381) @ com.google.gson.internal.$gson$types.resolve($gson$types.java:376) @ com.google.gson.internal.$gson$types.resolve($gson$types.java:381) @ com.google.gson.internal.$gson$types.resolve($gson$types.java:376) @ com.google.gson.internal.$gson$types.resolve($gson$types.java:381) @ com.google.gson.internal.$gson$types.resolve($gson$types.java:376) @ com.google.gson.internal.$gson$types.resolve($gson$types.java:381) @ com.google.gson.internal.$gson$types.resolve($gson$types.java:376) @ com.google.gson.internal.$gson$types.resolve($gson$types.java:381) @ com.google.gson.internal.$gson$types.resolve($gson$types.java:376) @ com.google.gson.internal.$gson$types.resolve($gson$types.java:356) @ com.google.gson.internal.bind.reflectivetypeadapterfactory.getboundfields(reflectivetypeadapterfactory.java:128) @ com.google.gson.internal.bind.reflectivetypeadapterfactory.create(reflectivetypeadapterfactory.java:75) @ com.google.gson.gson.getadapter(gson.java:358) @ com.google.gson.internal.bind.reflectivetypeadapterfactory.getfieldadapter(reflectivetypeadapterfactory.java:109) @ com.google.gson.internal.bind.reflectivetypeadapterfactory.access$100(reflectivetypeadapterfactory.java:46) @ com.google.gson.internal.bind.reflectivetypeadapterfactory$1.<init>(reflectivetypeadapterfactory.java:84) @ com.google.gson.internal.bind.reflectivetypeadapterfactory.createboundfield(reflectivetypeadapterfactory.java:83) @ com.google.gson.internal.bind.reflectivetypeadapterfactory.getboundfields(reflectivetypeadapterfactory.java:129) @ com.google.gson.internal.bind.reflectivetypeadapterfactory.create(reflectivetypeadapterfactory.java:75) @ com.google.gson.gson.getadapter(gson.java:358) @ com.google.gson.internal.bind.reflectivetypeadapterfactory.getfieldadapter(reflectivetypeadapterfactory.java:109) @ com.google.gson.internal.bind.reflectivetypeadapterfactory.access$100(reflectivetypeadapterfactory.java:46) @ com.google.gson.internal.bind.reflectivetypeadapterfactory$1.<init>(reflectivetypeadapterfactory.java:84) @ com.google.gson.internal.bind.reflectivetypeadapterfactory.createboundfield(reflectivetypeadapterfactory.java:83) @ com.google.gson.internal.bind.reflectivetypeadapterfactory.getboundfields(reflectivetypeadapterfactory.java:129) @ com.google.gson.internal.bin

any prepare available? :-)

u can this:

gson gson = new gsonbuilder() .setexclusionstrategies(new exclusionstrategy() { @override public boolean shouldskipfield(fieldattributes f) { homecoming f.getdeclaringclass().equals(realmobject.class); } @override public boolean shouldskipclass(class<?> clazz) { homecoming false; } }) .create();

string json = "{ name : 'john', email : 'john@corporation.com' }"; user user = gson.fromjson(json, user.class);

http://realm.io/docs/java/0.77.0/#gson

android gson realm

No comments:

Post a Comment