Configuration quoted and unquoted map keys #55483
radcortez
started this conversation in
Design Discussions
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
When a map key does not contain dots, it can be written in both quoted and unquoted forms:
or
Both forms are valid and equivalent for simple keys (no dots). However, when both forms are present in the configuration for the same logical key, properties from one form are silently lost:
Instead of producing one map entry with both url and timeout populated, only properties from one notation are bound. The other form's values are silently ignored, and which form wins depends on iteration order, hence our recommendation to use the same form: https://smallrye.io/smallrye-config/Latest/config/mappings/#maps.
Root Cause
There is a mismatch between how property names are compared and how map keys are extracted:
map.key.urlandmap."key".urlas two different names — quotes are only significant when the key contains dots.When building a map with a complex value type (a nested object), the code commits to one path form per key and constructs the nested object in a single pass using that path. Properties defined with the other form are never found because the property name comparison considers them different.
In many cases, extensions generate additional configurations that may not follow the user syntax (usually, we don't add quotes to single names, but the user may use them).
Comparison with Spring Boot
Spring Boot uses bracket notation (
map[key].url) instead of quotes. For simple keys, bothmap.key.urlandmap[key].urlare valid. When mixed for a complex object, Spring also binds properties from only one notation — the other is silently ignored. However, Spring's behavior is deterministic (bracket notation takes precedence), while in SmallRye Config the result depends on property name iteration order.Possible Solutions
Multiple Quarkus extensions have independently worked around this at the extension level:
Ideally, this should be fixed in SmallRye Config directly:
Unfortunately, I don't see any other solution than a fallback lookup. I've always refrained from implementing it, because it would potentially cause an explosion of lookups, as explained here: #52690 (comment).
The only other solution I see is to force the use of quotes (or even brackets) on any
Mapsegment, either simple or composed. This actually has the benefit of visually making it clear that a specific segment of a configuration is actually a user-defined name (or dynamic name).Related
All reactions