java - RoboSpice persist JSON array with OrmLite -
i'm using robospice spring android , persist json array of objects ormlite. gson used json marshalling. default caching works expected. ormlite doesn't seem array of objects.
this simplified version of json:
[{"id": 1, "title": "test 1"},{"id": 2, "title": "test 3"},{"id": 3, "title": "test 3"}]
i persist in following object:
@databasetable public class foo { @databasefield(id = true) private int id; @databasefield private string title; // getters , setters ... }
based on robospice ormlite example i've created following gsonspringandroidspiceservice class add ormlite cachemanager. problem starts.
public class customgsonspringandroidspiceservice extends gsonspringandroidspiceservice { @override public cachemanager createcachemanager(application application) { // add persisted classes class collection list<class<?>> classcollection = new arraylist<class<?>>(); classcollection.add(foo.class); // init cachemanager cachemanager = new cachemanager(); cachemanager.addpersister(new indatabaseobjectpersisterfactory( application, new robospicedatabasehelper( application, "database.db", 1), classcollection)); return cachemanager; } }
this results in following error:
requestprocessor.java:174(22356): java.lang.runtimeexception: class [lcom.example.model.foo; not handled registered factorylist
when change classcollection.add(foo.class);
classcollection.add(foo[].class);
following error:
requestprocessor.java:174(22601): 14:42:23.112 pool-5-thread-1 unexpected error occured when processsing request cachedspicerequest [requestcachekey=foo, cacheduration=-1, spicerequest=com.example.app.foorequest@4055df40] requestprocessor.java:174(22601): java.lang.illegalargumentexception: no fields have databasefield annotation in class [lcom.example.app.model.foo;
anyone idea how handle json array ormlite cachemanager ?
i've found work around problem. added result object holds array of objects. off course possible if able manipulate json. still not happy because have introduce useless class model.
so json looks like:
{ "id": 1, "result":[{"id": 1, "title": "test 1"},{"id": 2, "title": "test 3"},{"id": 3, "title": "test 3"}] }
and added following class hold json result:
@databasetable public class fooresult { @databasefield(id = true) private int id; @foreigncollectionfield(eager = false) private collection<foo> result; // getters , setters ... }
also added foreign relation the foo class:
@databasetable public class foo { @databasefield(id = true) private int id; @databasefield private string title; @databasefield(foreign = true) private fooresult result; // getters , setters ... }
Comments
Post a Comment