-
-
Notifications
You must be signed in to change notification settings - Fork 2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
datatable-java: Empty cell are not converted to null
's for String
class
#1617
Comments
This should be fixed with a PR against cucumber/datatable. To remain consistent the empty string should always be converted to null (so also for strings) and doing this would be a breaking change. Meaning this would have to be picked up with v5. |
For the the time being fixing this for all types but String would be good too. |
@mpkorstanje , sorry for asking, but where I can find some information about how to build datatable project in monorepo? |
Try running |
Thanks! That was easy. |
Data table version still needs to be updated. |
And then we have to wait for 5.0.0 to make the empty String convert to null. |
null
's for Double
classnull
's for String
class
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. |
@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 data table cells can either be considered null or empty strings. For example table below can converted to a map as `{name=Aspiring Author, first publication=}` or `{name=Aspiring Author, first publication=null}`. ```gherkin | name | first publication | | Aspiring Author | | ``` And as demonstrated #1617 there are good reasons to default the empty table cell to null. However this does not cover all cases. There are however good use cases to use the empty string. By declaring a table transformer with a replacement string it becomes possible to explicitly disambiguate between the two scenarios. For example: ```gherkin Given some authors | name | first publication | | Aspiring Author | | | Ancient Author | [blank] | ``` ```java @DataTableType(replaceWithEmptyString = "[blank]") public Author convert(Map<String, String> entry){ return new Author( entry.get("name"), entry.get("first publication") ); } @given("some authors") public void given_some_authors(List<Author> authors){ // authors = [Author(name="Aspiring Author", firstPublication=), Author(name="Ancient Author", firstPublication=null)] } ```
Empty data table cells can either be considered null or empty strings. For example table below can converted to a map as `{name=Aspiring Author, first publication=}` or `{name=Aspiring Author, first publication=null}`. ```gherkin | name | first publication | | Aspiring Author | | ``` And as demonstrated #1617 there are good reasons to default the empty table cell to null. However this does not cover all cases. There are however good use cases to use the empty string. By declaring a table transformer with a replacement string it becomes possible to explicitly disambiguate between the two scenarios. For example: ```gherkin Given some authors | name | first publication | | Aspiring Author | | | Ancient Author | [blank] | ``` ```java @DataTableType(replaceWithEmptyString = "[blank]") public Author convert(Map<String, String> entry){ return new Author( entry.get("name"), entry.get("first publication") ); } @given("some authors") public void given_some_authors(List<Author> authors){ // authors = [Author(name="Aspiring Author", firstPublication=null), Author(name="Ancient Author", firstPublication=)] } ```
Empty data table cells can either be considered null or empty strings. For example table below can converted to a map as `{name=Aspiring Author, first publication=}` or `{name=Aspiring Author, first publication=null}`. ```gherkin | name | first publication | | Aspiring Author | | ``` And as demonstrated #1617 there are good reasons to default the empty table cell to null. However this does not cover all cases. There are however good use cases to use the empty string. By declaring a table transformer with a replacement string it becomes possible to explicitly disambiguate between the two scenarios. For example: ```gherkin Given some authors | name | first publication | | Aspiring Author | | | Ancient Author | [blank] | ``` ```java @DataTableType(replaceWithEmptyString = "[blank]") public Author convert(Map<String, String> entry){ return new Author( entry.get("name"), entry.get("first publication") ); } @given("some authors") public void given_some_authors(List<Author> authors){ // authors = [Author(name="Aspiring Author", firstPublication=null), Author(name="Ancient Author", firstPublication=)] } ```
Empty data table cells can either be considered null or empty strings. For example table below can converted to a map as `{name=Aspiring Author, first publication=}` or `{name=Aspiring Author, first publication=null}`. ```gherkin | name | first publication | | Aspiring Author | | ``` And as demonstrated #1617 there are good reasons to default the empty table cell to null. However this does not cover all cases. There are however good use cases to use the empty string. By declaring a table transformer with a replacement string it becomes possible to explicitly disambiguate between the two scenarios. For example: ```gherkin Given some authors | name | first publication | | Aspiring Author | | | Ancient Author | [blank] | ``` ```java @DataTableType(replaceWithEmptyString = "[blank]") public Author convert(Map<String, String> entry){ return new Author( entry.get("name"), entry.get("first publication") ); } @given("some authors") public void given_some_authors(List<Author> authors){ // authors = [Author(name="Aspiring Author", firstPublication=null), Author(name="Ancient Author", firstPublication=)] } ```
Empty data table cells can either be considered null or empty strings. For example table below can converted to a map as `{name=Aspiring Author, first publication=}` or `{name=Aspiring Author, first publication=null}`. ```gherkin | name | first publication | | Aspiring Author | | ``` And as demonstrated #1617 there are good reasons to default the empty table cell to null. However this does not cover all cases. There are however good use cases to use the empty string. By declaring a table transformer with a replacement string it becomes possible to explicitly disambiguate between the two scenarios. For example: ```gherkin Given some authors | name | first publication | | Aspiring Author | | | Ancient Author | [blank] | ``` ```java @DataTableType(replaceWithEmptyString = "[blank]") public Author convert(Map<String, String> entry){ return new Author( entry.get("name"), entry.get("first publication") ); } @given("some authors") public void given_some_authors(List<Author> authors){ // authors = [Author(name="Aspiring Author", firstPublication=null), Author(name="Ancient Author", firstPublication=)] } ```
Empty data table cells can either be considered null or empty strings. For example table below can converted to a map as `{name=Aspiring Author, first publication=}` or `{name=Aspiring Author, first publication=null}`. ```gherkin | name | first publication | | Aspiring Author | | ``` And as demonstrated #1617 there are good reasons to default the empty table cell to null. However this does not cover all cases. There are however good use cases to use the empty string. By declaring a table transformer with a replacement string it becomes possible to explicitly disambiguate between the two scenarios. For example: ```gherkin Given some authors | name | first publication | | Aspiring Author | | | Ancient Author | [blank] | ``` ```java @DataTableType(replaceWithEmptyString = "[blank]") public Author convert(Map<String, String> entry){ return new Author( entry.get("name"), entry.get("first publication") ); } @given("some authors") public void given_some_authors(List<Author> authors){ // authors = [Author(name="Aspiring Author", firstPublication=null), Author(name="Ancient Author", firstPublication=)] } ```
Empty data table cells can either be considered null or empty strings. For example table below can converted to a map as `{name=Aspiring Author, first publication=}` or `{name=Aspiring Author, first publication=null}`. ```gherkin | name | first publication | | Aspiring Author | | ``` And as demonstrated #1617 there are good reasons to default the empty table cell to null. However this does not cover all cases. There are however good use cases to use the empty string. By declaring a table transformer with a replacement string it becomes possible to explicitly disambiguate between the two scenarios. For example: ```gherkin Given some authors | name | first publication | | Aspiring Author | | | Ancient Author | [blank] | ``` ```java @DataTableType(replaceWithEmptyString = "[blank]") public Author convert(Map<String, String> entry){ return new Author( entry.get("name"), entry.get("first publication") ); } @given("some authors") public void given_some_authors(List<Author> authors){ // authors = [Author(name="Aspiring Author", firstPublication=null), Author(name="Ancient Author", firstPublication=)] } ```
Empty data table cells can either be considered null or empty strings. For example table below can converted to a map as `{name=Aspiring Author, first publication=}` or `{name=Aspiring Author, first publication=null}`. ```gherkin | name | first publication | | Aspiring Author | | ``` And as demonstrated #1617 there are good reasons to default the empty table cell to null. However this does not cover all cases. There are however good use cases to use the empty string. By declaring a table transformer with a replacement string it becomes possible to explicitly disambiguate between the two scenarios. For example: ```gherkin Given some authors | name | first publication | | Aspiring Author | | | Ancient Author | [blank] | ``` ```java @DataTableType(replaceWithEmptyString = "[blank]") public Author convert(Map<String, String> entry){ return new Author( entry.get("name"), entry.get("first publication") ); } @given("some authors") public void given_some_authors(List<Author> authors){ // authors = [Author(name="Aspiring Author", firstPublication=null), Author(name="Ancient Author", firstPublication=)] } ```
Summary
The empty cell is not converted to
(Double)null
in Cucumber 4.3.0, as it happened in Cucumber 1.2.5In Cucumber 1.2.5 empty cell was converted to null of type
Double
, when performingasMap(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 newDataTableType
definition results inio.cucumber.datatable.DublicateTypeException
.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 stepis transformed to
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 transformContext & 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
The text was updated successfully, but these errors were encountered: