Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Smallrye Configuration missreading nested maps #25922

Closed
joao-v-fonseca-alb opened this issue Jun 2, 2022 · 2 comments
Closed

Smallrye Configuration missreading nested maps #25922

joao-v-fonseca-alb opened this issue Jun 2, 2022 · 2 comments
Assignees
Labels

Comments

@joao-v-fonseca-alb
Copy link

joao-v-fonseca-alb commented Jun 2, 2022

Describe the bug

When dealing with nested maps, Smallrye config is setting all keys as the key for the topmost map.

for an application.yml map:

key1:
  key2:
    key3: value

the config will read it as:

key3:
  key3:
    key3: value

Expected behavior

When reading nested maps, the keys must match what is on the aplication.yml.

Actual behavior

When reading nested maps, the keys are all set as the key of the topmost map.

How to Reproduce?

package com.example;

import io.smallrye.config.ConfigMapping;

import java.util.Map;

@ConfigMapping(prefix = "reproducer")
public interface Config {

    Map<String, Map<String, Map<String, String>>> triple();

    Map<String, Map<String, String>> dual();

}
package com.example;

import io.quarkus.test.junit.QuarkusTest;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;

import javax.inject.Inject;

import static org.junit.jupiter.api.Assertions.*;


@QuarkusTest
class ConfigTest {

    @Inject
    Config config;

    @Test
    void triple() {
        var key1 = config.triple().keySet().toArray()[0];
        var key2 = config.triple().get(key1).keySet().toArray()[0];
        var key3 = config.triple().get(key1).get(key2).keySet().toArray()[0];
        var value = config.triple().get(key1).get(key2).get(key3);

        Assertions.assertAll(
                () -> assertEquals("key1", key1, "First map"),
                () -> assertEquals("key2", key2, "Second map"),
                () -> assertEquals("key3", key3, "Third map"),
                () -> assertEquals("value", value, "value")
        );
    }

    @Test
    void dual() {
        var key1 = config.dual().keySet().toArray()[0];
        var key2 = config.dual().get(key1).keySet().toArray()[0];
        var value = config.dual().get(key1).get(key2);

        Assertions.assertAll(
                () -> assertEquals("key1", key1, "First map"),
                () -> assertEquals("key2", key2, "Second map"),
                () -> assertEquals("value", value, "value")
        );
    }
}

Application.yml

reproducer:
  dual:
    key1:
      key2: value

  triple:
    key1:
      key2:
        key3: value

Output of uname -a or ver

Linux 5.13.0-41-generic #46~20.04.1-Ubuntu SMP Wed Apr 20 13:16:21 UTC 2022 x86_64 x86_64 x86_64 GNU/Linux

Output of java -version

openjdk version "11.0.15" 2022-04-19

GraalVM version (if different from Java)

No response

Quarkus version or git rev

2.9.2.Final

Build tool (ie. output of mvnw --version or gradlew --version)

Apache Maven 3.8.4 (9b656c72d54e5bacbed989b64718c159fe39b537)

Additional information

This bug did not exist on version 2.5.x

@joao-v-fonseca-alb joao-v-fonseca-alb added the kind/bug Something isn't working label Jun 2, 2022
@quarkus-bot
Copy link

quarkus-bot bot commented Jun 2, 2022

@radcortez radcortez self-assigned this Jun 13, 2022
@radcortez
Copy link
Member

Duplicate of #26009.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants