我得到了一个响应,它是对象的映射,但它们都有相同的键:
{
"hits": [
{
"recipe": {
"id" : "0",
"label" : "chicken noodles",
...
},
"another_field": "value"
},
{
"recipe": {
"id" : "1",
"label" : "fried chicken",
...
},
"another_field": "value"
},
{ "recipe": {...}, ... }
]
}
我的Pojo:
public class SearchRecipeResponse {
private List<RecipeResponse> hits;
public List<RecipeResponse> getHits() {
return hits;
}
}
public class RecipeResponse{
private String label;
...
getters, etc
}
结果以对象列表的形式出现,但所有对象均为空,因为 json 有效负载具有此键“recipe”。
最佳答案
您可以为配方创建 POJO 并将其用于映射。虽然不确定这就是您想要做的,但您需要扩展您的问题以增加清晰度。
关于java - Json映射非标准接口(interface),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62427953/