Class GeocodingResponse

java.lang.Object
com.targomo.client.api.response.GeocodingResponse
All Implemented Interfaces:
Iterable<Candidate>

public class GeocodingResponse extends Object implements Iterable<Candidate>
Response of the ESRI geocoding REST service for a requested address. There are two different possible response types:
  • (1) the response was an error message (wasErrorResponse()==true), i.e. error value is set - see ErrorDescription
  • (2) the request was successful (wasErrorResponse()==false) the candidates value is set

Note: It is immutable with a private constructor since it is only meant to be created from the returned json object.
Note: This is not the complete response from the REST service - only relevant information is captured, the remainder is discarded.

  • Constructor Details

    • GeocodingResponse

      public GeocodingResponse(List<Candidate> candidates, ErrorDescription error, String jsonString)
      private - not used since this is a POJO only created from a json String
  • Method Details

    • createFromJson

      public static GeocodingResponse createFromJson(String jsonString)
      Creates the response from a JSON String
      Parameters:
      jsonString - to be parsed
      Returns:
      the resulting POJO GeocodingResponse
    • getError

      public ErrorDescription getError()
      Returns:
      if an error occurred, the ErrorDescription is returned
    • wasErrorResponse

      public boolean wasErrorResponse()
      Returns:
      true if error was recorded; false otherwise
    • getCompleteJsonResponseAsString

      public String getCompleteJsonResponseAsString()
      Returns:
      the complete JSON response as String
    • getRepresentativeGeocodeOfRequest

      public DefaultTargetCoordinate getRepresentativeGeocodeOfRequest()
      Returns:
      the first (and thus best) candidate coordinates contained in this geocoding response.
      Throws:
      NoSuchElementException - when response contains no candidates
    • getRepresentativeCandidate

      public Candidate getRepresentativeCandidate()
      Returns:
      the first (and thus best) candidate contained in this geocoding response.
      Throws:
      NoSuchElementException - when response contains no candidates
    • toString

      public String toString()
      Pretty prints the GeocodingResponse, i.e. with indention and line breaks.
      Overrides:
      toString in class Object
      Returns:
      the pretty print String of the response
    • iterator

      public Iterator<Candidate> iterator()
      Specified by:
      iterator in interface Iterable<Candidate>
    • isEmpty

      public boolean isEmpty()
      Returns:
      true if empty; false otherwise