question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

datatable-java: Empty cell are not converted to `null`'s for `String` class

See original GitHub issue

Summary

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)

  1. 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 |

  2. 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); }

  3. 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:closed
  • Created 4 years ago
  • Comments:9 (6 by maintainers)

github_iconTop GitHub Comments

1reaction
mpkorstanjecommented, Jan 9, 2020

@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 "".

0reactions
hsynkrtlcommented, Nov 4, 2019

how can i now pass an empty string to a datatable.

  | street | houseNumber | city         | zip | country | state | type            |
  |      |           | Trololotown2 |     | AZ           | WY    | ADDRESS |

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.

Read more comments on GitHub >

github_iconTop Results From Across the Web

datatable-java: Empty cell are not converted to null 's for String ...
Possible Solution. Convert empty cells to null values, or allow to override default build-in type transformations. Steps to Reproduce (for bugs).
Read more >
datatable-java: Empty cell are not converted to `null`'s for `String` class
Possible Solution. Convert empty cells to null values, or allow to override default build-in type transformations. ... Context & Motivation. It could be...
Read more >
Pass empty string to cucumber DataTable - java - Stack Overflow
Since v5.0.0 empty cells in a data table are into null values rather than the empty string. By using replaceWithEmptyString = "[blank]" on...
Read more >
Using data table types in Cucumber-JVM - On Test Automation
However, Cucumber-JVM by default interprets empty cells as null values, not as empty strings.
Read more >
Null Values - Azure Data Explorer | Microsoft Learn
Because the string type doesn't support null values, it's recommended to use the isempty() and the isnotempty() functions.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found