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
ciscoo
changed the title
Unable to bind properties to EnumMap due to unknown key type
Unable to bind properties to EnumMap due to missing key type
Jul 18, 2024
wilkinsona
changed the title
Unable to bind properties to EnumMap due to missing key type
Constructor binding of EnumMap fails due to missing key type
Jul 18, 2024
Thanks for the report. There are two similar problems here. One's in ValueObjectBinder to which you've linked, but it will only occur if the EnumMap record component or constructor parameter is annotated with @DefaultValue. The other is in MapBinder.bindAggregate(ConfigurationPropertyName, Bindable<?>, AggregateElementBinder). I think it's the latter that's causing the failure in your case. Regardless, both need to be updated to handle an EnumMap by providing the key type to CollectionFactory.
Uh oh!
There was an error while loading. Please reload this page.
Given the following:
and configuration:
Will result in the following exception:
It works if I switch to
Map
instead ofEnumMap
:But the keys (for my use case) are enums and it makes sense to use the specialized map implementation.
After some debugging, it looks to be an issue on Boot's side in
ValueObjectBinder
:spring-boot/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/context/properties/bind/ValueObjectBinder.java
Line 160 in 3648f5f
The key portion is lost which then fails Framework's check:
https://github.com/spring-projects/spring-framework/blob/5715b2a783b383c7cae214c2e37efb43f48d924f/spring-core/src/main/java/org/springframework/core/CollectionFactory.java#L319
Additionally, maybe related: #19156
The text was updated successfully, but these errors were encountered: