use of org.yaml.snakeyaml.representer.Representer in project apollo by apolloconfig.
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.representer.Representer in project shiba by codeforamerica.
the class ApplicationConfigurationFactory method getObject.
@Override
public ApplicationConfiguration getObject() {
ClassPathResource classPathResource = new ClassPathResource(configPath);
LoaderOptions loaderOptions = new LoaderOptions();
loaderOptions.setAllowDuplicateKeys(false);
loaderOptions.setMaxAliasesForCollections(Integer.MAX_VALUE);
loaderOptions.setAllowRecursiveKeys(true);
Yaml yaml = new Yaml(new Constructor(ApplicationConfiguration.class), new Representer(), new DumperOptions(), loaderOptions);
ApplicationConfiguration appConfig = null;
try {
appConfig = yaml.load(classPathResource.getInputStream());
} catch (IOException e) {
e.printStackTrace();
}
return appConfig;
}
use of org.yaml.snakeyaml.representer.Representer in project synopsys-detect by blackducksoftware.
the class PnpmLockYamlParser method parseYamlFile.
private PnpmLockYaml parseYamlFile(File pnpmLockYamlFile) throws FileNotFoundException {
Representer representer = new Representer();
representer.getPropertyUtils().setSkipMissingProperties(true);
Yaml yaml = new Yaml(new Constructor(PnpmLockYaml.class), representer);
return yaml.load(new FileReader(pnpmLockYamlFile));
}
use of org.yaml.snakeyaml.representer.Representer in project devops-service by open-hand.
the class GitlabCiUtil method getYamlObject.
/**
* 获取用于序列化{@link GitlabCi} 的{@link Yaml}对象
*
* @return 专用配置的序列化对象
*/
private static Yaml getYamlObject() {
Representer representer = new SkipNullAndUnwrapMapRepresenter();
representer.setPropertyUtils(new FieldOrderPropertyUtil());
DumperOptions options = new DumperOptions();
options.setDefaultFlowStyle(DumperOptions.FlowStyle.BLOCK);
options.setAllowReadOnlyProperties(true);
options.setPrettyFlow(true);
return new Yaml(representer, options);
}
use of org.yaml.snakeyaml.representer.Representer in project ozone by apache.
the class ContainerDataYaml method getYamlForContainerType.
/**
* Given a ContainerType this method returns a Yaml representation of
* the container properties.
*
* @param containerType type of container
* @param withReplicaIndex in the container yaml
* @return Yamal representation of container properties
* @throws StorageContainerException if the type is unrecognized
*/
public static Yaml getYamlForContainerType(ContainerType containerType, boolean withReplicaIndex) throws StorageContainerException {
PropertyUtils propertyUtils = new PropertyUtils();
propertyUtils.setBeanAccess(BeanAccess.FIELD);
propertyUtils.setAllowReadOnlyProperties(true);
if (containerType == ContainerType.KeyValueContainer) {
List<String> yamlFields = KeyValueContainerData.getYamlFields();
if (withReplicaIndex) {
yamlFields = new ArrayList<>(yamlFields);
yamlFields.add(REPLICA_INDEX);
}
Representer representer = new ContainerDataRepresenter(yamlFields);
representer.setPropertyUtils(propertyUtils);
representer.addClassTag(KeyValueContainerData.class, KEYVALUE_YAML_TAG);
Constructor keyValueDataConstructor = new ContainerDataConstructor();
return new Yaml(keyValueDataConstructor, representer);
}
throw new StorageContainerException("Unrecognized container Type " + "format " + containerType, ContainerProtos.Result.UNKNOWN_CONTAINER_TYPE);
}
Aggregations