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