Escaping a dot in a Map key in Yaml in Spring Boot
Interview Questions practice on Codemia
Over 8,000 real interview questions from top companies, searchable by company and role.
Introduction
In Spring Boot configuration binding, dots in property names usually represent nested paths. That can become a problem when the dot is part of an actual map key, such as a domain name or file extension rule. The fix is to use bracket notation with quoted keys so the binder treats the full key as literal text.
Why Dots Break Map Binding
Spring Boot property binding interprets a key like settings.api.timeout as nested objects. If your intended map key is api.timeout, you need to stop path splitting and preserve that exact string.
Consider this YAML:
Depending on your target type, this may not bind as expected to a flat map key. Bracket notation is safer for literal keys.
Correct YAML Pattern for Dot Keys
Use quoted bracket keys under the map field.
Then bind to a map in your configuration class.
With this pattern, keys remain exactly as written.
Verify Binding in a Test
A focused test prevents surprises during upgrades.
This is especially useful when configuration is loaded from several profile files.
Alternative Using properties Files
If your team prefers application.properties, map key preservation is often simpler to read:
The same binding class works with this format.
Work with Nested Maps and Typed Values
Literal dot keys are common when loading per host settings or extension based rules. If you need more structure than a string-to-string map, bind to nested map values and keep bracket notation for the outer key.
This pattern gives type safety while preserving exact map key text.
Environment Overrides and Key Names
Environment variable overrides flatten key names and can become hard to read for dotted map keys. In teams that depend on environment overrides, prefer loading values from profile specific files or config maps instead of trying to encode complex key syntax in environment variable names.
Common Pitfalls
A common mistake is using plain dotted keys in YAML and expecting literal key storage. Spring may parse them as nested fields.
Another issue is forgetting to quote bracket notation in YAML. Unquoted syntax can be parsed differently by YAML processors.
A third issue is mixing styles across profile files, which produces inconsistent maps across environments. Pick one style and use it everywhere.
Summary
- Dots in configuration keys are treated as path separators by default.
- Use quoted bracket notation for literal map keys with dots.
- Bind to a string keyed map in a
@ConfigurationPropertiesclass. - Add tests that assert key exactness across profiles.
- Keep one consistent format across YAML and properties files.
Related reading
- ETL in Java Spring Batch vs Apache Spark Benchmarking
- Even though JRE 8 is installed on my MAC - No Java Runtime present,requesting to install gets displayed in terminal
- EventListener with Async in Spring
- Example of Mockito's argumentCaptor
- Examples of GoF Design Patterns in Java's core libraries
- Exception handling in StreamingResponseBody
- Exception in thread main java.lang.UnsatisfiedLinkError Cannot find TensorFlow native library for OS linux, architecture x86_64
- Exception message not included in response when throwing ResponseStatusException in Spring Boot

OOD Fundamentals
Master object-oriented design from first principles, SOLID, design patterns, and classic interview problems with hands-on coding.
View the courseTrack what you have practised
A free account saves your progress, solutions and study plan across every problem on Codemia.
Interview Questions practice on Codemia
Over 8,000 real interview questions from top companies, searchable by company and role.