Skip to content

YAML support under PropertiesLoaderUtils #37066

Description

@varunu28

Enhancements requests

Currently https://github.com/spring-projects/spring-framework/blob/main/spring-core/src/main/java/org/springframework/core/io/support/PropertiesLoaderUtils.java#L92 provides support for parsing XML & .properties file. But it fails to parse if the properties file is defined as YAML.

Right now PropertiesLoaderUtils already checks for XML file extension & it can similarly check for YAML file extension & replace the current parsing logic with a custom implementation.

I agree that currently this can be achieved by providing a custom implementation of PropertySourceFactory as below without the need of any external library dependency

public class YamlPropertySourceFactory implements PropertySourceFactory {

    @Override
    public PropertiesPropertySource createPropertySource(String name, EncodedResource resource) {
        YamlPropertiesFactoryBean factory = new YamlPropertiesFactoryBean();
        factory.setResources(resource.getResource());
        Properties properties = factory.getObject();
        String sourceName = (name != null) ? name : resource.getResource().getFilename();
        return new PropertiesPropertySource(sourceName, properties);
    }
}

Though considering that YAML format is getting more traction(start.spring.io started supporting YAML format last year), can an out of box support be considered for supporting YAML files?

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions