Google Places JSON to Java Object, for use with GSON Parser for Android.
Made with http://www.jsonschema2pojo.org/
!!NOTICE!!: You should probably be using Retrofit instead for parsing REST API JSON to POJO. Regardless, I'm keeping this project up. :)
Making your own Java classes manually for GSON to parse correctly sucks. I used jsonschema2pojo to generate the classes necessary for parsing with GSON, and created the classes you need for parsing JSON data from Google Places here.
Copy and paste (or clone, or download, or whatever) the .java
classes into your project. Remember to change the package name at the top of the files.
The NearbySearch
class is the top level object, so you will need to call the following to store your results into a NearbySearch
instance:
// Query Google Places API for nearby places.
String query = '{
"html_attributions" : [],
"next_page_token" : "
...
}';
// Parse and store results into Java Object.
NearbySearch nbs = gson.fromJson(query, NearbySearch.class);
You will need to get the query string with an HTTP request. This can be done with an HTTP client library.
- Using GSON in Android
- Autogenerating POJOs from JSON - http://www.jsonschema2pojo.org/
- HTTP Clients libraries: