[英]Jackson Array serialize and de-serialize
我的傑克遜琴弦如下
{
"Response":{
"users":[{"userId":"1", "userName":"User 1"},{"userId":"2", "userName":"User 1"}]
}
}
My classes are following,
public class Response {
private List<User> users;
// getters and setters
}
public class User{
private String userId;
private String userName;
//getters and setters
}
當我嘗試從上述json字符串獲取java對象時。 它給了我以下錯誤。 任何想法如何解決這個問題?
com.fasterxml.jackson.databind.JsonMappingException:意外的令牌(START_ARRAY),預期的START_OBJECT:需要JSON對象包含類的As.WRAPPER_OBJECT類型信息
您需要再添加一個類包裝器:
class ResponseJson {
@JsonProperty("Response")
private Response response;
// getters, setters
}
另外,您需要注釋該注釋@JsonPropery,因為傑克遜在大寫字段名稱詳細信息方面存在一些問題: https : //github.com/swagger-api/swagger-codegen/issues/249
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.