Jackson plugin
Overview
The Jackson plugin supports reading a (JSON, XML or CSV) file and converting the data to an object.
- Technologies addressed
- Dependency
-
io.qalipsis.plugin:qalipsis-plugin-jackson - Namespace in scenario
-
jackson() - Client library
-
JsonMapper: refer to FasterXML.
Supported steps
csvToMap and csvToObject
The csvToMap step reads a CSV resource (file, classpath resource, or URL) and returns each row as a Map keyed by column name. The csvToObject step reads the same resource and deserializes each row directly into a typed object.
- Ancestor
-
Step
- Functionality
-
The
csvToMapstep converts each CSV row to aMapand pushes it to the next step.
ThecsvToObjectstep maps each CSV row to an instance of the specified target class and pushes it to the next step. - Example(csvToMap)
-
+
jackson().csvToMap {
classpath("battery-levels.csv")
escapeChar('E')
quoteChar('"')
columnSeparator(';')
withHeader()
allowComments()
header {
column("1st value").double()
column("2nd value").string().array(",")
column("3rd value").string(true)
column("4th value").string(true)
}
}
- Example (csvToObject)
jackson()
.csvToObject(BatteryState::class) {
classpath("battery-levels.csv")
header {
column("deviceId")
column("timestamp")
column("batteryLevel").integer()
}
unicast()
}
- Tip
-
Only one path (
classpath(path),file(path), orurl(url)) to the resource is allowed for eachcsvToObjectorcsvToMapstep.
csvToList
The csvToList step within the Jackson plugin reads a CSV resource (classpath, file, or url) and returns each item as a List of values, preserving column order. Use csvToList when a positional list of values per row is preferred over a Map or a typed object.
- Ancestor
-
Step
- Functionality
-
The
csvToListstep converts each CSV row to a list and pushes that list to the next step.
Rows are converted as:
* List<String>: Each row emitted with no header parsing.
* List<Any>: Each row emitted with parsed types in the configured column order; a header block is provided to define column types and parsing behavior.
- Example (
List<String>) -
jackson().csvToList { classpath("battery-levels.csv") } - Example (
List<Any>)
jackson().csvToList {
file("/data/measurements.csv")
header {
withHeader()
column("deviceId").string()
column("batteryLevel").integer()
column("timestamp").long()
}
broadcast()
}
- Reference documentation
-
Refer to the jackson documentation for further configuration and parameter information.
xmlToObject
The xmlToObject step within the Jackson plugin reads an XML resource (classpath, file, or url) and returns each item as an instance of an object of the specified class.
- Ancestor
-
Step
- Functionality
-
The
xmlToObjectstep specification has atargetClassproperty to which the output lines should be mapped. The step reads an XML file, converts the data to anObject, and pushes theObjectto the next step. - Example
-
jackson().xmlToObject(PojoForTest::class) { classpath("data.xml") } - Tip
-
Only one path (
classpath(path),file(path), orurl(url)) to the resource is allowed for eachxmlToObjectstep. - Reference documentation
-
Refer to the jackson documentation for further configuration and parameter information.
jsonToMap and jsonToObject
The jsonToMap step reads a JSON resource (file, classpath resource, or URL) and returns each element as a Map. The jsonToObject step reads the same resource and deserializes each element directly into a typed object.
- Ancestor
-
Step
- Functionality
-
The
jsonToMapstep converts each JSON element to aMapand pushes it to the next step.
ThejsonToObjectstep maps each JSON element to an instance of the specified target class and pushes it to the next step. - Example
-
jackson().jsonToMap() { classpath("data.json") } jackson().jsonToObject(PojoForTest::class) { classpath("data.json") } - Tip
-
Only one path (
classpath(path),file(path), orurl(url)) to the resource is allowed for eachjsonToObjectorjsonToMapstep. - Reference documentation
-
Refer to the jackson documentation for further configuration and parameter information.
Configuration
DSL parameters
Available parameters are described in the table below.
| Parameter | Description |
|---|---|
|
Reads the data from a specified class path resource; Example
|
|
Reads the data from a specified plain file in the file system; Example
|
|
Reads the data from a specified remote web resource. Example
|
|
Sets the character encoding used to open the Example
|
|
Sets the character used to split columns in a CSV row. Example
|
|
Sets the character used to quote cell values that contain the column separator or line separator, preventing them from being split. Example
|
|
Sets the character used to escape special characters inside a cell value so they are not interpreted as delimiters. Example
|
|
Sets the line separator used to split rows. Accepts either a Example
|
|
When called, any line whose first non-whitespace character is Example
|
|
Configures the column structure of the CSV file. The lambda receiver is Example
|
|
Declares that the first non-skipped line of the CSV file is the header row. Its cell values become the keys of the output map (for Example
|
|
Skips the first data row after the header. Use this when an external tool adds a units row or summary row immediately after the header line. Must be called inside Example
|
|
Registers a column by name (appended in declaration order) or by explicit 0-based index and name. Returns a Example
|
|
Tweaks the Example (JSON)
Example (XML)
|