Package org.dbunit.dataset.json
Class JsonProducer
java.lang.Object
org.dbunit.dataset.json.JsonProducer
- All Implemented Interfaces:
IDataSetProducer
Produces a dataset by reading a JSON document.
The expected JSON format is a top-level object whose keys are table names and whose values
are arrays of row objects. Each row object maps column names to cell values. Missing keys within
a row are treated as null for that column. Empty tables are represented by empty arrays.
{
"TABLE_NAME": [
{"COLUMN0": "value", "COLUMN1": "value"},
{"COLUMN0": "value"}
],
"EMPTY_TABLE": []
}
- Author:
- Jeff Jensen
-
Constructor Summary
ConstructorsConstructorDescriptionJsonProducer(File file) Creates a producer that reads from the given file.JsonProducer(InputStream inputStream) Creates a producer that reads from the given stream. -
Method Summary
Modifier and TypeMethodDescriptionvoidproduce()Process this dataset source.voidsetConsumer(IDataSetConsumer consumer) Sets the consumer notified of this producer's dataset content.
-
Constructor Details
-
JsonProducer
Creates a producer that reads from the given file.- Parameters:
file- The JSON file to read.- Throws:
IOException- If the file cannot be opened.
-
JsonProducer
Creates a producer that reads from the given stream. The stream is left open once reading completes; the caller remains responsible for closing it.- Parameters:
inputStream- The stream containing JSON dataset data.
-
-
Method Details
-
setConsumer
Description copied from interface:IDataSetProducerSets the consumer notified of this producer's dataset content.- Specified by:
setConsumerin interfaceIDataSetProducer- Parameters:
consumer- the consumer to notify.
-
produce
Description copied from interface:IDataSetProducerProcess this dataset source. During the processing, the IDataSetProducer will provide information about the dataset through the specified event listener.This method is synchronous: it will not return until processing has ended. If a client application wants to terminate parsing early, it should throw an exception from the listener.
- Specified by:
producein interfaceIDataSetProducer- Throws:
DataSetException- if processing the dataset source fails.
-