Hi.
I'm trying to merge two value files in the following way, but square brackets are added to my numeric keys.:
ByteArrayResource[] valuesYamlFromFile = ...
YamlMapFactoryBean factoryBean = new YamlMapFactoryBean();
factoryBean.setResolutionMethod(YamlProcessor.ResolutionMethod.OVERRIDE_AND_IGNORE);
factoryBean.setSingleton(false);
factoryBean.setResources(valuesYamlFromFile);
Map<String, Object> mergedValues = factoryBean.getObject();
Example of loading one yaml:
before:
numbers:
100: "101"
200: "201"
and after:
numbers:
[100]: "101"
[200]: "201"
adding square brackets happens here: https://github.com/spring-projects/spring-framework/blob/f516431260d27670c443006c08881c4ccc32a955/spring-beans/src/main/java/org/springframework/beans/factory/config/YamlProcessor.java#L252
Why did the numeric keys change in the form of adding square brackets? Yaml supports numbers as keys, but adding other characters to them can lead to errors.
Comment From: snicoll
YamlProcessor
are meant essentially to integrate with the Environment
and provide a way to build a PropertySource
from a YAML file, in particular a Properties
. As such you should not expect the type there to be preserved. If you need such feature, please use a different YAML parser.