英文:
Cannot Deserialize a JSON Array
问题
我正在尝试将这个JSON响应存储到一个对象中
[
{
"id": 52,
"disponibilita": 1,
"prezzo": 9
}
]
这是一个数组,我正在为它创建一个POJO类
private String id;
private String prezzo;
private String disponibilita;
private String titolo;
在主方法中,我尝试创建一个POJO类的对象并对其进行反序列化
poj = given().relaxedHTTPSValidation().header("Content-Type", "application/json")
.header("customerId", "xxx").header("S2S-Authorization", res4).expect()
.defaultParser(Parser.JSON).when()
.get("xxx").then()
.log().all().extract().response().as(pojode.class);
List
System.out.println(myList);
收到以下错误
Exception in thread "main" com.fasterxml.jackson.databind.exc.MismatchedInputException: Cannot deserialize instance of
Practise.pojode out of START_ARRAY token
英文:
Iam trying to store this JSON Response in an Object
[
{
"id": 52,
"disponibilita": 1,
"prezzo": 9
}
]
This is an Array and i am Creating a POJO Clss for it
private String id ;
private String prezzo ;
private String disponibilita ;
private String titolo;
In the main Method i am trying to create a object for the pojo class and deserialize it
poj = given().relaxedHTTPSValidation().header("Content-Type", "application/json")
.header("customerId", "xxx").header("S2S-Authorization", res4).expect()
.defaultParser(Parser.JSON).when()
.get("xxx").then()
.log().all().extract().response().as(pojode.class);
List<String> myList = poj.getAction();
System.out.println(myList);
Getting the Below Error
Exception in thread "main" com.fasterxml.jackson.databind.exc.MismatchedInputException: Cannot deserialize instance of
Practise.pojode out of START_ARRAY token
答案1
得分: 0
需要将 JSON 数组 []
映射到 Java 数组或集合。
pojode[] poj = given()...as(pojode[].class);
System.out.println(Arrays.toString(poj));
英文:
You need to map json array []
to Java array or Collection.
pojode[] poj = given()...as(pojode[].class);
System.out.println(Arrays.toString(poj));
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论