org.springframework.beans.factory.config.YamlFactoryBean Maven / Gradle / Ivy
package org.springframework.beans.factory.config;
import org.springframework.beans.factory.FactoryBean;
import org.springframework.beans.factory.InitializingBean;
public class YamlFactoryBean extends YamlProcessor implements FactoryBean, InitializingBean {
private boolean singleton = true;
private org.yaml.snakeyaml.Yaml yaml;
@Override
public void afterPropertiesSet() {
if (isSingleton()) {
this.yaml = createYaml();
}
}
@Override
public org.yaml.snakeyaml.Yaml getObject() {
return (this.yaml != null ? this.yaml : createYaml());
}
@Override
public Class getObjectType() {
return org.yaml.snakeyaml.Yaml.class;
}
@Override
protected org.yaml.snakeyaml.Yaml createYaml() {
org.yaml.snakeyaml.representer.Representer representer = new org.yaml.snakeyaml.representer.Representer();
representer.getPropertyUtils().setSkipMissingProperties(true);
representer.getPropertyUtils().setAllowReadOnlyProperties(true);
representer.getPropertyUtils().setBeanAccess(org.yaml.snakeyaml.introspector.BeanAccess.PROPERTY);
return new org.yaml.snakeyaml.Yaml(new StrictMapAppenderConstructor(), representer);
}
@Override
public boolean isSingleton() {
return this.singleton;
}
public void setSingleton(boolean singleton) {
this.singleton = singleton;
}
}