sksamuel / hoplite

A boilerplate-free Kotlin config library for loading configuration files as data classes
Apache License 2.0
922 stars 74 forks source link

LinkedHashMap keys are not denormalized #456

Open mdii opened 1 week ago

mdii commented 1 week ago

Since 2.8.x LinkedHashMap keys are not denormalized, so all the keys are converted to lowercase. This breaks our application. If we use Map instead of LinkedHashMap the keys are denormalized correctly. We are using two yaml file sources.

This test fails:

class DenormalizedLinkedHashMapKeysTest : FunSpec({
  data class Foo(
    val xVal: String = "x"
  )

  data class LinkedHashMapContainer(
    val m: LinkedHashMap<String, Foo> = linkedMapOf()
  )

  test("should set denormalized map keys and decode a data class inside a linked hash map") {
    val config = ConfigLoaderBuilder.default()
      .addResourceOrFileSource("/test_data_class_in_map.yaml")
      .build()
      .loadConfigOrThrow<LinkedHashMapContainer>()

    config shouldBe LinkedHashMapContainer(
      m = linkedMapOf(
        "DC1" to Foo("10"),
        "DC2" to Foo("20"),
      )
    )
  }
})