java - How to restore JSON stored in database to <MyClass> object -
i've got sqlite database in current android project text columns represent json objects converted own java classes. this:
string myclassinjsonstring = gson.tojson(myjavaclass.class)
gson class allows me use .fromjson(string, objecttype)
method convert json string stored in database original class getters , setters.
my question:
there way save class database original class type use getters , concrete value of object?
i can use this, don't want (long) json strings loaded xml textviews or views. i'd load original class type, use getter , value want show in textview.
string[] = {provider.myclass.first_colum, provider.myclass.second_column }; int[] = {r.id.textid_1, r.id.textid_2}; this.simplecursoradapter = new simplecursoradapter(this, r.layout.list_layout, null, from, to, defaults.no_flags);
should use (own) adapter, not simplecursoradapter? thanks.
i decided change column type text blob , used code list of entity.
public list<entity> getallentities(string tablename, string column) { list<entity> entities = new arraylist<>(); string selectquery = "select " + column + " " + tablename; entitiesdatabaseopenhelper openhelper = new entitiesdatabaseopenhelper(this); sqlitedatabase database = openhelper.getreadabledatabase(); cursor cursor = database.rawquery(selectquery, null); if (cursor.movetofirst()) { { byte[] entityblob = cursor.getblob(cursor.getcolumnindex(column)); string json = new string(entityblob); gson gson = new gson(); entity entity = gson.fromjson(json, new typetoken<entity>() { }.gettype()); entities.add(entity); } while (cursor.movetonext()); } cursor.close(); return entities; }
this not lucky solution. found way store data of each entity in tables every entity parameter saved in single column. can use joins , own adapter display data.
Comments
Post a Comment