Error when YAML Config + List + Constructor-based converter
See original GitHub issueDescribe the bug
I am getting a strange issue with lists in YAML configuration. The following works ok-ish:
@ConfigProperties
public interface BaseConfiguration {
public Collection<MyListElement> mylist();
public class MyListElement {
public String text;
public MyListElement(final String text){ this.text = text.toUpperCase(); }
}
}
Now I want to make sure I retain the order of the elements in mylist
, hence I replace Collection
by List
.
If I do so, Arc refuses the MyListElement
class at compile time for not having a no-args constructor 🤔
Caused by: java.lang.IllegalArgumentException: Class 'org.acme.BaseConfiguration$MyListElement' which is used as return type of method 'mylist' in class 'org.acme.BaseConfiguration' must be have a no-args constructor
at io.quarkus.arc.deployment.configproperties.YamlListObjectHandler.validateClass(YamlListObjectHandler.java:160)
Side-note the typo in the message requiring the class must be have
a no-args constructor
If I add the constructor, snakeyaml
crashes at run-time asking for a single-argument constructor for a synthetic class org.acme.BaseConfiguration$MyListElement_GeneratedListWrapper_mylist
Caused by: Can't construct a java object for tag:yaml.org,2002:org.acme.BaseConfiguration$MyListElement_GeneratedListWrapper_mylist; exception=No single argument constructor found for class org.acme.BaseConfiguration$MyListElement_GeneratedListWrapper_mylist : null
in 'string', line 1, column 1:
element,anotherElement
^
at org.yaml.snakeyaml.constructor.Constructor$ConstructYamlObject.construct(Constructor.java:335)
...
Expected behavior
Expect List
configuration entries to be working the same way as Collection
entries.
Actual behavior
List
configuration entries crash with using constructor-based converters.
To Reproduce
Reproducer here: https://github.com/someth2say/quarkus-issue-list-converter
Configuration
base:
mylist:
- element
- anotherElement
Environment (please complete the following information):
Output of uname -a
or ver
Linux localhost.localdomain 5.10.22-200.fc33.x86_64 #1 SMP Tue Mar 9 22:05:08 UTC 2021 x86_64 x86_64 x86_64 GNU/Linux
Output of java -version
openjdk version “11.0.10” 2021-01-19 OpenJDK Runtime Environment GraalVM CE 20.3.1 (build 11.0.10+8-jvmci-20.3-b09) OpenJDK 64-Bit Server VM GraalVM CE 20.3.1 (build 11.0.10+8-jvmci-20.3-b09, mixed mode, sharing)
GraalVM version (if different from Java)
Quarkus version or git rev
1.12.2.Final
Build tool (ie. output of mvnw --version
or gradlew --version
)
Apache Maven 3.6.3 (cecedd343002696d0abb50b32b541b8a6ba2883f) Maven home: /home/jordisola/.m2/wrapper/dists/apache-maven-3.6.3-bin/1iopthnavndlasol9gbrbg6bf2/apache-maven-3.6.3 Java version: 11.0.10, vendor: GraalVM Community, runtime: /home/jordisola/.sdkman/candidates/java/20.3.1.r11-grl Default locale: en_GB, platform encoding: UTF-8 OS name: “linux”, version: “5.10.22-200.fc33.x86_64”, arch: “amd64”, family: “unix”
Additional context
(Add any other context about the problem here.) https://quarkusio.zulipchat.com/#narrow/stream/187030-users/topic/Errors.20with.20YAML.20config.20.2B.20List.20.20.2B.20Constructor-based.20conve.2E.2E.2E
Issue Analytics
- State:
- Created 3 years ago
- Comments:9 (9 by maintainers)
So we plan to replace the
@ConfigPropeties
interfaces implementation with the one from SR Config, so in the end they should work the same.Sure! The
ConfigMapping
approach worked for me.