Skip to content
Snippets Groups Projects
Commit ac7dfef7 authored by Simon Ehrenstein's avatar Simon Ehrenstein
Browse files

Make parsing yaml to kotlin objects work

parent 7437021d
No related branches found
No related tags found
4 merge requests!159Re-implementation of Theodolite with Kotlin/Quarkus,!157Update Graal Image in CI pipeline,!85Introduce new Benchmark class and Patcher,!83WIP: Re-implementation of Theodolite with Kotlin/Quarkus
package theodolite.benchmark package theodolite.benchmark
import org.yaml.snakeyaml.Yaml import org.yaml.snakeyaml.Yaml
import org.yaml.snakeyaml.constructor.BaseConstructor
import org.yaml.snakeyaml.constructor.Constructor
import java.io.File import java.io.File
import java.io.FileInputStream import java.io.FileInputStream
import java.io.InputStream import java.io.InputStream
class BenchmarkYamlParser<T>: Parser<T> { class BenchmarkYamlParser<T>: Parser<T> {
override fun parse(path: String): T { override fun parse(path: String): KubernetesBenchmark? {
val input: InputStream = FileInputStream(File(path)) val input: InputStream = FileInputStream(File(path))
val parser = Yaml() val parser = Yaml(Constructor(KubernetesBenchmark::class.java))
return parser.load<T>(input) return parser.loadAs(input, KubernetesBenchmark::class.java)
} }
} }
\ No newline at end of file
package theodolite.benchmark package theodolite.benchmark
interface Parser<T> { interface Parser<T> {
fun parse(path: String): T //Yaml fun parse(path: String): KubernetesBenchmark? //Yaml
} }
\ No newline at end of file
...@@ -2,8 +2,8 @@ package theodolite.benchmark ...@@ -2,8 +2,8 @@ package theodolite.benchmark
class TheodoliteYamlExecutor { class TheodoliteYamlExecutor {
fun run() { fun run() {
val parser = BenchmarkYamlParser<KubernetesBenchmark>() val parser = theodolite.benchmark.BenchmarkYamlParser<KubernetesBenchmark>()
val benchmark= parser.parse("./../../../resources/main/yaml/test.yaml") val benchmark= parser.parse("./../../../resources/main/yaml/test.yaml")
System.out.println(benchmark.name) System.out.println(benchmark?.name)
} }
} }
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment