java - Json映射非标准接口(interface)

标签 java jackson restful-url

我得到了一个响应,它是对象的映射,但它们都有相同的键:

{
    "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/

相关文章:

jackson - 如何反序列化引用 Jackson 中的抽象类型的 JSON

grails - Grails3 Restful API URL映射原理,用于多个查询

java - JsonIgnore 不适用于 Spring

java - 使用 Pageable 字段测试端点时出现 JsonMappingException

rest - REST 架构中的分页

RESTful API - 不同类型的子资源

java - 错误 : Could not find or load main class (Command Prompt). 包名称有何影响

java - 如何从语言中获取本地国家?

java - 读取 JNLP 中通过 href 标签传递的属性

java - 使用 Spring Boot 配置 Ehcache TTL 超时