java - How can List<Customclass> be filled with LinkedHashMaps, rather then instances of Customclass? -


i'm having trouble understanding why in example below, customclass lists(response.results , results) filled linkedhashmaps. i'd expected after parsing json inputstream, lists full of customclasses, classmembers containing data, straight json. instead, lists come containing linkedhashmaps, though type customclass.

could explain?

gson gson = new gson(); reader reader = new inputstreamreader(inputstream);  placeslist response = gson.fromjson(reader, placeslist.class);  list<place> results = response.results; 

customclasses used:

public class placeslist implements serializable {      @key     public string status;      @key     public string error_message;      @key     public list<place> results;  } 

&

public class place implements serializable {      @key     public string id;      @key     public string name;      @key     public string reference;      @key     public string icon;      @key     public string vicinity;      @key     public geometry geometry;      @key     public string formatted_address;      @key     public string formatted_phone_number;      @override     public string tostring() {         return name + " - " + id + " - " + reference;     }       public static class geometry implements serializable     {         @key         public location location;     }      public static class location implements serializable     {         @key         public double lat;          @key         public double lng;     }  } 

the json format not contain type information, except own primitive types. text-based format, arrays , objects mapped respectively whatever concept of ordered list , ordered key-value pair list exists in each programming language.

therefore linkedhashmap natural representation of json object in java. such, json deserializers output default.

to retrieve custom objects in json implementations have used need either supply a custom deserializer class, or post-process output of standard deserializer. may necessary custom serializer assist inserting some type information in json stream resolve ambiguous cases.


Comments

Popular posts from this blog

user interface - How to replace the Python logo in a Tkinter-based Python GUI app? -

objective c - Greedy NSProgressIndicator Allocation -

how to set an OCR language in Google Drive -