Search in sources :

Example 46 with Yaml

use of org.yaml.snakeyaml.Yaml in project fabric8-maven-plugin by fabric8io.

the class ImageStreamServiceTest method readImageStreamDescriptor.

private Map readImageStreamDescriptor(File target) throws FileNotFoundException {
    Yaml yaml = new Yaml();
    InputStream ios = new FileInputStream(target);
    // Parse the YAML file and return the output as a series of Maps and Lists
    return (Map<String, Object>) yaml.load(ios);
}
Also used : Yaml(org.yaml.snakeyaml.Yaml)

Example 47 with Yaml

use of org.yaml.snakeyaml.Yaml in project halyard by spinnaker.

the class GlobalApplicationOptions method getInstance.

public static GlobalApplicationOptions getInstance() {
    if (GlobalApplicationOptions.options == null) {
        Yaml yamlParser = new Yaml();
        ObjectMapper objectMapper = new ObjectMapper();
        objectMapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
        objectMapper.configure(DeserializationFeature.FAIL_ON_NULL_CREATOR_PROPERTIES, false);
        objectMapper.setSerializationInclusion(JsonInclude.Include.NON_NULL);
        try {
            GlobalApplicationOptions.options = objectMapper.convertValue(yamlParser.load(FileUtils.openInputStream(new File(CONFIG_PATH))), GlobalApplicationOptions.class);
        } catch (IOException e) {
            GlobalApplicationOptions.options = new GlobalApplicationOptions();
        }
    }
    return GlobalApplicationOptions.options;
}
Also used : IOException(java.io.IOException) File(java.io.File) Yaml(org.yaml.snakeyaml.Yaml) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper)

Example 48 with Yaml

use of org.yaml.snakeyaml.Yaml in project CommandHelper by EngineHub.

the class VirtualFileSystemSettings method serialize.

public static String serialize(Map<VirtualGlob, SettingGroup> settings) {
    DumperOptions options = new DumperOptions();
    options.setPrettyFlow(true);
    Yaml yaml = new Yaml(options);
    Map<String, Map<String, Object>> serializable = new HashMap<String, Map<String, Object>>();
    for (VirtualGlob glob : settings.keySet()) {
        Map<String, Object> inner = new HashMap<String, Object>();
        for (VirtualFileSystemSetting setting : settings.get(glob).settingGroup.keySet()) {
            inner.put(setting.getName(), settings.get(glob).get(setting));
        }
        serializable.put(glob.toString(), inner);
    }
    return yaml.dump(serializable);
}
Also used : HashMap(java.util.HashMap) DumperOptions(org.yaml.snakeyaml.DumperOptions) EnumMap(java.util.EnumMap) HashMap(java.util.HashMap) Map(java.util.Map) Yaml(org.yaml.snakeyaml.Yaml)

Example 49 with Yaml

use of org.yaml.snakeyaml.Yaml in project gravitee-management-rest-api by gravitee-io.

the class PortalNotificationServiceImpl method create.

@Override
public void create(Hook hook, List<String> users, Object params) {
    try {
        // get notification template
        String tpl = RELATIVE_TPL_PATH + hook.getScope().name() + "." + hook.name() + ".yml";
        final Template template = freemarkerConfiguration.getTemplate(tpl);
        final String yamlContent = processTemplateIntoString(template, params);
        Yaml yaml = new Yaml();
        Map<String, String> load = yaml.loadAs(yamlContent, HashMap.class);
        List<NewPortalNotificationEntity> notifications = new ArrayList<>(users.size());
        users.forEach(user -> {
            NewPortalNotificationEntity notification = new NewPortalNotificationEntity();
            notification.setUser(user);
            notification.setTitle(load.get("title"));
            notification.setMessage(load.get("message"));
            notifications.add(notification);
        });
        create(notifications);
    } catch (final Exception ex) {
        LOGGER.error("Error while sending notification", ex);
        throw new TechnicalManagementException("Error while sending notification", ex);
    }
}
Also used : FreeMarkerTemplateUtils.processTemplateIntoString(org.springframework.ui.freemarker.FreeMarkerTemplateUtils.processTemplateIntoString) NewPortalNotificationEntity(io.gravitee.management.model.notification.NewPortalNotificationEntity) Yaml(org.yaml.snakeyaml.Yaml) TechnicalException(io.gravitee.repository.exceptions.TechnicalException) TechnicalManagementException(io.gravitee.management.service.exceptions.TechnicalManagementException) TechnicalManagementException(io.gravitee.management.service.exceptions.TechnicalManagementException) Template(freemarker.template.Template)

Example 50 with Yaml

use of org.yaml.snakeyaml.Yaml in project pai by Microsoft.

the class YamlUtils method toObject.

// Bytes <-> Yaml
public static <T> T toObject(byte[] bytes, Class<T> classRef) {
    Representer representer = new Representer();
    representer.getPropertyUtils().setSkipMissingProperties(true);
    Yaml yaml = new Yaml(new Constructor(classRef), representer);
    return yaml.loadAs(new String(bytes), classRef);
}
Also used : Representer(org.yaml.snakeyaml.representer.Representer) Constructor(org.yaml.snakeyaml.constructor.Constructor) Yaml(org.yaml.snakeyaml.Yaml)

Aggregations

Yaml (org.yaml.snakeyaml.Yaml)276 Map (java.util.Map)104 HashMap (java.util.HashMap)85 IOException (java.io.IOException)58 FileInputStream (java.io.FileInputStream)49 InputStream (java.io.InputStream)49 File (java.io.File)43 DumperOptions (org.yaml.snakeyaml.DumperOptions)42 Constructor (org.yaml.snakeyaml.constructor.Constructor)30 Test (org.junit.Test)26 ArrayList (java.util.ArrayList)25 FileNotFoundException (java.io.FileNotFoundException)22 SafeConstructor (org.yaml.snakeyaml.constructor.SafeConstructor)22 List (java.util.List)21 Writer (java.io.Writer)18 Path (java.nio.file.Path)17 LinkedHashMap (java.util.LinkedHashMap)17 Reader (java.io.Reader)16 Properties (java.util.Properties)14 InputStreamReader (java.io.InputStreamReader)13