datatable-java: Empty cell are not converted to `null`'s for `String` class
See original GitHub issueSummary
The empty cell is not converted to (Double)null
in Cucumber 4.3.0, as it happened in Cucumber 1.2.5
In Cucumber 1.2.5 empty cell was converted to null of type Double
, when performing asMap(String,Double)
table conversion. This no longer happens in Cucumber 4.3.0. I also couldn’t find the way to override this behavior because just adding new DataTableType
definition results in io.cucumber.datatable.DublicateTypeException
.
typeRegistry.defineDataTableType(
new DataTableType(
Double.class,
(TableCellTransformer<Double>) value ->
(!value.isEmpty()) ? (Double.parseDouble(value)) : (null)));
Expected Behavior
Empty cell is converted to null
by default for nullable number types (Double
, Float
, Int
etc.). So that the table in the following step
Then the marker values are
| M1 | 1.7988 |
| M2 | |
| M3 | 1.5312 |
| M4 | 1.7720 |
| M5 | 1.6840 |
| M6 | 0.0000 |
| M9 | |
| M12 | 1.7002 |
is transformed to
{
"M1": 1.7988,
"M2": null,
"M3": 1.5312,
"M4": 1.7720,
"M5": 1.6840,
"M6": 0.0,
"M9": null,
"M12": 1.7002,
}
Current Behavior
Exception is thrown: io.cucumber.datatable.CucumberDataTableException: ‘java.util.List<java.util.List<java.lang.Double>>’ could not transform
Possible Solution
Convert empty cells to null values, or allow to override default build-in type transformations.
Steps to Reproduce (for bugs)
-
The table in the following step:
Then the marker values are
| M1 | 1.7988 | | M2 | | | M3 | 1.5312 | | M4 | 1.7720 | | M5 | 1.6840 | | M6 | 0.0000 | | M9 | | | M12 | 1.7002 |
-
Is trasformed to a
Map
@Then(“Then the marker values are”) public void theMarkerValuesAre(DataTable expectedValues) { Map<String, Double> expected = expectedValues.asMap(String.class, Double.class); }
-
CucumberDataTableException
is thrown with message: ‘java.util.List<java.util.List<java.lang.Double>>’ could not transform
Context & Motivation
It could be useful to represent the clearing of the input value in the form where user can enter/update several similar values in one go.
Your Environment
- Version used: 4.3.0
- Operating System and version: Windows 10
- Link to your project: N/A
Issue Analytics
- State:
- Created 4 years ago
- Comments:9 (6 by maintainers)
Top GitHub Comments
@hsynkrtl you’re replying to a closed issue which means that chances of anybody reading this are absolutely terrible. I happened to see this by sheer chance.
I would suggest that you make empty strings explicit by using the text
[empty]
and then prior to converting the entry to an object replace the"[empty]"
strings with""
.how can i now pass an empty string to a datatable.
with the last update of datatable street and housNumber get [null] instead of an empty string “” which is valid for a string value to be empty.