java - Gson Parser unable to create objects from array -


i attempting write gson parser create pojo's jms messages. messages delivered in text format in following style:

{   "priceupdate":[     {        "symbol":"eur/usd",      "entrytype":"0",      "price":"1.09286"   },   {        "symbol":"eur/usd",      "entrytype":"1",      "price":"1.0929"   }  ] } 

i trying create pojo objects each item in array code fails when attempt parse:

public void consumemessage(string text) {     try {         priceupdatetypedto updates = gson.fromjson(text,priceupdatetypedto.class);         (priceupdateitemdto u : updates.items) {             if (u.getentrytype() == "0") {                 connectedmarket.setbidprice(double.parsedouble(u.getprice()));             } else {                 connectedmarket.setofferprice(double.parsedouble(u.getprice()));             }         }     } catch (exception e) {         e.printstacktrace();     } } 

i nullpointer when running on tomcat server

java.lang.nullpointerexception @ com.markets.ticker.pricestreamclient.consumemessage(pricestreamclient.java:25) 

here pojo classes:

public class priceupdatetypedto {       private arraylist<priceupdateitemdto> items;     //getter & setter }   public class priceupdateitemdto {      private string symbol;      private string entrytype;      private string price;     //getters & setters } 

the name of arraylist in priceupdatetypedto needs have same name array in json:

change

 private arraylist<priceupdateitemdto> items; 

to

 private arraylist<priceupdateitemdto> priceupdate; 

or vice-versa (change name of array in json "items")


Comments

Popular posts from this blog

toolbar - How to add link to user registration inside toobar in admin joomla 3 custom component -

linux - disk space limitation when creating war file -

How to provide Authorization & Authentication using Asp.net, C#? -