From 68cba1e81a6bc971e0cd0be535232cc99756cd81 Mon Sep 17 00:00:00 2001 From: "sebastian.sellmair" Date: Mon, 20 Jul 2020 09:39:50 +0200 Subject: Align json representation of filepaths --- core/src/main/kotlin/utilities/json.kt | 26 ++++++++++++++++++-------- 1 file changed, 18 insertions(+), 8 deletions(-) (limited to 'core/src/main/kotlin') diff --git a/core/src/main/kotlin/utilities/json.kt b/core/src/main/kotlin/utilities/json.kt index d2e70d75..2096879a 100644 --- a/core/src/main/kotlin/utilities/json.kt +++ b/core/src/main/kotlin/utilities/json.kt @@ -1,19 +1,26 @@ package org.jetbrains.dokka.utilities import com.fasterxml.jackson.core.JsonGenerator -import com.fasterxml.jackson.databind.* -import com.fasterxml.jackson.databind.jsonFormatVisitors.JsonFormatVisitorWrapper +import com.fasterxml.jackson.core.JsonParser +import com.fasterxml.jackson.databind.DeserializationContext +import com.fasterxml.jackson.databind.DeserializationFeature +import com.fasterxml.jackson.databind.SerializerProvider +import com.fasterxml.jackson.databind.deser.std.StdScalarDeserializer import com.fasterxml.jackson.databind.module.SimpleModule import com.fasterxml.jackson.databind.ser.std.StdScalarSerializer import com.fasterxml.jackson.module.kotlin.jacksonObjectMapper import com.fasterxml.jackson.module.kotlin.jacksonTypeRef +import org.jetbrains.dokka.DokkaConfiguration.SourceRoot +import org.jetbrains.dokka.SourceRootImpl import java.io.File -import java.lang.reflect.Type import com.fasterxml.jackson.core.type.TypeReference as JacksonTypeReference private val objectMapper = run { val module = SimpleModule().apply { addSerializer(FileSerializer) + addSerializer(SourceRoot::class.java, SourceRootSerializer) + addDeserializer(SourceRootImpl::class.java, SourceRootImplDeserializer) + addDeserializer(SourceRoot::class.java, SourceRootImplDeserializer) } jacksonObjectMapper() .registerModule(module) @@ -47,13 +54,16 @@ private object FileSerializer : StdScalarSerializer(File::class.java) { override fun serialize(value: File, g: JsonGenerator, provider: SerializerProvider) { g.writeString(value.path) } +} - override fun getSchema(provider: SerializerProvider, typeHint: Type): JsonNode { - return createSchemaNode("string", true) +private object SourceRootSerializer : StdScalarSerializer(SourceRoot::class.java) { + override fun serialize(value: SourceRoot, g: JsonGenerator, provider: SerializerProvider) { + g.writeString(value.path) } +} - @Throws(JsonMappingException::class) - override fun acceptJsonFormatVisitor(visitor: JsonFormatVisitorWrapper, typeHint: JavaType) { - visitStringFormat(visitor, typeHint) +private object SourceRootImplDeserializer : StdScalarDeserializer(SourceRootImpl::class.java) { + override fun deserialize(p: JsonParser, ctxt: DeserializationContext): SourceRootImpl { + return SourceRootImpl(p.text) } } -- cgit