aboutsummaryrefslogtreecommitdiff
path: root/core/src/main
diff options
context:
space:
mode:
Diffstat (limited to 'core/src/main')
-rw-r--r--core/src/main/kotlin/links/DRI.kt9
1 files changed, 7 insertions, 2 deletions
diff --git a/core/src/main/kotlin/links/DRI.kt b/core/src/main/kotlin/links/DRI.kt
index c646934d..2cbae8cc 100644
--- a/core/src/main/kotlin/links/DRI.kt
+++ b/core/src/main/kotlin/links/DRI.kt
@@ -33,15 +33,20 @@ abstract class DRIExtraProperty<T> {
?: (this.javaClass.let { it.`package`.name + "." + it.simpleName.ifEmpty { "anonymous" } })
}
+
class DRIExtraContainer(val data: String? = null) {
- val map: MutableMap<String, Any> = if (data != null) ObjectMapper().readValue(data) else mutableMapOf()
+ val map: MutableMap<String, Any> = if (data != null) OBJECT_MAPPER.readValue(data) else mutableMapOf()
inline operator fun <reified T> get(prop: DRIExtraProperty<T>): T? =
map[prop.key]?.let { prop as? T }
inline operator fun <reified T> set(prop: DRIExtraProperty<T>, value: T) =
value.also { map[prop.key] = it as Any }
- fun encode(): String = ObjectMapper().writeValueAsString(map)
+ fun encode(): String = OBJECT_MAPPER.writeValueAsString(map)
+
+ private companion object {
+ private val OBJECT_MAPPER = ObjectMapper()
+ }
}
val DriOfUnit = DRI("kotlin", "Unit")