My problem with the current EnumToStringConverter
is that it doesn't put in the hands of the coder the decision on how to represent the Enum value (at least easily). It uses the .name()
instead of the .toString()
, so one cannot override it.
I have a workaround, make a custom converter and register it. Although, it can get cumbersome if I need to do this for multiple enums.
My point is, why not use the .toString()
method, by default it will use the .name()
, and if the coder wants to change it, simply overrides the .toString()
and returns whatever he wants.
Comment From: sbrannen
Hi @MarcoMartins86,
Congratulations on submitting your first issue for the Spring Framework! 👍
Regarding your proposal, the Javadoc for EnumToStringConverter
states that it "calls Enum.name()
to convert a source Enum
to a String
."
Thus, that is by design, and more importantly has always been the case.
My point is, why not use the
.toString()
method, by default it will use the.name()
, and if the coder wants to change it, simply overrides the.toString()
and returns whatever he wants.
If we were to change the behavior of EnumToStringConverter
in that regard, it would be a breaking change for any enums that override toString()
.
As you stated, it's possible to register a customer converter for applications that wish to rely on Enum#toString
instead of Enum#name
.
In light of that, we will retain the current behavior, and I'll close this issue.
Regards,
Sam