0

I have the following configuration:

my:
  filter:
      number-range:
        - range:
              from: +994700110000
              to: +994700110002

The ConfigMapping is:

@ConfigMapping(prefix = "my.filter")
public interface SmsGatewayFilterListConfig {

    List<RangeWrapper> numberRange();
}

with pojos:


public record RangeWrapper(Range range) {
}

public record Range(String from,
                    String to) {
}

And my converter (registered in META-INF/services/org.eclipse.microprofile.config.spi.Converter ):

import org.eclipse.microprofile.config.spi.Converter;
import org.yaml.snakeyaml.Yaml;

public class RangeWrapperConverter implements Converter<RangeWrapper> {
    @Override
    public RangeWrapper convert(String s) throws IllegalArgumentException, NullPointerException {
        System.out.println("Got: " + s);
        return new Yaml().loadAs(s, RangeWrapper.class);
    }
}

I have the quarkus-config-yaml dependency set, and am using application.yml

When i try to startup my quarkus app, I am getting parsing issues however, as the string which is passed to my converter is being:

{"number-range": [{"range": {"from": "+994700110000"

This seems to somehow be in json format, and even then not providing the full content of my yaml. What can be wrong please?

mangusbrother
  • 3,988
  • 11
  • 51
  • 103

1 Answers1

0

My recommendation is to use the following mapping strategy:

@ConfigMapping(prefix = "my.filter")
interface RangesMapping {
    List<Ranges> numberRange();

    interface Ranges {
        Range range();

        interface Range {
            String from();

            String to();
        }
    }
}

This does not require any specific Converter. Everything is handled for you automatically.

What you currently see is a legacy feature that provided the value of the parent property my.filter tree, so users could use a Converter, because there was no automatic conversion support for List or Map. That is not the case anymore and such property value will be removed.

Roberto Cortez
  • 803
  • 4
  • 8