
com.wavemaker.commons.util.DefaultYamlProcessor Maven / Gradle / Ivy
/*******************************************************************************
* Copyright (C) 2022-2023 WaveMaker, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
******************************************************************************/
package com.wavemaker.commons.util;
import java.util.Properties;
import org.springframework.beans.factory.config.YamlProcessor;
import org.springframework.core.CollectionFactory;
/**
* This class uses YamlProcessor to convert the yaml resources to properties.
* The Properties created by this class have nested paths for hierarchical
* objects, so for instance this YAML
*
*
* environments:
* dev:
* url: https://dev.bar.com
* name: Developer Setup
* prod:
* url: https://foo.bar.com
* name: My Cool App
*
*
* is transformed into these properties:
*
*
* environments.dev.url=https://dev.bar.com
* environments.dev.name=Developer Setup
* environments.prod.url=https://foo.bar.com
* environments.prod.name=My Cool App
*
*
* Lists are split as property keys with []
dereferencers, for
* example this YAML:
*
*
* servers:
* - dev.bar.com
* - foo.bar.com
*
*
* becomes properties like this:
*
*
* servers[0]=dev.bar.com
* servers[1]=foo.bar.com
*
*/
public class DefaultYamlProcessor extends YamlProcessor {
public Properties getProperties() {
return createProperties();
}
private Properties createProperties() {
Properties result = CollectionFactory.createStringAdaptingProperties();
process((properties, map) -> result.putAll(properties));
return result;
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy