Trouble loading a subset of custom application.yml configurations to a Map

250 views
Skip to first unread message

Filipe Castilho

unread,
Feb 27, 2020, 12:31:24 PM2/27/20
to Quarkus Development mailing list
Hi everyone,

I'm trying to use yaml extension as my main source for configs and I was trying to figure out what the best approach is for loading a map from the yaml file.

The application.yml

quarkus:
  http:
    port: 8080
configuration:
  value:
    name1: test1
    name2: test2
    name3: test3


In the code I tried to inject the config value like this:
@ConfigProperty(name = "configuration.value")
Values value;


Where Values contains a custom Eclipse Microprofile Converter. The converter looks like this:
public class ValueConverter implements Converter<Values> {

    @Override
    public Values convert(String value) {
// Here there would be the actual code to convert to Map.
        return new Values(map);
    }
}

The problem is that String value comes empty, ie, it does not loading the stull below configuration.value
    name1: test1
    name2: test2
    name3: test3

I've also tried annotating a class with @ConfigProperties(prefix = "configuration.value") and have a map inside but then it does not know how to map that to a Map as expected... Is there a way to create custom config properties converter?

Is this a Eclipse Microprofile issue? Is this a bug? Is this a feature request? :)
Or, is there another/better way of doing this?

Thanks for the help!

Georgios Andrianakis

unread,
Feb 27, 2020, 2:54:17 PM2/27/20
to ktul...@gmail.com, Quarkus Development mailing list
To use @ConfigProperties, you would have to define the type of each type, so it's not useful for this case.

Is this a Eclipse Microprofile issue? Is this a bug? Is this a feature request? :)
Or, is there another/better way of doing this?

I believe this isn't possible in Eclipse Microprofile, but I could very well be wrong, so I will let others comment.

Thanks for the help!

--
You received this message because you are subscribed to the Google Groups "Quarkus Development mailing list" group.
To unsubscribe from this group and stop receiving emails from it, send an email to quarkus-dev...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/quarkus-dev/71939b4f-984f-4384-9df8-c958b95df19c%40googlegroups.com.

David Lloyd

unread,
Feb 27, 2020, 3:36:17 PM2/27/20
to Georgios Andrianakis, ktul...@gmail.com, Quarkus Development mailing list
On Thu, Feb 27, 2020 at 1:54 PM Georgios Andrianakis
<gand...@redhat.com> wrote:
> On Thu, Feb 27, 2020 at 7:31 PM Filipe Castilho <ktul...@gmail.com> wrote:
>> Is this a Eclipse Microprofile issue? Is this a bug? Is this a feature request? :)
>> Or, is there another/better way of doing this?
>
> I believe this isn't possible in Eclipse Microprofile, but I could very well be wrong, so I will let others comment.

That's correct. In MP config, one property can map to one value.
Multiple properties cannot be merged by any means defined in the MP
config spec.

You're probably best off doing this programmatically in your case:
iterate the available property names, matching the property names you
are interested in, and manually adding them to a map. It'd be about
4-5 lines of code at most, I think.
--
- DML

Roberto Cortez

unread,
Feb 27, 2020, 4:05:59 PM2/27/20
to ktul...@gmail.com, Quarkus Development mailing list
You can use org.eclipse.microprofile.config.Config#getPropertyNames and iterate them all.

The annoying thing with the map is that it would be harder for you to know which config converts to what.

@david, I guess this might be another use case for the ConfigAccessors idea.

Cheers,
Roberto
> --
> You received this message because you are subscribed to the Google Groups "Quarkus Development mailing list" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to quarkus-dev...@googlegroups.com.
> To view this discussion on the web visit https://groups.google.com/d/msgid/quarkus-dev/CANghgrR0sHY8OzCCogtCATZE6X%2B4k60VTsEV02va1CG_Jxy68Q%40mail.gmail.com.

Filipe Castilho

unread,
Mar 5, 2020, 6:56:34 PM3/5/20
to Quarkus Development mailing list
I've followed your suggestions to go through the configs and add the ones I wanted to a map!

Thank you all for the help!


On Thursday, February 27, 2020 at 9:05:59 PM UTC, Roberto Cortez wrote:
You can use org.eclipse.microprofile.config.Config#getPropertyNames and iterate them all.

The annoying thing with the map is that it would be harder for you to know which config converts to what.

@david, I guess this might be another use case for the ConfigAccessors idea.

Cheers,
Roberto

> On 27 Feb 2020, at 20:35, David Lloyd <david...@redhat.com> wrote:
>
> On Thu, Feb 27, 2020 at 1:54 PM Georgios Andrianakis
> <gand...@redhat.com> wrote:
>> On Thu, Feb 27, 2020 at 7:31 PM Filipe Castilho <ktul...@gmail.com> wrote:
>>> Is this a Eclipse Microprofile issue? Is this a bug? Is this a feature request? :)
>>> Or, is there another/better way of doing this?
>>
>> I believe this isn't possible in Eclipse Microprofile, but I could very well be wrong, so I will let others comment.
>
> That's correct.  In MP config, one property can map to one value.
> Multiple properties cannot be merged by any means defined in the MP
> config spec.
>
> You're probably best off doing this programmatically in your case:
> iterate the available property names, matching the property names you
> are interested in, and manually adding them to a map.  It'd be about
> 4-5 lines of code at most, I think.
> --
> - DML
>
> --
> You received this message because you are subscribed to the Google Groups "Quarkus Development mailing list" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to quark...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages