Spring Batch JSON 支持

Spring Batch 4.1 開始能夠支持 JSON 格式了。這個發佈介紹了一個新的數據讀(item reader)能夠讀取一個 JSON 資源,這個資源按照下面的格式:

[
  {
    "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 個庫:

如果你還希望添加其他的庫的話,你可以實現 JsonObjectReader  接口。

JSON 數據的寫是通過 JsonFileItemWriter 來支持的。

有關更多 JSON 數據的支持,請參考 ItemReaders and ItemWriters 章節中的內容。

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


發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章