@@ -6,7 +6,7 @@ import org.junit.jupiter.api.Test
6
6
7
7
class TemplateTest {
8
8
@Test
9
- fun `template values in map should be replaced` () {
9
+ fun `template values in map should be replaced` () {
10
10
val templates =
11
11
mapOf (
12
12
" templateVal1" to " val1" ,
@@ -25,49 +25,4 @@ class TemplateTest {
25
25
println (it)
26
26
}
27
27
}
28
-
29
- // Example usage
30
- fun main () {
31
- val jsonData: Map <String , Any > =
32
- mapOf (
33
- " myobject" to
34
- mapOf (
35
- " participantId" to " \$ {someTemlateVal}" ,
36
- " actAs" to listOf (" \$ {templateVal1}, \$ {templateVal2}" ),
37
- " readAs" to listOf (" \$ {templateVal2}" ),
38
- ),
39
- " myobject2" to " someValue" ,
40
- )
41
-
42
- val templates =
43
- mapOf (
44
- " someTemlateVal" to " participant123" ,
45
- " templateVal1" to " actor123" ,
46
- " templateVal2" to " reader123" ,
47
- )
48
-
49
- val replacedData = jsonData.replaceValues(templates)
50
- println (replacedData)
51
- }
52
-
53
- /* fun replaceTemplates(data: Map<String, Any>, templates: Map<String, String>): Map<String, Any> {
54
- fun replaceValue(value: Any): Any {
55
- return when (value) {
56
- is String -> replaceTemplateString(value, templates)
57
- is List<*> -> value.map { replaceValue(it) }
58
- is Map<*, *> -> value.mapValues { replaceValue(it.value) }
59
- else -> value
60
- }
61
- }
62
-
63
- fun replaceTemplateString(value: String, templates: Map<String, String>): String {
64
- val regex = Regex("""\$\{(\w+)\}""")
65
- return regex.replace(value) { matchResult ->
66
- val key = matchResult.groupValues[1]
67
- templates[key] ?: matchResult.value
68
- }
69
- }
70
-
71
- return data.mapValues { replaceValue(it.value) }
72
- }*/
73
28
}
0 commit comments