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

com.ancientlightstudios.simplegen.YamlReader.kt Maven / Gradle / Ivy

There is a newer version: 5.1.0
Show newest version
package com.ancientlightstudios.simplegen

import com.fasterxml.jackson.core.type.TypeReference
import com.fasterxml.jackson.databind.ObjectMapper
import com.fasterxml.jackson.dataformat.yaml.YAMLFactory
import java.io.InputStream
import java.util.*

object YamlReader {

    /**
     * Reads a yaml stream into a map.
     * @param stream the stream to read
     * @return the resulting map.
     */
    fun readToMap(stream: InputStream): Map {
        val typeRef = object : TypeReference>() {}
        return ObjectMapper(YAMLFactory()).readValue(stream, typeRef)
    }

    /**
     * Reads a yaml stream into a pojo.
     * @param stream the stream to read
     * @param type the pojo type
     * @return the resulting pojo
     */
    fun  readToPojo(stream: InputStream, type: Class): T = ObjectMapper(YAMLFactory()).readValue(stream, type)
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy