
infra.beans.factory.config.YamlMapFactoryBean Maven / Gradle / Ivy
The newest version!
/*
* Copyright 2017 - 2024 the original author or authors.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see [https://www.gnu.org/licenses/]
*/
package infra.beans.factory.config;
import java.util.LinkedHashMap;
import java.util.Map;
import infra.beans.factory.FactoryBean;
import infra.beans.factory.InitializingBean;
import infra.core.YamlProcessor;
import infra.lang.Nullable;
/**
* Factory for a {@code Map} that reads from a YAML source, preserving the
* YAML-declared value types and their structure.
*
* YAML is a nice human-readable format for configuration, and it has some
* useful hierarchical properties. It's more or less a superset of JSON, so it
* has a lot of similar features.
*
*
If multiple resources are provided the later ones will override entries in
* the earlier ones hierarchically; that is, all entries with the same nested key
* of type {@code Map} at any depth are merged. For example:
*
*
* foo:
* bar:
* one: two
* three: four
*
*
* plus (later in the list)
*
*
* foo:
* bar:
* one: 2
* five: six
*
*
* results in an effective input of
*
*
* foo:
* bar:
* one: 2
* three: four
* five: six
*
*
* Note that the value of "foo" in the first document is not simply replaced
* with the value in the second, but its nested values are merged.
*
* Requires SnakeYAML 2.0 or higher
*
* @author Dave Syer
* @author Juergen Hoeller
* @author Harry Yang
* @since 4.0 2021/11/30 14:11
*/
public class YamlMapFactoryBean extends YamlProcessor implements FactoryBean
© 2015 - 2025 Weber Informatics LLC | Privacy Policy