Reputation: 945
I have two classes
class MyType {
private MyInnerType myInnerType;
private String name;
private Integer number;
}
class MyInnerType {
private String subTypeName;
private String id;
}
These two classes are used in a cucumber test which has Step definition:
@Given("^the system has types$")
public void types(List<MyType> myTypeList) {
....
}
The clause is defined with a data table:
| subTypeName | id | name | number |
| abc | 1 | tom | 1000 |
| def | 2 | jerry | 2000 |
| ghi | 3 | jack | 3000 |
This definition works fine using Cucumber 1. It looks like the type conversion and inner type conversion are done automatically.
After this code is migrated to cucumber 4, I started to getting error like this:
Caused by: io.cucumber.datatable.CucumberDataTableException: 'java.util.List<com.mycompany.MyType>' could not transform
I did some google search. The obvious answer is to register type transformer for MyType and MyInnerType. This sounds to me like a very useful feature was removed for a newer version.
Can I still use cucumber 4 with automatic resolution without using type transformer?
Upvotes: 0
Views: 416
Reputation: 12029
This sounds to me like a very useful feature was removed for a newer version.
From: https://cucumber.io/blog/announcing-cucumber-jvm-3-0-0/
Cucumber 1.x and 2.x used a library called XStream as a central building block for data tables conversion. However the usage of XStream in combination with Cucumber was poorly documented and it did not allow for the use of other Object Mappers (e.g. Jackson) which made it impossible to reuse domain objects. As XStream is not compatible with Java 9 it was also problem in long term.
--
Can I still use cucumber 4 with automatic resolution without using type transformer?
You can choose an object mapper framework (Jackson, XStream, Gson, ect) and install that as the default data table transformer. This will handle most use cases.
See: https://cucumber.io/blog/announcing-cucumber-jvm-4-0-0/
Though I don't believe there are any object mapper frameworks that can convert a map to a nested structure. You'll have to find a different solution there.
Upvotes: 2