use of org.yaml.snakeyaml.LoaderOptions in project spring-framework by spring-projects.
the class YamlProcessor method createYaml.
/**
* Create the {@link Yaml} instance to use.
* <p>The default implementation sets the "allowDuplicateKeys" flag to {@code false},
* enabling built-in duplicate key handling in SnakeYAML 1.18+.
* <p>As of Spring Framework 5.1.16, if custom {@linkplain #setSupportedTypes
* supported types} have been configured, the default implementation creates
* a {@code Yaml} instance that filters out unsupported types encountered in
* YAML documents. If an unsupported type is encountered, an
* {@link IllegalStateException} will be thrown when the node is processed.
* @see LoaderOptions#setAllowDuplicateKeys(boolean)
*/
protected Yaml createYaml() {
LoaderOptions loaderOptions = new LoaderOptions();
loaderOptions.setAllowDuplicateKeys(false);
return new Yaml(new FilteringConstructor(loaderOptions), new Representer(), new DumperOptions(), loaderOptions);
}
use of org.yaml.snakeyaml.LoaderOptions in project configuration-as-code-plugin by jenkinsci.
the class YamlUtils method read.
public static Node read(YamlSource source, Reader reader, ConfigurationContext context) throws IOException {
LoaderOptions loaderOptions = new LoaderOptions();
loaderOptions.setMaxAliasesForCollections(context.getYamlMaxAliasesForCollections());
Composer composer = new Composer(new ParserImpl(new StreamReaderWithSource(source, reader)), new Resolver(), loaderOptions);
try {
return composer.getSingleNode();
} catch (YAMLException e) {
if (e.getMessage().startsWith("Number of aliases for non-scalar nodes exceeds the specified max")) {
throw new ConfiguratorException(String.format("%s%nYou can increase the maximum by setting an environment variable or property%n ENV: %s=\"100\"%n PROPERTY: -D%s=\"100\"", e.getMessage(), ConfigurationContext.CASC_YAML_MAX_ALIASES_ENV, ConfigurationContext.CASC_YAML_MAX_ALIASES_PROPERTY));
}
throw e;
}
}
Aggregations