DataTable - Automatic conversion to custom type stopped working
See original GitHub issueSummary
After updating cucumber-testng
(and subsequently all transient dependencies) from 2.4.0
to 3.0.2
in pom.xml
, automatic conversion for datatables using custom types stopped working and now throws UndefinedDataTableTypeException
.
Expected Behavior
Only change required is to update imports to import io.cucumber.datatable.DataTable;
and tests to run as per usual.
Current Behavior
Getting this exception from steps that worked prior to update:
io.cucumber.datatable.UndefinedDataTableTypeException: Can’t convert DataTable to List<jcucumberng.steps.pojos.Income>. Please register a DataTableType with a TableEntryTransformer or TableRowTransformer for class jcucumberng.steps.pojos.Income
// Feature
When I Enter My Regular Income Sources
| name | amount | frequency |
| Salary | 25000 | every 2 weeks |
// Stepdef
@When("^I Enter My Regular Income Sources$")
public void I_Enter_My_Regular_Income_Sources(DataTable dataTable) throws Throwable {
List<Income> incomes = dataTable.asList(Income.class);
// More code
}
// Custom type
public class Income {
private String name = null;
private String amount = null;
private String frequency = null;
public Income(String name, String amount, String frequency) {
this.name = name;
this.amount = amount;
this.frequency = frequency;
}
// Getters and setters
}
Possible Solution
Show more useful comments/javadocs for DataTable specially if updating from v2.x.x to v3.x.x for major changes to its usage. Allow easier automatic conversion like before.
Context & Motivation
A revamp of the DataTable usage will break a lot of existing tests and can totally prevent people from updating to v3.x.x. It also outdates a lot of widely available tutorials and references.
Issue Analytics
- State:
- Created 5 years ago
- Reactions:5
- Comments:39 (31 by maintainers)
Top GitHub Comments
I’ve got a pending PR for this (haven’t pushed yet). I’m reopening since I plan to fix it next week.
Context: I just ran a public training where a few people remarked that while the new data tables are great, they do require more boilerplate/configuration code. I think I’ve found a pragmatic middle ground, where you’ll still need to register a
DataTableType
, but doing so will be a one-liner.You are looking for a quick fix for what exactly? The context of this issue allows for a number of problems.
To wit the default table converters receive the same information that XStream would. So if anything you can use XStream as the default converter though you may have to copy the exact configuration from Cucumbers v2.4 source to retain all features and functionality.
You can find documentation here, though I’d suggest reading the context around it too:
Do bear in mind that this is an open source project, developed primarily by volunteers and available free of charge. While it is unfortunate that you are working with professional constraints and requirements that put you in a bind they are yours to solve.