Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I'm a fan of Jackson and I can say you made me curious. I used the URL you exposed and make it work like below. <strong>Used the current API version: 2.2.3</strong></p> <p>Model classes:</p> <p><strong>GeocoderResult</strong></p> <pre><code>public class GeocoderResult { @JsonProperty("results") private ArrayList&lt;GeocoderGoog&gt; geocoder; @JsonProperty("status") private String status; public ArrayList&lt;GeocoderGoog&gt; getGeocoder() { return geocoder; } public String getStatus() { return status; } } </code></pre> <p><strong>GeocoderGoog</strong></p> <pre><code>public class GeocoderGoog { @JsonProperty("address_components") private ArrayList&lt;AddressComponent&gt; addressComponents; @JsonProperty("formatted_address") private String formattedAddress; private ArrayList&lt;String&gt; types; private Geometry geometry; public ArrayList&lt;AddressComponent&gt; getAddressComponents() { return addressComponents; } public String getFormattedAddress() { return formattedAddress; } public ArrayList&lt;String&gt; getTypes() { return types; } public Geometry getGeometry() { return geometry; } } </code></pre> <p><strong>AddressComponent</strong></p> <pre><code>public class AddressComponent { @JsonProperty("long_name") private String longName; @JsonProperty("short_name") private String shortName; private ArrayList&lt;String&gt; types; public String getLongName() { return longName; } public String getShortName() { return shortName; } public ArrayList&lt;String&gt; getTypes() { return types; } } </code></pre> <p>A <strong>Coordinates</strong> used in other classes</p> <pre><code>public class Coordinates { private double lat; private double lng; public double getLat() { return lat; } public void setLat(double lat) { this.lat = lat; } public double getLng() { return lng; } public void setLng(double lng) { this.lng = lng; } } </code></pre> <p>and a <strong>Geometry</strong> with <strong>Viewport</strong>:</p> <pre><code>public class Geometry { private Coordinates location; @JsonProperty("location_type") private String locationType; private ViewPort viewport; public Coordinates getLocation() { return location; } public String getLocationType() { return locationType; } public ViewPort getViewport() { return viewport; } public static class ViewPort { private Coordinates northeast; private Coordinates southwest; public Coordinates getNortheast() { return northeast; } public Coordinates getSouthwest() { return southwest; } } } </code></pre> <p>and to wrap it up - for me this worked from first attempt:</p> <pre><code>protected void performJackson() { new AsyncTask&lt;Void, Void, Void&gt;() { @Override protected Void doInBackground(Void... params) { try { String baseUrl = "http://maps.google.com/maps/api/geocode/json?latlng=47.3195254,5.0430687&amp;sensor=true"; HttpURLConnection connection = (HttpURLConnection) new URL(baseUrl).openConnection(); ObjectMapper mapper = new ObjectMapper(); // disable exceptions when there is unknown properties mapper.disable(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES); int statusCode = connection.getResponseCode(); Log.d("SJackson", "Status : " + statusCode); if (statusCode == HttpURLConnection.HTTP_OK) { // 200 InputStream is = new BufferedInputStream(connection.getInputStream()); GeocoderResult result = mapper.readValue(is, GeocoderResult.class); Log.d("SJackson", "Done: " + (result != null)); } } catch (Exception ex) { Log.e("SJackson", null, ex); } return null; } }.execute(); } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload