Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/303.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 没有要从字符串值反序列化的字符串参数构造函数/工厂方法-从restTemplate反序列化json对象时出现异常_Java_Json_Jackson_Deserialization_Resttemplate - Fatal编程技术网

Java 没有要从字符串值反序列化的字符串参数构造函数/工厂方法-从restTemplate反序列化json对象时出现异常

Java 没有要从字符串值反序列化的字符串参数构造函数/工厂方法-从restTemplate反序列化json对象时出现异常,java,json,jackson,deserialization,resttemplate,Java,Json,Jackson,Deserialization,Resttemplate,在调用检索json响应并对其进行解析时遇到问题 [ { "name": "john doe", "age": "24", "address": "{\"state\":\"LA\",\"country\":\"US\"}" } ] 型

在调用检索json响应并对其进行解析时遇到问题

[
    {
        "name": "john doe",
        "age": "24",
        "address": "{\"state\":\"LA\",\"country\":\"US\"}"
    }
]
型号:

Person.java

@Data
@NoArgsConstructor
@JsonIgnoreProperties(ignoreUnknown = true) 
public class Person {
    private String name;
    private String age;
    private Address address;
}
地址:java

@Data
@NoArgsConstructor
@JsonIgnoreProperties(ignoreUnknown = true) 
public class Address {
    private String state;
    private String country;
}
读取此数据的代码

ResponseEntity<List<Person>> response = restTemplate.exchange(builder.toUriString(), HttpMethod.GET,requestEntity,new ParameterizedTypeReference<List<Person>>() {});
ResponseEntity response=restemplate.exchange(builder.toUriString(),HttpMethod.GET,requestEntity,new parameteredTypeReference(){});
但我得到以下例外

调用ABS ServiceError时发生RestClientException,提取类型
[java.util.List]
和内容类型[application/json;charset=UTF-8]的响应时发生错误;嵌套的异常是org.springframework.http.converter.httpMessageEndableException:JSON解析错误:无法构造
com.bp.model.Address
(尽管至少存在一个创建者):没有字符串参数构造函数/工厂方法从字符串值反序列化(“{”state:“LA”,“country:“US”}”);嵌套异常为com.fasterxml.jackson.databind.exc.MismatchedInputException:无法构造
com.bp.model.Address
(尽管至少存在一个创建者):没有字符串参数构造函数/工厂方法从字符串值反序列化(“{”state:“IN”,“brand:“anthem”}”) 在[Source:(PushbackInputStream);第1行,第325列](通过引用链:java.util.ArrayList[0]->com.bp.model.Person[“address”])


代码是正确的,但JSON有一个问题。地址是字符串而不是JSON对象。要让它工作,它需要类似于:

"address": {"state": "LA", "country": "US"}

没有外部引号和转义字符。

@rph非常感谢!我完全忽略了json:)