Class JsonFileItemWriterBuilder<T>
- java.lang.Object
- org.springframework.batch.item.json.builder.JsonFileItemWriterBuilder<T>
- Type Parameters:
T- type of objects to write as Json output.
public class JsonFileItemWriterBuilder<T> extends java.lang.ObjectBuilder forJsonFileItemWriter.- Since:
- 4.1
- Author:
- Mahmoud Ben Hassine
Constructor Summary
Constructors Constructor Description JsonFileItemWriterBuilder()
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description JsonFileItemWriterBuilder<T>append(boolean append)If set to true and the file exists, the output will be appended to the existing file.JsonFileItemWriter<T>build()Validate the configuration and build a newJsonFileItemWriter.JsonFileItemWriterBuilder<T>encoding(java.lang.String encoding)Encoding used for output.JsonFileItemWriterBuilder<T>footerCallback(FlatFileFooterCallback callback)A callback for footer processing.JsonFileItemWriterBuilder<T>forceSync(boolean forceSync)A flag indicating that changes should be force-synced to disk on flush.JsonFileItemWriterBuilder<T>headerCallback(FlatFileHeaderCallback callback)A callback for header processing.JsonFileItemWriterBuilder<T>jsonObjectMarshaller(JsonObjectMarshaller<T> jsonObjectMarshaller)Set theJsonObjectMarshallerto use to marshal objects to json.JsonFileItemWriterBuilder<T>lineSeparator(java.lang.String lineSeparator)String used to separate lines in output.JsonFileItemWriterBuilder<T>name(java.lang.String name)The name used to calculate the key within theExecutionContext.JsonFileItemWriterBuilder<T>resource(org.springframework.core.io.Resource resource)TheResourceto be used as output.JsonFileItemWriterBuilder<T>saveState(boolean saveState)Configure if the state of theItemStreamSupportshould be persisted within theExecutionContextfor restart purposes.JsonFileItemWriterBuilder<T>shouldDeleteIfEmpty(boolean shouldDelete)If set to true, once the step is complete, if the resource previously provided is empty, it will be deleted.JsonFileItemWriterBuilder<T>shouldDeleteIfExists(boolean shouldDelete)If set to true, upon the start of the step, if the resource already exists, it will be deleted and recreated.JsonFileItemWriterBuilder<T>transactional(boolean transactional)If set to true, the flushing of the buffer is delayed while a transaction is active.
Method Detail
saveState
public JsonFileItemWriterBuilder<T> saveState(boolean saveState)
Configure if the state of theItemStreamSupportshould be persisted within theExecutionContextfor restart purposes.- Parameters:
saveState- defaults to true- Returns:
- The current instance of the builder.
name
public JsonFileItemWriterBuilder<T> name(java.lang.String name)
The name used to calculate the key within theExecutionContext. Required ifsaveState(boolean)is set to true.- Parameters:
name- name of the reader instance- Returns:
- The current instance of the builder.
- See Also:
ItemStreamSupport.setName(String)
forceSync
public JsonFileItemWriterBuilder<T> forceSync(boolean forceSync)
A flag indicating that changes should be force-synced to disk on flush. Defaults to false.- Parameters:
forceSync- value to set the flag to- Returns:
- The current instance of the builder.
- See Also:
AbstractFileItemWriter.setForceSync(boolean)
lineSeparator
public JsonFileItemWriterBuilder<T> lineSeparator(java.lang.String lineSeparator)
String used to separate lines in output. Defaults to the System propertyline.separator.- Parameters:
lineSeparator- value to use for a line separator- Returns:
- The current instance of the builder.
- See Also:
AbstractFileItemWriter.setLineSeparator(String)
jsonObjectMarshaller
public JsonFileItemWriterBuilder<T> jsonObjectMarshaller(JsonObjectMarshaller<T> jsonObjectMarshaller)
Set theJsonObjectMarshallerto use to marshal objects to json.- Parameters:
jsonObjectMarshaller- to use- Returns:
- The current instance of the builder.
- See Also:
JsonFileItemWriter.setJsonObjectMarshaller(JsonObjectMarshaller)
resource
public JsonFileItemWriterBuilder<T> resource(org.springframework.core.io.Resource resource)
TheResourceto be used as output.- Parameters:
resource- the output of the writer.- Returns:
- The current instance of the builder.
- See Also:
AbstractFileItemWriter.setResource(Resource)
encoding
public JsonFileItemWriterBuilder<T> encoding(java.lang.String encoding)
Encoding used for output.- Parameters:
encoding- encoding type.- Returns:
- The current instance of the builder.
- See Also:
AbstractFileItemWriter.setEncoding(String)
shouldDeleteIfEmpty
public JsonFileItemWriterBuilder<T> shouldDeleteIfEmpty(boolean shouldDelete)
If set to true, once the step is complete, if the resource previously provided is empty, it will be deleted.- Parameters:
shouldDelete- defaults to false- Returns:
- The current instance of the builder
- See Also:
AbstractFileItemWriter.setShouldDeleteIfEmpty(boolean)
shouldDeleteIfExists
public JsonFileItemWriterBuilder<T> shouldDeleteIfExists(boolean shouldDelete)
If set to true, upon the start of the step, if the resource already exists, it will be deleted and recreated.- Parameters:
shouldDelete- defaults to true- Returns:
- The current instance of the builder
- See Also:
AbstractFileItemWriter.setShouldDeleteIfExists(boolean)
append
public JsonFileItemWriterBuilder<T> append(boolean append)
If set to true and the file exists, the output will be appended to the existing file.- Parameters:
append- defaults to false- Returns:
- The current instance of the builder
- See Also:
AbstractFileItemWriter.setAppendAllowed(boolean)
headerCallback
public JsonFileItemWriterBuilder<T> headerCallback(FlatFileHeaderCallback callback)
A callback for header processing.- Parameters:
callback-FlatFileHeaderCallbackimplementation- Returns:
- The current instance of the builder
- See Also:
AbstractFileItemWriter.setHeaderCallback(FlatFileHeaderCallback)
footerCallback
public JsonFileItemWriterBuilder<T> footerCallback(FlatFileFooterCallback callback)
A callback for footer processing.- Parameters:
callback-FlatFileFooterCallbackimplementation- Returns:
- The current instance of the builder
- See Also:
AbstractFileItemWriter.setFooterCallback(FlatFileFooterCallback)
transactional
public JsonFileItemWriterBuilder<T> transactional(boolean transactional)
If set to true, the flushing of the buffer is delayed while a transaction is active.- Parameters:
transactional- defaults to true- Returns:
- The current instance of the builder
- See Also:
AbstractFileItemWriter.setTransactional(boolean)
build
public JsonFileItemWriter<T> build()
Validate the configuration and build a newJsonFileItemWriter.- Returns:
- a new instance of the
JsonFileItemWriter