@JsonCreator 不反序列化枚举类型的 @RequestParam
我正在开发一个 Spring 应用程序,其中控制器正在接收 Spring 绑定到包装器对象的请求参数列表。其中一个参数是 enum 类型,我通过某个属性名称接收它。
Endpoint example: http://localhost:8080/searchCustomers?lastName=Smith&country=Netherlands
@RequestMapping(value = "/search/customers", method = RequestMethod.GET)
public CustomerList searchCustomers(@Valid CustomerSearchCriteria searchCriteria)
public class CustomerSearchCriteria {
private String lastName;
private Country country;
}
public enum Country {
GB("United Kingdom"),
NL("Netherlands")
private String countryName;
Country(String countryName) {
countryName = countryName;
}
@JsonCreator
public static Country fromCountryName(String countryName) {
for(Country country : Country.values()) {
if(country.getCountryName().equalsIgnoreCase(countryName)) {
return country;
}
}
return null;
}
@JsonValue
public String toCountryName() {
return countryName; …Run Code Online (Sandbox Code Playgroud) 我正在尝试使用 Google Places API 查找给定邮政编码附近的餐馆。我在 API 调用中使用的纬度/经度与 Google 地图网站返回的纬度/经度相同,但餐厅列表几乎有 80% 不同。
我的 API 调用如下所示
我该怎么做才能从 Google Places API 返回更准确的结果(最好与从maps.google.com 返回的列表相同)?