Configuration for list of objects

Viewed 1221

Using Quarkus configuration system, what would be the best way to inject a list of objects in my application ?

In my case I want to configure a list of servers and their types. Using yaml configs that would be :

app.servers
  - uri: host1
    type: type1
  - uri: host2
    type: type2

I can only find solution for array of primitive types but is it possible for custom class ?

2 Answers

Since the question was asked quarkus begun supporting yaml configuration file so the easiest way to configure a list of objects would be through a .yaml config file

For that just add the following dependency :

<dependency>
    <groupId>io.quarkus</groupId>
    <artifactId>quarkus-config-yaml</artifactId>
</dependency>

If you still need to have it as a .properties file then what I ended up doing (because yaml was not supported yet) was to implement a custom property converter.

I am facing with the same issue, unfortunately, custom property converter is still immature, it will concatenate the yaml object to one string like this:

uri=host1type=type1

You have to split it programmatically and create your dto.

This is really ugly...

Related