From ac7dfef789f4bc33a033f48775342f82a52aa761 Mon Sep 17 00:00:00 2001
From: Simon Ehrenstein <simon.ehrenstein@gmail.com>
Date: Tue, 16 Feb 2021 14:08:06 +0100
Subject: [PATCH] Make parsing yaml to kotlin objects work

---
 .../kotlin/theodolite/benchmark/BenchmarkYamlParser.kt    | 8 +++++---
 .../src/main/kotlin/theodolite/benchmark/Parser.kt        | 2 +-
 .../kotlin/theodolite/benchmark/TheodoliteYamlExecutor.kt | 4 ++--
 3 files changed, 8 insertions(+), 6 deletions(-)

diff --git a/theodolite-quarkus/src/main/kotlin/theodolite/benchmark/BenchmarkYamlParser.kt b/theodolite-quarkus/src/main/kotlin/theodolite/benchmark/BenchmarkYamlParser.kt
index 8ce10af33..9e5b4456f 100644
--- a/theodolite-quarkus/src/main/kotlin/theodolite/benchmark/BenchmarkYamlParser.kt
+++ b/theodolite-quarkus/src/main/kotlin/theodolite/benchmark/BenchmarkYamlParser.kt
@@ -1,15 +1,17 @@
 package theodolite.benchmark
 
 import org.yaml.snakeyaml.Yaml
+import org.yaml.snakeyaml.constructor.BaseConstructor
+import org.yaml.snakeyaml.constructor.Constructor
 import java.io.File
 import java.io.FileInputStream
 import java.io.InputStream
 
 
 class BenchmarkYamlParser<T>: Parser<T> {
-    override fun parse(path: String): T {
+    override fun parse(path: String): KubernetesBenchmark? {
         val input: InputStream = FileInputStream(File(path))
-        val parser = Yaml()
-        return parser.load<T>(input)
+        val parser = Yaml(Constructor(KubernetesBenchmark::class.java))
+        return parser.loadAs(input, KubernetesBenchmark::class.java)
     }
 }
\ No newline at end of file
diff --git a/theodolite-quarkus/src/main/kotlin/theodolite/benchmark/Parser.kt b/theodolite-quarkus/src/main/kotlin/theodolite/benchmark/Parser.kt
index 1af3006a3..df6655b7e 100644
--- a/theodolite-quarkus/src/main/kotlin/theodolite/benchmark/Parser.kt
+++ b/theodolite-quarkus/src/main/kotlin/theodolite/benchmark/Parser.kt
@@ -1,5 +1,5 @@
 package theodolite.benchmark
 
 interface Parser<T> {
-    fun parse(path: String): T //Yaml
+    fun parse(path: String): KubernetesBenchmark? //Yaml
 }
\ No newline at end of file
diff --git a/theodolite-quarkus/src/main/kotlin/theodolite/benchmark/TheodoliteYamlExecutor.kt b/theodolite-quarkus/src/main/kotlin/theodolite/benchmark/TheodoliteYamlExecutor.kt
index 66c3de474..04d0bd306 100644
--- a/theodolite-quarkus/src/main/kotlin/theodolite/benchmark/TheodoliteYamlExecutor.kt
+++ b/theodolite-quarkus/src/main/kotlin/theodolite/benchmark/TheodoliteYamlExecutor.kt
@@ -2,8 +2,8 @@ package theodolite.benchmark
 
 class TheodoliteYamlExecutor {
     fun run() {
-        val parser = BenchmarkYamlParser<KubernetesBenchmark>()
+        val parser = theodolite.benchmark.BenchmarkYamlParser<KubernetesBenchmark>()
         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
-- 
GitLab