JsonMappingExceptionUnrecognized field Problem

blindmind

Mitglied
Hallo Zusammen!
Folgende Situation:
Ich mache einen Rest-Call gegen die Google Geocoder API und bekommen das Ergebnis als JSON-String, welchen ich mit Jackson in ein Objekt mappen möchte. Dazu existiert folgende Klasse (getter/setter ausgelassen):

Code:
//@JsonIgnoreProperties(ignoreUnknown = true)
public class GeoCodeResponse
{
	@JsonProperty("status")
	public String status;
	
	@JsonProperty("results")
	public Results[] results;
	
	public GeoCodeResponse() {	
	}

	public class Results
	{
		@JsonCreator
		public Results() {
		}

		@JsonProperty("formatted_address")
		public String formattedAddress;
		
		@JsonProperty("address_components")
		public AddressComponents[] addressComponents;
	}
	
	public class AddressComponents
	{
		@JsonCreator
		public AddressComponents() {
		}
		
		public String long_name;
		public String short_name;
		public String[] types;
	}
}

und folgender Aufruf:

Code:
final String apiResponse = getGeoCoderApiResponse(latitude, 
LOG.debug("api response: {}", apiResponse);
try {
    final GeoCodeResponse response = objectMapper.readValue(apiResponse, GeoCodeResponse.class);
    LOG.debug("parsed GeoCodeResponse: {}", response);
}

Die apiResponse hat folgenden Inhalt:

Code:
{
   "results" : [
      {
         "address_components" : [
            {
               "long_name" : "717",
               "short_name" : "717",
               "types" : [ "route" ]
            },
            {
               "long_name" : "Värmland County",
               "short_name" : "Värmland County",
               "types" : [ "administrative_area_level_1", "political" ]
            },
            {
               "long_name" : "Sweden",
               "short_name" : "SE",
               "types" : [ "country", "political" ]
            },
            {
               "long_name" : "66991",
               "short_name" : "66991",
               "types" : [ "postal_code" ]
            },
            {
               "long_name" : "Deje",
               "short_name" : "Deje",
               "types" : [ "postal_town" ]
            }
         ],
         "formatted_address" : "717, 669 91 Deje, Sweden",
         "geometry" : {
            "bounds" : {
               "northeast" : {
                  "lat" : 59.55148389999999,
                  "lng" : 13.41808010
               },
               "southwest" : {
                  "lat" : 59.54473329999999,
                  "lng" : 13.41663310
               }
            },
            "location" : {
               "lat" : 59.54815460,
               "lng" : 13.4178270
            },
            "location_type" : "APPROXIMATE",
            "viewport" : {
               "northeast" : {
                  "lat" : 59.55148389999999,
                  "lng" : 13.41870558029150
               },
               "southwest" : {
                  "lat" : 59.54473329999999,
                  "lng" : 13.41600761970850
               }
            }
         },
         "types" : [ "route" ]
      },
      {
         "address_components" : [
            {
               "long_name" : "66731",
               "short_name" : "66731",
               "types" : [ "postal_code" ]
            },
            {
               "long_name" : "Värmland County",
               "short_name" : "Värmland County",
               "types" : [ "administrative_area_level_1", "political" ]
            },
            {
               "long_name" : "Sweden",
               "short_name" : "SE",
               "types" : [ "country", "political" ]
            },
            {
               "long_name" : "Forshaga",
               "short_name" : "Forshaga",
               "types" : [ "postal_town" ]
            }
         ],
         "formatted_address" : "667 31 Forshaga, Sweden",
         "geometry" : {
            "bounds" : {
               "northeast" : {
                  "lat" : 59.56482290,
                  "lng" : 13.49849390
               },
               "southwest" : {
                  "lat" : 59.5299580,
                  "lng" : 13.41098690
               }
            },
            "location" : {
               "lat" : 59.54792410,
               "lng" : 13.45675190
            },
            "location_type" : "APPROXIMATE",
            "viewport" : {
               "northeast" : {
                  "lat" : 59.56482290,
                  "lng" : 13.49849390
               },
               "southwest" : {
                  "lat" : 59.5299580,
                  "lng" : 13.41098690
               }
            }
         },
         "types" : [ "postal_code" ]
      },
      {
         "address_components" : [
            {
               "long_name" : "Forshaga",
               "short_name" : "Forshaga",
               "types" : [ "postal_town" ]
            },
            {
               "long_name" : "Värmland County",
               "short_name" : "Värmland County",
               "types" : [ "administrative_area_level_1", "political" ]
            },
            {
               "long_name" : "Sweden",
               "short_name" : "SE",
               "types" : [ "country", "political" ]
            }
         ],
         "formatted_address" : "Forshaga, Sweden",
         "geometry" : {
            "bounds" : {
               "northeast" : {
                  "lat" : 59.57255210,
                  "lng" : 13.59030310
               },
               "southwest" : {
                  "lat" : 59.4652470,
                  "lng" : 13.39565190
               }
            },
            "location" : {
               "lat" : 59.52647330000001,
               "lng" : 13.49340930
            },
            "location_type" : "APPROXIMATE",
            "viewport" : {
               "northeast" : {
                  "lat" : 59.57255210,
                  "lng" : 13.59030310
               },
               "southwest" : {
                  "lat" : 59.4652470,
                  "lng" : 13.39565190
               }
            }
         },
         "types" : [ "postal_town" ]
      },
      {
         "address_components" : [
            {
               "long_name" : "Forshaga V",
               "short_name" : "Forshaga V",
               "types" : [ "sublocality", "political" ]
            },
            {
               "long_name" : "Värmland County",
               "short_name" : "Värmland County",
               "types" : [ "administrative_area_level_1", "political" ]
            },
            {
               "long_name" : "Sweden",
               "short_name" : "SE",
               "types" : [ "country", "political" ]
            }
         ],
         "formatted_address" : "Forshaga V, Sweden",
         "geometry" : {
            "bounds" : {
               "northeast" : {
                  "lat" : 59.7621330,
                  "lng" : 13.51439710
               },
               "southwest" : {
                  "lat" : 59.4851720,
                  "lng" : 13.34480110
               }
            },
            "location" : {
               "lat" : 59.65289830,
               "lng" : 13.40750750
            },
            "location_type" : "APPROXIMATE",
            "viewport" : {
               "northeast" : {
                  "lat" : 59.7621330,
                  "lng" : 13.51439710
               },
               "southwest" : {
                  "lat" : 59.4851720,
                  "lng" : 13.34480110
               }
            }
         },
         "types" : [ "sublocality", "political" ]
      },
      {
         "address_components" : [
            {
               "long_name" : "Forshaga",
               "short_name" : "Forshaga",
               "types" : [ "administrative_area_level_2", "political" ]
            },
            {
               "long_name" : "Värmland County",
               "short_name" : "Värmland County",
               "types" : [ "administrative_area_level_1", "political" ]
            },
            {
               "long_name" : "Sweden",
               "short_name" : "SE",
               "types" : [ "country", "political" ]
            }
         ],
         "formatted_address" : "Forshaga, Sweden",
         "geometry" : {
            "bounds" : {
               "northeast" : {
                  "lat" : 59.80336310,
                  "lng" : 13.65750890
               },
               "southwest" : {
                  "lat" : 59.4783970,
                  "lng" : 13.35987910
               }
            },
            "location" : {
               "lat" : 59.62834600000001,
               "lng" : 13.53006610
            },
            "location_type" : "APPROXIMATE",
            "viewport" : {
               "northeast" : {
                  "lat" : 59.80336310,
                  "lng" : 13.65750890
               },
               "southwest" : {
                  "lat" : 59.4783970,
                  "lng" : 13.35987910
               }
            }
         },
         "types" : [ "administrative_area_level_2", "political" ]
      },
      {
         "address_components" : [
            {
               "long_name" : "Värmland County",
               "short_name" : "Värmland County",
               "types" : [ "administrative_area_level_1", "political" ]
            },
            {
               "long_name" : "Sweden",
               "short_name" : "SE",
               "types" : [ "country", "political" ]
            }
         ],
         "formatted_address" : "Värmland County, Sweden",
         "geometry" : {
            "bounds" : {
               "northeast" : {
                  "lat" : 61.06945409999999,
                  "lng" : 14.489750
               },
               "southwest" : {
                  "lat" : 58.83082580000001,
                  "lng" : 11.6818770
               }
            },
            "location" : {
               "lat" : 59.72940650,
               "lng" : 13.23540240
            },
            "location_type" : "APPROXIMATE",
            "viewport" : {
               "northeast" : {
                  "lat" : 61.06945409999999,
                  "lng" : 14.489750
               },
               "southwest" : {
                  "lat" : 58.83085910,
                  "lng" : 11.6818770
               }
            }
         },
         "types" : [ "administrative_area_level_1", "political" ]
      },
      {
         "address_components" : [
            {
               "long_name" : "Sweden",
               "short_name" : "SE",
               "types" : [ "country", "political" ]
            }
         ],
         "formatted_address" : "Sweden",
         "geometry" : {
            "bounds" : {
               "northeast" : {
                  "lat" : 69.05997090,
                  "lng" : 24.16659230
               },
               "southwest" : {
                  "lat" : 55.33670240,
                  "lng" : 10.96318660
               }
            },
            "location" : {
               "lat" : 60.12816100000001,
               "lng" : 18.6435010
            },
            "location_type" : "APPROXIMATE",
            "viewport" : {
               "northeast" : {
                  "lat" : 69.05997090,
                  "lng" : 24.1660240
               },
               "southwest" : {
                  "lat" : 55.33670240,
                  "lng" : 10.96318660
               }
            }
         },
         "types" : [ "country", "political" ]
      }
   ],
   "status" : "OK"
}

Das Problem ist das ich immer die folgende Exception bekomme:

Code:
 JsonMappingException: Unrecognized field "address_components" (Class net.GeoCodeResponse), not marked as ignorable


Ich kann leider nicht nachvollziehen wieso, da ich denke, das meine GeoCodeResponse Klasse richtig modelliert ist. Aber wenn ich die Annotation @JsonIgnoreProperties(ignoreUnknown = true) benutze sind die Felder addressComponents sowie formattedAddress immer NULL obwohl diese Objekte im JSON-String existieren...

Bin Danke im voraus für jede Anregung!!