You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When mapping an enum to an enum of the same class, the AnyToEnumConverter is found as a suitable converter.
When AnyToEnumConverter.doConvert kicks in for converting an enum to its own instance, it takes the toString() value of the enum and then applies that value to a valueOf.
When the enum class has a toString method, this conversion will fail.
The doConvert always does the conversion, even if both sides are of the same class type.
Suggestion solution
Make sure the source class is checked against the targetClass. When they are the same immediately return the source and abandon the conversion process.
The text was updated successfully, but these errors were encountered:
When performing a conversion from an enum to the same enum, the
AnyToEnumConverter is triggered, which performs a full cycle conversion,
using the toString() method of source and the valueOf() of the target
enum.
When the source enum is the same as the target enum and the source enum
has an overridden toString() method, this fails because the value can
not be mapped to the enum.
Instead, the AnyToEnumConverter now checks whether the source is of the
same enum class as the target. If this is the case, the conversion task
is skipped and the source is returned literally.
Problem
When mapping an enum to an enum of the same class, the
AnyToEnumConverter
is found as a suitable converter.When
AnyToEnumConverter.doConvert
kicks in for converting an enum to its own instance, it takes the toString() value of the enum and then applies that value to avalueOf
.When the enum class has a
toString
method, this conversion will fail.Diagnosis
See:
The
doConvert
always does the conversion, even if both sides are of the same class type.Suggestion solution
Make sure the source class is checked against the targetClass. When they are the same immediately return the source and abandon the conversion process.
The text was updated successfully, but these errors were encountered: