POJO with nullable enum fields support in tables #684
Closed
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
The issue I encountered is that there is no way to omit specifying enum value when this enum is a part of the POJO.
The reason for that is that the xstream's EnumConverter doesn't check for null or empty string before asking for
valueOf()
. Cucumber has it's own implementation (ConverterWithEnumFormat) which does handle nulls and empty strings in the expected way, and on top of this allows user to be more flexible in specifying enum value (upper-case, lower-case, capitalised). Unfortunately, this custom enum converter is not used when converting to POJOs.The solution I suggest via this PR is to register a new DynamicEnumConverter class which would in turn instantiate needed ConverterWithEnumFormat based on the enum class expectations. The PR also contains a fix for a small defect in the ConverterWithEnumFormat where an enum value of mixed case which starts with lowercase letter would not be supported by any of the formats.
I haven't updated the change log as see this change as pretty minor. Please let me know if this is not the case.
Potential regression: the original XStream's EnumConverter has a special support for "polymorphic enums" which is missing from the proposed implementation. Due to lack of knowledge, I could not reproduce the case by tests, so leaving a simple implementation for now.