Package org.dbunit.dataset.json
Class JsonDataSet
java.lang.Object
org.dbunit.dataset.AbstractDataSet
org.dbunit.dataset.CachedDataSet
org.dbunit.dataset.json.JsonDataSet
- All Implemented Interfaces:
IDataSet,IDataSetConsumer
Reads and writes flat JSON-based dataset documents.
Contrary to the flat XML layout, columns are calculated by parsing the entire dataset, not
just the first row. Each table is a top-level key in the JSON object, and its value is an array
of row objects. Columns with null values are omitted from the JSON representation.
Example:
{
"TEST_TABLE": [
{"COL0": "row 0 col 0", "COL1": "row 0 col 1"},
{"COL0": "row 1 col 0"}
],
"EMPTY_TABLE": []
}
- Author:
- Jeff Jensen
-
Field Summary
Fields inherited from class org.dbunit.dataset.AbstractDataSet
_orderedTableNameMap -
Constructor Summary
ConstructorsConstructorDescriptionJsonDataSet(File file) Creates a JSON dataset from the given file.JsonDataSet(InputStream inputStream) Creates a JSON dataset from the given input stream. -
Method Summary
Modifier and TypeMethodDescriptionstatic voidwrite(IDataSet dataSet, OutputStream out) Writes the specified dataset to the given output stream as JSON, encoded in UTF-8, matching whatJsonProducerdecodes.static voidWrites the specified dataset to the given writer as JSON.Methods inherited from class org.dbunit.dataset.CachedDataSet
createIterator, endDataSet, endTable, row, startDataSet, startTableMethods inherited from class org.dbunit.dataset.AbstractDataSet
createTableNameMap, getTable, getTableMetaData, getTableNames, getTables, initialize, isCaseSensitiveTableNames, iterator, reverseIterator, toString
-
Constructor Details
-
JsonDataSet
Creates a JSON dataset from the given file.- Parameters:
file- The JSON file to read.- Throws:
IOException- If the file cannot be opened.DataSetException- If the JSON content cannot be parsed as a dataset.
-
JsonDataSet
Creates a JSON dataset from the given input stream. The stream is left open once reading completes; the caller remains responsible for closing it.- Parameters:
inputStream- The stream containing JSON dataset data.- Throws:
DataSetException- If the JSON content cannot be parsed as a dataset.
-
-
Method Details
-
write
Writes the specified dataset to the given output stream as JSON, encoded in UTF-8, matching whatJsonProducerdecodes.- Parameters:
dataSet- The dataset to write.out- The stream to write to.- Throws:
DataSetException- If the dataset cannot be serialized.
-
write
Writes the specified dataset to the given writer as JSON.- Parameters:
dataSet- The dataset to write.out- The writer to write to.- Throws:
DataSetException- If the dataset cannot be serialized.
-