Search in sources :

Example 31 with Representer

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);
}
Also used : LoaderOptions(org.yaml.snakeyaml.LoaderOptions) Representer(org.yaml.snakeyaml.representer.Representer) SafeConstructor(org.yaml.snakeyaml.constructor.SafeConstructor) DumperOptions(org.yaml.snakeyaml.DumperOptions) Yaml(org.yaml.snakeyaml.Yaml)

Example 32 with Representer

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;
}
Also used : LoaderOptions(org.yaml.snakeyaml.LoaderOptions) Representer(org.yaml.snakeyaml.representer.Representer) Constructor(org.yaml.snakeyaml.constructor.Constructor) DumperOptions(org.yaml.snakeyaml.DumperOptions) IOException(java.io.IOException) ClassPathResource(org.springframework.core.io.ClassPathResource) Yaml(org.yaml.snakeyaml.Yaml)

Example 33 with Representer

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));
}
Also used : Representer(org.yaml.snakeyaml.representer.Representer) Constructor(org.yaml.snakeyaml.constructor.Constructor) PnpmLockYaml(com.synopsys.integration.detectable.detectables.pnpm.lockfile.model.PnpmLockYaml) FileReader(java.io.FileReader) Yaml(org.yaml.snakeyaml.Yaml) PnpmLockYaml(com.synopsys.integration.detectable.detectables.pnpm.lockfile.model.PnpmLockYaml)

Example 34 with Representer

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);
}
Also used : Representer(org.yaml.snakeyaml.representer.Representer) DumperOptions(org.yaml.snakeyaml.DumperOptions) Yaml(org.yaml.snakeyaml.Yaml)

Example 35 with Representer

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);
}
Also used : Representer(org.yaml.snakeyaml.representer.Representer) PropertyUtils(org.yaml.snakeyaml.introspector.PropertyUtils) Constructor(org.yaml.snakeyaml.constructor.Constructor) StorageContainerException(org.apache.hadoop.hdds.scm.container.common.helpers.StorageContainerException) Yaml(org.yaml.snakeyaml.Yaml)

Aggregations

Representer (org.yaml.snakeyaml.representer.Representer)82 Yaml (org.yaml.snakeyaml.Yaml)77 DumperOptions (org.yaml.snakeyaml.DumperOptions)54 Constructor (org.yaml.snakeyaml.constructor.Constructor)25 LoaderOptions (org.yaml.snakeyaml.LoaderOptions)21 FileInputStream (java.io.FileInputStream)12 SafeConstructor (org.yaml.snakeyaml.constructor.SafeConstructor)11 IOException (java.io.IOException)7 Tag (org.yaml.snakeyaml.nodes.Tag)7 File (java.io.File)6 TypeDescription (org.yaml.snakeyaml.TypeDescription)6 BaseConstructor (org.yaml.snakeyaml.constructor.BaseConstructor)5 FileNotFoundException (java.io.FileNotFoundException)4 InputStream (java.io.InputStream)4 PropertyUtils (org.yaml.snakeyaml.introspector.PropertyUtils)4 FileOutputStream (java.io.FileOutputStream)3 FileReader (java.io.FileReader)3 OutputStreamWriter (java.io.OutputStreamWriter)3 PrintWriter (java.io.PrintWriter)3 Map (java.util.Map)3