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

ConfigMapping with generic child objects from dependencies not working #43934

Open
JM92103 opened this issue Oct 17, 2024 · 2 comments
Open

ConfigMapping with generic child objects from dependencies not working #43934

JM92103 opened this issue Oct 17, 2024 · 2 comments
Labels
area/config kind/enhancement New feature or request

Comments

@JM92103
Copy link

JM92103 commented Oct 17, 2024

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

@JM92103 JM92103 added the kind/bug Something isn't working label Oct 17, 2024
Copy link

quarkus-bot bot commented Oct 17, 2024

/cc @radcortez (config)

@radcortez
Copy link
Member

Currently, we don't support generic declarations in the config interface. It is not impossible to add it, but it does require a considerable amount of effort. Until now, we have never had users ask for it.

Honestly, I don't think this is a top priority. If someone wants to work in this, I'm happy to help review the PR.

@radcortez radcortez added kind/enhancement New feature or request and removed kind/bug Something isn't working labels Oct 18, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/config kind/enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants