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
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 Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionThe POJO type to deserialize each element into.A callback that will do work on a batch of read elements.protected PathThe JSON array file to process.protected intThe number of elements to load into memory and transform at a time.protected com.fasterxml.jackson.databind.ObjectMapperTheObjectMapperto use for deserialization.voidread()
-
Constructor Details
-
StreamingJsonArrayFileReader
public StreamingJsonArrayFileReader(com.fasterxml.jackson.databind.ObjectMapper objectMapper, Class<T> deserializedElementType, int maxElementsToReadInBatch, Consumer<List<T>> elementBatchHandler, Path fileToProcess) Creates a newStreamingJsonArrayFileReaderinstance.- Parameters:
objectMapper- TheObjectMapperto use for deserialization.deserializedElementType- The POJO type to deserialize each element into.maxElementsToReadInBatch- The number of elements to load into memory and transform at a time.elementBatchHandler- A callback that will do work on a batch of read elements.fileToProcess- The JSON array file to process.
-
-
Method Details
-
read
- Throws:
IOException- if something went wrong
-
getObjectMapper
protected com.fasterxml.jackson.databind.ObjectMapper getObjectMapper()TheObjectMapperto use for deserialization. -
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
A callback that will do work on a batch of read elements. -
getFileToProcess
The JSON array file to process.
-