Class StreamingJsonArrayFileReader<T>

java.lang.Object
com.broadleafcommerce.datafeed.service.publisher.file.support.StreamingJsonArrayFileReader<T>
Type Parameters:
T - the POJO type to deserialize each array element into

public class StreamingJsonArrayFileReader<T> extends Object
Useful for reading through a file which is just a JSON array of objects (ex: typically what is in DataFeedProcessExecution.getQueriedDataFileLocation() when using AbstractJsonArrayDataFeedCollector). This utility allows consumers to read elements from such a file in a streaming fashion (to avoid loading everything into memory at once).

This is not intended to be a bean, and is expected to be manually instantiated and used to process a specific file.

  • Constructor Details

    • StreamingJsonArrayFileReader

      public StreamingJsonArrayFileReader(com.fasterxml.jackson.databind.ObjectMapper objectMapper, Class<T> deserializedElementType, int maxElementsToReadInBatch, Consumer<List<T>> elementBatchHandler, Path fileToProcess)
  • Method Details

    • read

      public void read() throws IOException
      Throws:
      IOException - if something went wrong
    • getObjectMapper

      protected com.fasterxml.jackson.databind.ObjectMapper getObjectMapper()
      The ObjectMapper to use for deserialization.
    • getDeserializedElementType

      protected Class<T> getDeserializedElementType()
      The POJO type to deserialize each element into.
    • getMaxElementsToReadInBatch

      protected int getMaxElementsToReadInBatch()
      The number of elements to load into memory and transform at a time.
    • getElementBatchHandler

      protected Consumer<List<T>> getElementBatchHandler()
      A callback that will do work on a batch of read elements.
    • getFileToProcess

      protected Path getFileToProcess()
      The JSON array file to process.