All Downloads are FREE. Search and download functionalities are using the official Maven repository.

ch.sbb.releasetrain.utils.yaml.YamlModelAccessor Maven / Gradle / Ivy

/*
 * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements;
 * and to You under the Apache License, Version 2.0.
 */
package ch.sbb.releasetrain.utils.yaml;

import java.util.Collections;
import java.util.List;

import lombok.extern.slf4j.Slf4j;

import org.yaml.snakeyaml.Yaml;

import ch.sbb.releasetrain.utils.model.Recognizable;

/**
 * Marshaling / unmarsahling models from / to xstream strings
 *
 * @author u203244 (Daniel Marthaler)
 * @since 0.0.1, 2016
 */
@Slf4j
@SuppressWarnings("unchecked")
public class YamlModelAccessor {

    Yaml yaml = new Yaml();

    public String convertEntrys(List in) {
        return yaml.dump(in);
    }

    public List convertEntrys(String in) {
        List list = (List) yaml.load(in);
        Collections.sort(list);
        return list;
    }

    public String convertEntry(T in) {
        return yaml.dump(in);
    }

    public T convertEntry(String in) {
        return (T) yaml.load(in);
    }

}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy