类 JsonFileItemWriter<T>
- java.lang.Object
- org.springframework.batch.item.ItemStreamSupport
- org.springframework.batch.item.support.AbstractItemStreamItemWriter<T>
- org.springframework.batch.item.support.AbstractFileItemWriter<T>
- org.springframework.batch.item.json.JsonFileItemWriter<T>
- 类型参数:
T
- type of object to write as json representation
- 所有已实现的接口:
ResourceAwareItemWriterItemStream<T>
,ItemStream
,ItemStreamWriter<T>
,ItemWriter<T>
,org.springframework.beans.factory.InitializingBean
public class JsonFileItemWriter<T> extends AbstractFileItemWriter<T>
Item writer that writes data in json format to an output file. The location of the output file is defined by aResource
and must represent a writable file. Items are transformed to json format using aJsonObjectMarshaller
. Items will be enclosed in a json array as follows:
The implementation is not thread-safe.[ {json object}, {json object}, {json object} ]
- 从以下版本开始:
- 4.1
- 作者:
- Mahmoud Ben Hassine
- 另请参阅:
GsonJsonObjectMarshaller
,JacksonJsonObjectMarshaller
嵌套类概要
从类继承的嵌套类/接口 org.springframework.batch.item.support.AbstractFileItemWriter
AbstractFileItemWriter.OutputState
字段概要
从类继承的字段 org.springframework.batch.item.support.AbstractFileItemWriter
append, DEFAULT_CHARSET, DEFAULT_LINE_SEPARATOR, DEFAULT_TRANSACTIONAL, lineSeparator, logger, shouldDeleteIfExists, state
构造器概要
构造器 构造器 说明 JsonFileItemWriter(org.springframework.core.io.Resource resource, JsonObjectMarshaller<T> jsonObjectMarshaller)
Create a newJsonFileItemWriter
instance.
方法概要
所有方法 实例方法 具体方法 修饰符和类型 方法 说明 void
afterPropertiesSet()
Assert that mandatory properties (jsonObjectMarshaller) are set.java.lang.String
doWrite(java.util.List<? extends T> items)
Write out a string of items followed by a "new line", where the format of the new line separator is determined by the underlying operating system.void
setJsonObjectMarshaller(JsonObjectMarshaller<T> jsonObjectMarshaller)
Set theJsonObjectMarshaller
to use to marshal object to json.从类继承的方法 org.springframework.batch.item.support.AbstractFileItemWriter
close, getOutputState, open, setAppendAllowed, setEncoding, setFooterCallback, setForceSync, setHeaderCallback, setLineSeparator, setResource, setSaveState, setShouldDeleteIfEmpty, setShouldDeleteIfExists, setTransactional, update, write
从类继承的方法 org.springframework.batch.item.ItemStreamSupport
getExecutionContextKey, setExecutionContextName, setName
构造器详细资料
JsonFileItemWriter
public JsonFileItemWriter(org.springframework.core.io.Resource resource, JsonObjectMarshaller<T> jsonObjectMarshaller)
Create a newJsonFileItemWriter
instance.- 参数:
resource
- to write json data tojsonObjectMarshaller
- used to marshal object into json representation
方法详细资料
afterPropertiesSet
public void afterPropertiesSet() throws java.lang.Exception
Assert that mandatory properties (jsonObjectMarshaller) are set.- 抛出:
java.lang.Exception
- 另请参阅:
InitializingBean.afterPropertiesSet()
setJsonObjectMarshaller
public void setJsonObjectMarshaller(JsonObjectMarshaller<T> jsonObjectMarshaller)
Set theJsonObjectMarshaller
to use to marshal object to json.- 参数:
jsonObjectMarshaller
- the marshaller to use
doWrite
public java.lang.String doWrite(java.util.List<? extends T> items)
从类复制的说明:AbstractFileItemWriter
Write out a string of items followed by a "new line", where the format of the new line separator is determined by the underlying operating system.- 指定者:
doWrite
在类中AbstractFileItemWriter<T>
- 参数:
items
- to be written- 返回:
- written lines