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

Add support for parsing Collections and Maps from the Spring YML format #739

Open
wants to merge 3 commits into
base: 2.x
Choose a base branch
from

Conversation

akang31
Copy link
Contributor

@akang31 akang31 commented Nov 13, 2024

Add support for understanding the Spring YML (YamlPropertiesFactoryBean) way of parsing YML files via the Archaius endpoints. This supports the ConfigProxy and PropertyRepository as these all are eventually backed by AbstractConfig.

This enables all existing Archaius read methods to read multi-line/multi-property maps and arrays as specified by Spring.

Spring YML files are converted to configs from this yml file

test:
    map:
        key1: 1
        key2: 2
        key3: 3
    stringList:
        - a
        - b
        - c

To these configs:

test.map.key1=1
test.map.key2=2
test.map.key3=3
test.stringList[0]=a
test.stringList[1]=b
test.stringList[2]=c

@@ -81,6 +82,14 @@ public Type getRawType() {
return rawType;
}

public boolean isMap() {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe move these two to be private static helper methods in AbstractConfig? Then things would work with any ParametrizedType, not just with ArchaiusType.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good call, moved these into the AbstractConfig instead

@@ -298,6 +299,29 @@ protected <T> T getValue(Type type, String key) {
@SuppressWarnings("unchecked")
protected <T> T getValueWithDefault(Type type, String key, T defaultValue) {
Object rawProp = getRawProperty(key);
if (rawProp == null && type instanceof ArchaiusType) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't ... hate this, but let's think about it a bit more. I'd really love it if there was some way we could call the existing decoders here instead of marshaling the entire map into a single string just to unmarshal it back a nanosecond later. The same goes for the List support.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I updated the code to instead rely on the decoder inside the AbstractConfig. The typing does become a little more annoying, and I also didn't include some of the DefaultCollectionsTypeConverterFactory types (specifically SortedSet and LinkedList). Honestly no great reason for that, but our SBN docs only specifically reference Map, List, and Set.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants