use of org.yaml.snakeyaml.representer.Representer 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.representer.Representer in project BoofCV by lessthanoptimal.
the class CalibrationIO method loadOpenCV.
/**
* Loads intrinsic parameters in OpenCV format.
*/
public static CameraPinholeBrown loadOpenCV(Reader reader) {
CameraPinholeBrown out = new CameraPinholeBrown();
try {
String filtered = IOUtils.toString(reader);
// It doesn't like the header or that class def
filtered = filtered.replace("%YAML:1.0", "");
filtered = filtered.replace("!!opencv-matrix", "");
Representer representer = new Representer();
representer.getPropertyUtils().setSkipMissingProperties(true);
Yaml yaml = new Yaml(new Constructor(), representer);
Map<String, Object> map = yaml.load(filtered);
int width = getOrThrow(map, "image_width");
int height = getOrThrow(map, "image_height");
DMatrixRMaj K = loadOpenCVMatrix(getOrThrow(map, "camera_matrix"));
DMatrixRMaj distortion = loadOpenCVMatrix(getOrThrow(map, "distortion_coefficients"));
PerspectiveOps.matrixToPinhole(K, width, height, out);
if (distortion.getNumElements() >= 5)
out.setRadial(distortion.get(0), distortion.get(1), distortion.get(4));
else if (distortion.getNumElements() >= 2)
out.setRadial(distortion.get(0), distortion.get(1));
if (distortion.getNumElements() >= 5)
out.fsetTangental(distortion.get(2), distortion.get(3));
} catch (IOException e) {
throw new UncheckedIOException(e);
}
return out;
}
use of org.yaml.snakeyaml.representer.Representer in project testcases by coheigea.
the class YamlTest method referencesWithRecursiveKeysNotAllowedByDefaultAtAPILevel.
@org.junit.Test
public void referencesWithRecursiveKeysNotAllowedByDefaultAtAPILevel() {
String output = createDump(30);
// Load
LoaderOptions settings = new LoaderOptions();
settings.setMaxAliasesForCollections(150);
Yaml yaml = new Yaml(new CustomConstructor(), new Representer(), new DumperOptions(), settings);
try {
yaml.load(output);
fail();
} catch (Exception e) {
assertEquals("Recursive key for mapping is detected but it is not configured to be allowed.", e.getMessage());
}
}
use of org.yaml.snakeyaml.representer.Representer in project today-framework by TAKETODAY.
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>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.representer.Representer in project today-framework by TAKETODAY.
the class OriginTrackedYamlLoader method createYaml.
private Yaml createYaml(LoaderOptions loaderOptions) {
BaseConstructor constructor = new OriginTrackingConstructor(loaderOptions);
Representer representer = new Representer();
DumperOptions dumperOptions = new DumperOptions();
LimitedResolver resolver = new LimitedResolver();
return new Yaml(constructor, representer, dumperOptions, loaderOptions, resolver);
}
Aggregations