use of org.yaml.snakeyaml.representer.Representer in project spring-framework-5.2.9.RELEASE by somepeopleHavingDream.
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);
if (!this.supportedTypes.isEmpty()) {
return new Yaml(new FilteringConstructor(loaderOptions), new Representer(), new DumperOptions(), loaderOptions);
}
return new Yaml(loaderOptions);
}
use of org.yaml.snakeyaml.representer.Representer in project montithings by MontiCore.
the class DockerComposeConfig method serializeYaml.
public String serializeYaml() {
DumperOptions opt = new DumperOptions();
opt.setAllowReadOnlyProperties(true);
opt.setDefaultFlowStyle(FlowStyle.BLOCK);
// hide java class name
Representer repr = new Representer(opt);
repr.addClassTag(DockerComposeConfig.class, Tag.MAP);
return new Yaml(repr, opt).dump(this);
}
use of org.yaml.snakeyaml.representer.Representer in project spring-framework-debug by Joker-5.
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);
if (!this.supportedTypes.isEmpty()) {
return new Yaml(new FilteringConstructor(loaderOptions), new Representer(), new DumperOptions(), loaderOptions);
}
return new Yaml(loaderOptions);
}
use of org.yaml.snakeyaml.representer.Representer in project HaE by gh0stkey.
the class SetConfig method format.
public void format() {
DumperOptions dop = new DumperOptions();
dop.setDefaultFlowStyle(DumperOptions.FlowStyle.BLOCK);
Representer representer = new Representer();
representer.addClassTag(RulesConfig.class, Tag.MAP);
Yaml yaml = new Yaml(new Constructor(), representer, dop);
RulesConfig con = new RulesConfig();
List<Rules> rls = new ArrayList<>();
Config.ruleConfig.keySet().forEach(i -> {
Rules rlsTmp = new Rules();
rlsTmp.setType(i);
List<Rule> rl = new ArrayList<>();
for (Object[] objects : Config.ruleConfig.get(i)) {
Rule rlTmp = new Rule();
rlTmp.setName((String) objects[1]);
rlTmp.setLoaded((Boolean) objects[0]);
rlTmp.setRegex((String) objects[2]);
rlTmp.setColor((String) objects[3]);
rlTmp.setScope((String) objects[4]);
rlTmp.setEngine((String) objects[5]);
rl.add(rlTmp);
}
rlsTmp.setRule(rl);
rls.add(rlsTmp);
});
con.setRules(rls);
File f = new File(LoadConfig.getConfigPath());
try {
Writer ws = new OutputStreamWriter(new FileOutputStream(f), StandardCharsets.UTF_8);
yaml.dump(con, ws);
} catch (Exception ex) {
ex.printStackTrace();
}
}
use of org.yaml.snakeyaml.representer.Representer in project spring-security by spring-projects.
the class CheckAntoraVersionTask method check.
@TaskAction
public void check() throws FileNotFoundException {
File antoraYmlFile = getAntoraYmlFile().getAsFile().get();
String expectedAntoraVersion = getAntoraVersion().get();
String expectedAntoraPrerelease = getAntoraPrerelease().getOrElse(null);
String expectedAntoraDisplayVersion = getAntoraDisplayVersion().getOrElse(null);
Representer representer = new Representer();
representer.getPropertyUtils().setSkipMissingProperties(true);
Yaml yaml = new Yaml(new Constructor(AntoraYml.class), representer);
AntoraYml antoraYml = yaml.load(new FileInputStream(antoraYmlFile));
String actualAntoraPrerelease = antoraYml.getPrerelease();
boolean preReleaseMatches = antoraYml.getPrerelease() == null && expectedAntoraPrerelease == null || (actualAntoraPrerelease != null && actualAntoraPrerelease.equals(expectedAntoraPrerelease));
String actualAntoraDisplayVersion = antoraYml.getDisplay_version();
boolean displayVersionMatches = antoraYml.getDisplay_version() == null && expectedAntoraDisplayVersion == null || (actualAntoraDisplayVersion != null && actualAntoraDisplayVersion.equals(expectedAntoraDisplayVersion));
String actualAntoraVersion = antoraYml.getVersion();
if (!preReleaseMatches || !displayVersionMatches || !expectedAntoraVersion.equals(actualAntoraVersion)) {
throw new GradleException("The Gradle version of '" + getProject().getVersion() + "' should have version: '" + expectedAntoraVersion + "' prerelease: '" + expectedAntoraPrerelease + "' display_version: '" + expectedAntoraDisplayVersion + "' defined in " + antoraYmlFile + " but got version: '" + actualAntoraVersion + "' prerelease: '" + actualAntoraPrerelease + "' display_version: '" + actualAntoraDisplayVersion + "'");
}
}
Aggregations