Skip to content

Binding to @ConfigurationProperties with a Map does not preserve the order of keys #2487

@dsyer

Description

@dsyer

Binding to @ConfigurationProperties with a Map does not preserve the order of keys, even though the order is carefully preserved in YamlPropertySourceLoader. The culprit is PropertySourcesPropertyValues which has an unordered map of name-value pairs. Example:

    @Component
    @EnableConfigurationProperties
    @ConfigurationProperties("foo")
    public static class Foo {
        private Map<String,Bar> bar = new LinkedHashMap<String, Bar>();
        public Map<String, Bar> getBar() {
            return bar;
        }
        public void setBar(Map<String, Bar> bar) {
            this.bar = bar;
        }
        public static class Bar {
            private String name;

            public String getName() {
                return name;
            }

            public void setName(String name) {
                this.name = name;
            }
        }
    }
foo:
  bar:
    one:
      name: uno
    two:
      name: due
    three:
      name: trei
    four:
      name: quattro
    five:
      name: cinque

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions