cucumber-jvm icon indicating copy to clipboard operation
cucumber-jvm copied to clipboard

Add a built in table cell converter that supports Enums

Open mpkorstanje opened this issue 5 years ago • 7 comments

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.

mpkorstanje avatar Mar 19 '20 16:03 mpkorstanje

Is it should be added to the monorepo? https://github.com/cucumber/cucumber/tree/master/datatable/java/datatable/src/main/java/io/cucumber/datatable

rasklaad avatar Mar 20 '20 07:03 rasklaad

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.

mpkorstanje avatar Mar 20 '20 09:03 mpkorstanje

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

rasklaad avatar Mar 23 '20 10:03 rasklaad

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

mpkorstanje avatar Mar 23 '20 13:03 mpkorstanje

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?

mpkorstanje avatar Sep 26 '20 22:09 mpkorstanje

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.

mpkorstanje avatar Sep 27 '20 11:09 mpkorstanje

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.

stale[bot] avatar Apr 14 '23 08:04 stale[bot]