java - Is there efficient way to convert org.json.JSONObject to POJO model using GSON? -


is there efficient way convert org.json.jsonobject pojo model using gson ? (at moment u thought

gson g=new gson(); g.fromjson(json.tostring(), personmodel.class); 

json jsonobject). using volley , in response instance of jsonobject , can parse on http://www.kpbird.com/2013/05/volley-easy-fast-networking-for-android.html have complex structure in models nested lists , avoid manual extracting of data json.

first, sorry bumping old question.

i asking myself same question , found example in android volley section called implementing custom requests in android developer site.

@override protected response<t> parsenetworkresponse(         networkresponse response) {     try {         string json = new string(response.data,         httpheaderparser.parsecharset(response.headers));     return response.success(gson.fromjson(json, clazz),     httpheaderparser.parsecacheheaders(response));     }     // handle errors ... } 

i use stringrequest , use gson on response callback, should faster getting jsonobject , converting string prior calling gson. see in jsonobject javadoc there's no way create instance byte[], http response in bytes converted string, jsonobject, , convert string again. using stringrequest can skip last 2 steps.


Comments

Popular posts from this blog

html - How to style widget with post count different than without post count -

How to remove text and logo OR add Overflow on Android ActionBar using AppCompat on API 8? -

javascript - storing input from prompt in array and displaying the array -