aboutsummaryrefslogtreecommitdiff
path: root/core/src/main
diff options
context:
space:
mode:
authorIgnat Beresnev <ignat@beresnev.me>2022-01-19 08:32:49 +0300
committerGitHub <noreply@github.com>2022-01-19 08:32:49 +0300
commitcdebe4038580564fc45ef507303c334b94fbb7eb (patch)
treeab6e44301850ef202a41877555fb89762d899063 /core/src/main
parent2986661d784f1f37036c98f881ce8aa214c4f247 (diff)
downloaddokka-cdebe4038580564fc45ef507303c334b94fbb7eb.tar.gz
dokka-cdebe4038580564fc45ef507303c334b94fbb7eb.tar.bz2
dokka-cdebe4038580564fc45ef507303c334b94fbb7eb.zip
Reuse `ObjectMapper` (#2315)
* Reuse `ObjectMapper`
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")