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