Skip to content

Order of map property in application yaml is no longer preserved #21470

@mengelbrecht

Description

@mengelbrecht

Scenario:
A ConfigurationProperties class contains a Map<String, String> property.
The contents of the map are specified in an application.yml file.

Expected behavior:
The order of the map entries (as specified in the yaml file) is preserved. This is the case with Spring-Boot 2.2.7.

Actual behavior:
The order of the map entries (as specified in the yaml file) is not preserved. This is the case with Spring-Boot 2.3.0.

Minimal project to reproduce:

DemoApplication.kt:

package com.example.demo

import org.springframework.beans.factory.annotation.Autowired
import org.springframework.boot.autoconfigure.SpringBootApplication
import org.springframework.boot.context.properties.ConfigurationProperties
import org.springframework.boot.context.properties.ConfigurationPropertiesScan
import org.springframework.boot.context.properties.ConstructorBinding
import org.springframework.boot.runApplication
import javax.annotation.PostConstruct

@ConfigurationProperties("test")
@ConstructorBinding
class Properties(
    val map: Map<String, String>
)

@SpringBootApplication
@ConfigurationPropertiesScan
class DemoApplication {
    @Autowired
    private lateinit var properties: Properties

    @PostConstruct
    fun postInit() {
        println(properties.map.toString())
    }
}

fun main(args: Array<String>) {
    runApplication<DemoApplication>(*args)
}

application.yml:

test:
  map:
    foo: foo
    baz: baz
    bar: bar

Spring-Boot 2.2.7 prints: {foo=foo, baz=baz, bar=bar}
Spring-Boot 2.3.0 prints: {baz=baz, bar=bar, foo=foo}

Demo Project: demo.zip

Metadata

Metadata

Assignees

Labels

type: regressionA regression from a previous release

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions