Class JsonFileItemWriter<T>
java.lang.Object
org.springframework.batch.infrastructure.item.ItemStreamSupport
org.springframework.batch.infrastructure.item.support.AbstractItemStreamItemWriter<T>
org.springframework.batch.infrastructure.item.support.AbstractFileItemWriter<T>
org.springframework.batch.infrastructure.item.json.JsonFileItemWriter<T>
- Type Parameters:
T- type of object to write as json representation
- All Implemented Interfaces:
ResourceAwareItemWriterItemStream<T>, ItemStream, ItemStreamWriter<T>, ItemWriter<T>, org.springframework.beans.factory.Aware, org.springframework.beans.factory.BeanNameAware, org.springframework.beans.factory.InitializingBean
Item writer that writes data in json format to an output file. The location of the
output file is defined by a
WritableResource and must represent a writable
file. Items are transformed to json format using a JsonObjectMarshaller. Items
will be enclosed in a json array as follows:
[
{json object},
{json object},
{json object}
]
- Since:
- 4.1
- Author:
- Mahmoud Ben Hassine, Jimmy Praet
- See Also:
-
Nested Class Summary
Nested classes/interfaces inherited from class AbstractFileItemWriter
AbstractFileItemWriter.OutputState -
Field Summary
Fields inherited from class AbstractFileItemWriter
append, DEFAULT_CHARSET, DEFAULT_LINE_SEPARATOR, DEFAULT_TRANSACTIONAL, lineSeparator, logger, resource, shouldDeleteIfExists, state -
Constructor Summary
ConstructorsConstructorDescriptionJsonFileItemWriter(org.springframework.core.io.WritableResource resource, JsonObjectMarshaller<T> jsonObjectMarshaller) Create a newJsonFileItemWriterinstance. -
Method Summary
Modifier and TypeMethodDescriptionvoidAssert that mandatory properties (jsonObjectMarshaller) are set.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.voidsetJsonObjectMarshaller(JsonObjectMarshaller<T> jsonObjectMarshaller) Set theJsonObjectMarshallerto use to marshal object to json.Methods inherited from class AbstractFileItemWriter
close, getOutputState, open, setAppendAllowed, setEncoding, setFooterCallback, setForceSync, setHeaderCallback, setLineSeparator, setResource, setSaveState, setShouldDeleteIfEmpty, setShouldDeleteIfExists, setTransactional, update, writeMethods inherited from class ItemStreamSupport
getExecutionContextKey, getName, setBeanName, setExecutionContextName, setName
-
Constructor Details
-
JsonFileItemWriter
public JsonFileItemWriter(org.springframework.core.io.WritableResource resource, JsonObjectMarshaller<T> jsonObjectMarshaller) Create a newJsonFileItemWriterinstance.- Parameters:
resource- to write json data tojsonObjectMarshaller- used to marshal object into json representation
-
-
Method Details
-
afterPropertiesSet
-
setJsonObjectMarshaller
Set theJsonObjectMarshallerto use to marshal object to json.- Parameters:
jsonObjectMarshaller- the marshaller to use
-
doWrite
Description copied from class:AbstractFileItemWriterWrite 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.- Specified by:
doWritein classAbstractFileItemWriter<T>- Parameters:
items- to be written- Returns:
- written lines
-