Skip to content

YamlProcessor outside spring-boot #46575

@wind57

Description

@wind57

It all starts with an issue we have recently received in spring-cloud-kubernetes. I will try to simplify it as much as I can.

If I have an application.yaml like this:

bean:
  items:
    - Item 1
    - Item 2
    - Item 3
    - Item 4
    - Item 5

---
spring:
  config:
    activate:
      on-profile: dev

bean:
  items:
    - Item 1
    - Item 6
    - Item 7

and activate the dev profile, bean.items would be injected as [Item 1, Item 6, Item 7] and that is of course correct.

We need to "replicate" the same thing in spring-cloud-kubernetes. There, we read a configmap for example and based on what's inside it, we would create the PropertySource by hand.

The problem is, until now, we were using YamlPropertiesFactoryBean, and this one would "override" properties for lists, because of this code:

    protected Properties createProperties() {
        Properties result = CollectionFactory.createStringAdaptingProperties();
        this.process((properties, map) -> result.putAll(properties));
        return result;
    }

As such, we would end up with:

bean.items = [Item 1, Item 6, Item 7, Item 4, Item 5]

This happens because YamlPropertiesFactoryBean does not know to override properly arrays and maps. I ended up creating our own class for this parsing, that is heavily based on YamlPropertiesFactoryBean.

Ryan Baxter advised me to open an issue here to see if the real solution is in spring-boot and not us creating a custom parsing class.

Thank you.

Metadata

Metadata

Assignees

No one assigned

    Labels

    status: declinedA suggestion or change that we don't feel we should currently apply

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions