Class 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.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 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} ]

The implementation is not thread-safe.
Since:
4.1
Author:
Mahmoud Ben Hassine
See Also:
  • Constructor Details

    • JsonFileItemWriter

      public JsonFileItemWriter(org.springframework.core.io.WritableResource resource, JsonObjectMarshaller<T> jsonObjectMarshaller)
      Create a new JsonFileItemWriter instance.
      Parameters:
      resource - to write json data to
      jsonObjectMarshaller - used to marshal object into json representation
  • Method Details

    • afterPropertiesSet

      public void afterPropertiesSet() throws Exception
      Assert that mandatory properties (jsonObjectMarshaller) are set.
      Throws:
      Exception
      See Also:
      • InitializingBean.afterPropertiesSet()
    • setJsonObjectMarshaller

      public void setJsonObjectMarshaller(JsonObjectMarshaller<T> jsonObjectMarshaller)
      Set the JsonObjectMarshaller to use to marshal object to json.
      Parameters:
      jsonObjectMarshaller - the marshaller to use
    • doWrite

      public String doWrite(Chunk<? extends T> items)
      Description copied from class: 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.
      Specified by:
      doWrite in class AbstractFileItemWriter<T>
      Parameters:
      items - to be written
      Returns:
      written lines