• Labhansh Gupta
  • NEWBIE
  • 0 Points
  • Member since 2019

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 0
    Questions
  • 1
    Replies
Hello everyone,

I'm working with the geonames web services, the datetime field is being returned as null when I'm deserializing as follows--

 ResCls eqList = (ResCls)JSON.deserialize(responseBody,ResCls.class);

Here's the wrapper class-
public class ResCls{
        List <Earthquakes> earthQuakes;
        
        public ResCls(List <Earthquakes> eqlist1){
            earthQuakes= eqlist1;
        }
    }
    
    public class Earthquakes{
        public Datetime eqDatetime;
        public Double depth;
        public Double lng;
        public String src;
        public String eqId;
        public Double lat;
        public Double magnitude;
        
        public Earthquakes(Datetime eqd, Double dep, Double lng1, string src1, string eqid2, Double mag, Double lat1){
            eqDatetime = eqd;
            depth = dep;
            lng = lng1;
            src = src1;
            eqId=eqid2;
            magnitude = mag;
            lat = lat1;
        
        }
           
    }

Here's the sample JSON that is being deserialized-
{"earthquakes":[{"datetime":"2011-03-11 04:46:23","depth":24.4,"lng":142.369,"src":"us","eqid":"c0001xgp","magnitude":8.8,"lat":38.322},{"datetime":"2012-04-11 06:38:37","depth":22.9,"lng":93.0632,"src":"us","eqid":"c000905e","magnitude":8.6,"lat":2.311},{"datetime":"2007-09-12 09:10:26","depth":30,"lng":101.3815,"src":"us","eqid":"2007hear","magnitude":8.4,"lat":-4.5172},{"datetime":"2012-04-11 08:43:09","depth":16.4,"lng":92.4522,"src":"us","eqid":"c00090da","magnitude":8.2,"lat":0.7731},{"datetime":"2007-04-01 18:39:56","depth":10,"lng":156.9567,"src":"us","eqid":"2007aqbk","magnitude":8,"lat":-8.4528},{"datetime":"2015-04-25 06:13:40","depth":15,"lng":84.6493,"src":"us","eqid":"us20002926","magnitude":7.9,"lat":28.1306},{"datetime":"2016-12-17 11:00:30","depth":103.19,"lng":153.4495,"src":"us","eqid":"us200081v8","magnitude":7.9,"lat":-4.5091},{"datetime":"2007-09-12 21:49:01","depth":10,"lng":100.9638,"src":"us","eqid":"2007hec6","magnitude":7.8,"lat":-2.5265},{"datetime":"2016-03-02 12:55:00","depth":24,"lng":94.275,"src":"us","eqid":"us10004u1y","magnitude":7.8,"lat":-4.9082},{"datetime":"2015-05-30 11:36:00","depth":677.56,"lng":140.4932,"src":"us","eqid":"us20002ki3","magnitude":7.8,"lat":27.8312}]}

I have tried using 'string', that is also returning datetime as null, all other fields are being deserialezed just fine. Not sure what could be the issue.

Thnak you.