Package org.springframework.batch.item.json.builder

# 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 Object
Builder for `JsonFileItemWriter`.

Since:
  4.1
Author:
  Mahmoud Ben Hassine

- ## Constructor Summary

  Constructors
  Constructor
  Description
  `JsonFileItemWriterBuilder()`

- ## Method Summary

  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 new `JsonFileItemWriter`.
  `JsonFileItemWriterBuilder<T>`
  `encoding(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 the `JsonObjectMarshaller` to use to marshal objects to json.
  `JsonFileItemWriterBuilder<T>`
  `lineSeparator(String lineSeparator)`
  String used to separate lines in output.
  `JsonFileItemWriterBuilder<T>`
  `name(String name)`
  The name used to calculate the key within the `ExecutionContext`.
  `JsonFileItemWriterBuilder<T>`
  `resource(org.springframework.core.io.Resource resource)`
  The `Resource` to be used as output.
  `JsonFileItemWriterBuilder<T>`
  `saveState(boolean saveState)`
  Configure if the state of the `ItemStreamSupport` should be persisted within the `ExecutionContext` for 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.

  ### Methods inherited from class java.lang.Object

  `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- ## Constructor Details

  - ### JsonFileItemWriterBuilder

    public JsonFileItemWriterBuilder()

- ## Method Details

  - ### saveState

    public JsonFileItemWriterBuilder<T> saveState(boolean saveState)
    Configure if the state of the `ItemStreamSupport` should be persisted within the `ExecutionContext` for restart purposes.
    Parameters:
      `saveState` - defaults to true
    Returns:
      The current instance of the builder.

  - ### name

    public JsonFileItemWriterBuilder<T> name(String name)
    The name used to calculate the key within the `ExecutionContext`. Required if `saveState(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(String lineSeparator)
    String used to separate lines in output. Defaults to the System property `line.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 the `JsonObjectMarshaller` to 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)
    The `Resource` to 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(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` - `FlatFileHeaderCallback` implementation
    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` - `FlatFileFooterCallback` implementation
    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 new `JsonFileItemWriter`.
    Returns:
      a new instance of the `JsonFileItemWriter`