【问题标题】:How to create reader for JSON file in Spring Batch如何在 Spring Batch 中为 JSON 文件创建阅读器
【发布时间】:2021-06-06 15:38:48
【问题描述】:

我有一个格式类似的 JSON 文件

{ 
    name : [
        "Karan",
         "Hemant",
         "Sanjay",
       ],
    user_id : 1,
    user_number : +9125468846 
}

我可以将 FlatFileItemReader 用于 CSV,但对于这种格式,我如何使用阅读器以及我只需要 name 和 user id 的阅读器,在我的 POJO 类中,我创建了两个属性 LIST name 和 int user_id 我想返回对象拥有这两个属性到处理器的客户,知道我该怎么做

【问题讨论】:

  • 你能在你的例子中添加另一个项目吗? json 对象如何在您的输入文件中存储/表示?输入文件的格式(ndjson.org、包含在数组中的常规 json 对象等)对于正确选择要使用的 json 阅读器很重要。
  • { "name" : [ "Karan", "Hemant", "Sanjay", ], "enabled_products" : ["product1","product2"], "user_id" : 1, "user_number" : +9125468846,"user_catrgory":"I","user_account" :"accountType" }
  • 请编辑您的问题并添加格式正确的第二项以查看您输入的结构。看不到格式,就无法正确回答您的问题。

标签: java spring spring-boot spring-batch


【解决方案1】:

【讨论】:

  • 我目前正在使用它,但它没有将数据映射到我想要的那些属性,我使用了resource(filepath).jsonObjectReader(ClassName::new).build()
  • 从文档看来,JSON中必须有一个项目数组,而不仅仅是顶级对象;你能把它包装起来(更改 JSON 文件),让它看起来像 { [ { name: '', ... } ] },看看会发生什么?
  • 更改格式不在我手中,它通过 api 来实现
猜你喜欢
  • 2014-02-24
  • 1970-01-01
  • 2012-09-19
  • 1970-01-01
  • 2014-03-15
  • 2019-08-25
  • 2019-05-04
  • 2019-06-04
  • 2019-01-26
相关资源
最近更新 更多