cucumber-jvm
cucumber-jvm copied to clipboard
Add a built in table cell converter that supports Enums
See:
https://stackoverflow.com/questions/60760745/is-there-a-way-to-pass-list-of-enums-to-step-in-cucumber-4-x-and-java
Cucumber expressions currently does something similar with BuiltInParameterTransformer.
Is it should be added to the monorepo? https://github.com/cucumber/cucumber/tree/master/datatable/java/datatable/src/main/java/io/cucumber/datatable
Yes. Though these features have to work end-to-end so I find it better to start ideas here.
And there is some possibility that my suggestion won't work because adding a default cell transformer creates ambiguity.
So perhaps I should phrase this request differently. Enums need some better out of the box support.
I think it shouldn't be default cell transformer, because user can replace it with his own transformer and enums transformation probably could be broken.
So we need to define one more built in transformer in DataTableTypeRegistry
Good point.
We'd have to make lookupTableTypeByType a bit smarter to handle enums.
https://github.com/cucumber/cucumber/blob/master/datatable/java/datatable/src/main/java/io/cucumber/datatable/DataTableTypeRegistry.java#L84
So the problem with defining a data type for Enum is that it wouldn't work for any enum because all enums are subclasses of Enum.
So I reckon the best way to do this would be to do something similar to https://github.com/cucumber/cucumber/pull/1182
By making the TypeFactory recognize enums we can then treat it as a special case when using lookupTableTypeByType. If the enum doens't have a custom converter registered we can create one on the fly for the particular enum.
@rasklaad would you be interested in picking this up?
On the other hand.
Unlike the other build in types and optional, there is no sensible default way to convert enums. We could use the value of Enum.name() but there are other ways to do this. Which ever solution we choose, all users would be stuck with it.
So trying to solve this with a regular data table type won't work. The regular data table types take precedence over the default table cell transformer and would make it impossible to replace them categorically. Implementing this as part of the default transformer which can be overridden would allow this.
This issue has been automatically marked as stale because it has not had recent activity. It will be closed in two months if no further activity occurs.