quarkusio / quarkus

Quarkus: Supersonic Subatomic Java.
https://quarkus.io
Apache License 2.0
13.72k stars 2.66k forks source link

ConfigMapping with generic child objects from dependencies not working #43934

Open JM92103 opened 1 hour ago

JM92103 commented 1 hour ago

Describe the bug

I have created an external library which defines an Interface as below which is expected to be implemented by different enum classes.

public interface ErrorCode {
    String code();
    String description();
    SeverityResult severity();
    Map<String, Object> additionalProperties();
}

I then have another Interface which defines my configuration object that will be used in my Quarkus Project. It defines T as an Enum which implements the interface above.

public interface RuleConfiguration<T extends Enum<T> & ErrorCode> {
    T exceptionCode();
    String name();
    String description();
    Integer ruleOrder();
    Boolean continueOnFailure();
    Map<String, Object> additionalProperties();
}

I am currently implementing my library into my project, but I am getting various errors around configuration mapping. I have defined the configuration. My implementation of the ErrorCode is below.

public enum TestExceptionCode implements ErrorCode {
    ERROR_ONE("Error1", "Test Exception Code",
            SeverityResult.REJECT, Map.of(VALIDATION_LEVEL, ValidationLevel.NONE, TAG, Tag.of(ApplicationMetrics.TYPE, "MF001")));

    private final String code;
    private final String description;
    private final SeverityResult severityResult;
    private final Map<String, Object> additionalProperties;

    TestExceptionCode(final String code, final String description, final SeverityResult severityResult, final Map<String, Object> additionalProperties) {
        this.code = code;
        this.description = description;
        this.severityResult = severityResult;
        this.additionalProperties = additionalProperties;
    }

    @Override
    public String code() {
        return this.code;
    }

    @Override
    public String description() {
        return this.description;
    }

    @Override
    public SeverityResult severity() {
        return this.severityResult;
    }

    @Override
    public Map<String, Object> additionalProperties() {
        return this.additionalProperties;
    }
}

And then I have a configuration Interface that is defined as

@ConfigMapping(prefix = "validation.rules.test")
public interface TestConfiguration {
    RuleConfiguration<TestExceptionCode> testErrorOne();
}

And configuration in YAML format as below

validation:
  rules:
    test:
      test-error-one:
        name: Test Error One
        description: A Friendly Description
        rule-order: 0
        continue-on-failure: true
        additional-properties:
          property-one:
            - LGIM_TCS
          property-two:
            - NONE
        exception-code: ERROR_ONE

Now once I run the application, I am getting the below errors related to the Configuration java.lang.IllegalArgumentException: SRCFG00013: No Converter registered for interface com.lgim.configuration.RuleConfiguration

Expected behavior

I expect the Configuration to map to my object

Actual behavior

Configuration fails to map and produces an error

How to Reproduce?

Steps above should be enough to reproduce. If it isn't enough I will try and find some time to create a reproducer

Output of uname -a or ver

Linux LG39016415 5.15.153.1-microsoft-standard-WSL2 #1 SMP Fri Mar 29 23:14:13 UTC 2024 x86_64 GNU/Linux

Output of java -version

openjdk version "21.0.4" 2024-07-16 OpenJDK Runtime Environment (Red_Hat-21.0.4.0.7-2) (build 21.0.4+7) OpenJDK 64-Bit Server VM (Red_Hat-21.0.4.0.7-2) (build 21.0.4+7, mixed mode, sharing)

Quarkus version or git rev

3.12.1

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

Apache Maven 3.9.1 (Red Hat 3.9.1-3) Maven home: /usr/share/maven Java version: 21.0.4, vendor: Red Hat, Inc., runtime: /usr/lib/jvm/java-21-openjdk-21.0.4.0.7-2.fc39.x86_64 Default locale: en_US, platform encoding: UTF-8 OS name: "linux", version: "5.15.153.1-microsoft-standard-wsl2", arch: "amd64", family: "unix"

Additional information

No response

code-with-quarkus.zip Edit: Added a reproducer project

quarkus-bot[bot] commented 1 hour ago

/cc @radcortez (config)