java - Jackson Json to POJO mapping -


getting started jackson first time, having issues mapping json data java classes. json structure follow:

{   "status": "ok",   "all_tags": [     {       "id": 14,       "term_name": "term 1",       "category_details": [         {           "category_id": 21,           "category_name": "category name",           "category_count": 1,           "category_image": "...202x300.jpg"         },         {           "category_id": 19,           "category_name": "category sample",           "category_count": 3,           "category_image": "...202x300.jpg"         }       ]     },     {       "id": 17,       "term_name": "term 2",       "category_details": [         {           "category_id": 20,           "category_name": "category sample again",           "category_count": 1,           "category_image": "....200x300.jpg"         }       ]     },     .......   ] } 

i used jsonschema2pojo website generate categorydetail.java , alltag.java, response.java pojo classes.

because accessing json online used volley make requests:

        mrequestqueue = jacksonnetwork.newrequestqueue(getapplicationcontext());         mrequestqueue.add(new jacksonrequest<alltag>(request.method.get,         "http://example.com/file.json",         new jacksonrequestlistener<alltag>() {             @override             public void onresponse(alltag response, int statuscode, volleyerror error) {                 if (response != null) {                     // not sure how parse json                      // , map data pojo                  } else {                     log.e(tag, "an error occurred while parsing data! stack trace follows:");                     error.printstacktrace();                 }             }              @override             public javatype getreturntype() {                 return simpletype.construct(alltag.class);             }         }) );  

i read documentation have no idea how map json data classes can loop , retreive data later. appreciate if jackson knowledge send me right direction.

you need jackson read snakecase , 1 more class reponse

public class response {     string status;     list<alltags> alltags;     //setter getter     // constructor  } 

update request

        mrequestqueue = jacksonnetwork.newrequestqueue(getapplicationcontext());     mrequestqueue.add(new jacksonrequest<response>(request.method.get,     "http://example.com/file.json",     new jacksonrequestlistener<response>() {         @override         public void onresponse(response response, int statuscode, volleyerror error) {             if (response != null) {                 // response.getalltags() loop here                 // not sure how parse json                  // , map data pojo              } else {                 log.e(tag, "an error occurred while parsing data! stack trace follows:");                 error.printstacktrace();             }         }          @override         public javatype getreturntype() {             return simpletype.construct(response.class);         }     })  );  

Comments

Popular posts from this blog

java - SSE Emitter : Manage timeouts and complete() -

jquery - uncaught exception: DataTables Editor - remote hosting of code not allowed -

java - How to resolve error - package com.squareup.okhttp3 doesn't exist? -