use of org.yaml.snakeyaml.LoaderOptions in project swagger-parser by swagger-api.
the class DeserializationUtils method buildSnakeYaml.
public static org.yaml.snakeyaml.Yaml buildSnakeYaml(BaseConstructor constructor) {
try {
LoaderOptions.class.getMethod("getMaxAliasesForCollections");
} catch (NoSuchMethodException e) {
return new org.yaml.snakeyaml.Yaml(constructor);
}
try {
LoaderOptions loaderOptions = new LoaderOptions();
Method method = LoaderOptions.class.getMethod("setMaxAliasesForCollections", int.class);
method.invoke(loaderOptions, options.getMaxYamlAliasesForCollections());
method = LoaderOptions.class.getMethod("setAllowRecursiveKeys", boolean.class);
method.invoke(loaderOptions, options.isYamlAllowRecursiveKeys());
method = LoaderOptions.class.getMethod("setAllowDuplicateKeys", boolean.class);
method.invoke(loaderOptions, false);
org.yaml.snakeyaml.Yaml yaml = new org.yaml.snakeyaml.Yaml(constructor, new Representer(), new DumperOptions(), loaderOptions, new CustomResolver());
return yaml;
} catch (ReflectiveOperationException e) {
//
LOGGER.debug("using snakeyaml < 1.25, not setting YAML Billion Laughs Attack snakeyaml level protection");
}
return new org.yaml.snakeyaml.Yaml(constructor);
}
use of org.yaml.snakeyaml.LoaderOptions in project spring-boot by spring-projects.
the class OriginTrackedYamlLoader method createYaml.
@Override
protected Yaml createYaml() {
LoaderOptions loaderOptions = new LoaderOptions();
loaderOptions.setAllowDuplicateKeys(false);
loaderOptions.setMaxAliasesForCollections(Integer.MAX_VALUE);
loaderOptions.setAllowRecursiveKeys(true);
return createYaml(loaderOptions);
}
use of org.yaml.snakeyaml.LoaderOptions in project apollo by ctripcorp.
the class YamlParser method createYaml.
/**
* Create the {@link Yaml} instance to use.
*/
private Yaml createYaml() {
LoaderOptions loadingConfig = new LoaderOptions();
loadingConfig.setAllowDuplicateKeys(false);
return new Yaml(new SafeConstructor(), new Representer(), new DumperOptions(), loadingConfig);
}
use of org.yaml.snakeyaml.LoaderOptions in project es6draft by anba.
the class Test262Info method readYaml.
private void readYaml(String descriptor, ErrorHandler error) throws MalformedDataException {
assert descriptor != null && !descriptor.isEmpty();
boolean lenient = error == ErrorHandler.Ignore;
Yaml yaml = null;
if (lenient) {
yaml = yamlQueue.poll();
}
if (yaml == null) {
Constructor constructor = new Constructor(TestDescriptor.class);
if (lenient) {
PropertyUtils utils = new PropertyUtils();
utils.setSkipMissingProperties(true);
constructor.setPropertyUtils(utils);
}
yaml = new Yaml(constructor);
if (!lenient) {
LoaderOptions loaderOptions = new LoaderOptions();
loaderOptions.setAllowDuplicateKeys(false);
}
}
TestDescriptor desc;
try {
desc = yaml.loadAs(descriptor, TestDescriptor.class);
} catch (YAMLException e) {
throw new MalformedDataException(e.getMessage(), e);
}
if (lenient) {
yamlQueue.offer(yaml);
}
this.description = desc.getDescription();
this.includes = desc.getIncludes();
this.features = desc.getFeatures();
this.errorType = desc.getNegative().getType();
this.errorPhase = from(desc.getNegative().getPhase(), lenient);
this.negative = desc.getNegative().getType() != null;
if (!desc.getFlags().isEmpty()) {
if (!lenient) {
for (String flag : desc.getFlags()) {
if (!allowedFlags.contains(flag)) {
throw new MalformedDataException(String.format("Unknown flag '%s'", flag));
}
}
}
this.noStrict = desc.getFlags().contains("noStrict");
this.onlyStrict = desc.getFlags().contains("onlyStrict");
this.module = desc.getFlags().contains("module");
this.raw = desc.getFlags().contains("raw");
this.async = desc.getFlags().contains("async");
}
if (!lenient && errorPhase == ErrorPhase.Resolution && !module) {
throw new MalformedDataException(String.format("Invalid error phase 'resolution' for non-module test"));
}
}
use of org.yaml.snakeyaml.LoaderOptions in project java by kubernetes-client.
the class Yaml method getSnakeYaml.
/**
* Instantiate a snake yaml with the target model type, and the dump/load option specified..
* Optionally, passing custom type descriptions if the target serialized name differs from the
* actual field name.
*
* @param type the target model type
* @param dumperOptions the dumper options
* @param loaderOptions the loader options
* @param typeDescriptions additional type descriptions for customizing the serializer
* @return the new snake yaml instance
*/
public static org.yaml.snakeyaml.Yaml getSnakeYaml(Class<?> type, DumperOptions dumperOptions, LoaderOptions loaderOptions, TypeDescription... typeDescriptions) {
if (loaderOptions == null) {
loaderOptions = new LoaderOptions();
}
loaderOptions.setEnumCaseSensitive(false);
BaseConstructor constructor = new SafeConstructor(loaderOptions);
Representer representer = new CustomRepresenter();
if (type != null) {
constructor = new CustomConstructor(type, loaderOptions);
}
// register builtin type descriptions
registerBuiltinGsonCompatibles(constructor, representer);
for (TypeDescription desc : typeDescriptions) {
registerCustomTypeDescriptions(constructor, representer, desc);
}
if (dumperOptions == null) {
dumperOptions = new DumperOptions();
dumperOptions.setDefaultFlowStyle(representer.getDefaultFlowStyle());
dumperOptions.setDefaultScalarStyle(representer.getDefaultScalarStyle());
dumperOptions.setAllowReadOnlyProperties(representer.getPropertyUtils().isAllowReadOnlyProperties());
dumperOptions.setTimeZone(representer.getTimeZone());
}
return new org.yaml.snakeyaml.Yaml(constructor, representer, dumperOptions, loaderOptions);
}
Aggregations