Spring Batch JSON 支持

Spring Batch 4.1 开始可以支持 JSON 格式了。这个发布介绍了一个新的数据读(item reader)可以读取一个 JSON 资源,这个资源按照下面的格式:git

[
  {
    "isin": "123",
    "quantity": 1,
    "price": 1.2,
    "customer": "foo"
  },
  {
    "isin": "456",
    "quantity": 2,
    "price": 1.4,
    "customer": "bar"
  }
]

 

与针对 XML 的 StaxEventItemReader 相似,新的 JsonItemReader 使用流 API(streaming APIs)来读取 JSON 对象到块中。Spring Batch 可以支持下面 2 个库:github

若是你还但愿添加其余的库的话,你能够实现 JsonObjectReader  接口。google

JSON 数据的写是经过 JsonFileItemWriter 来支持的。code

有关更多 JSON 数据的支持,请参考 ItemReaders and ItemWriters 章节中的内容。对象

https://www.cwiki.us/display/SpringBatchZH/JSON+support接口

相关文章
相关标签/搜索