diff options
author | sebastian.sellmair <sebastian.sellmair@jetbrains.com> | 2020-07-20 09:39:50 +0200 |
---|---|---|
committer | Sebastian Sellmair <34319766+sellmair@users.noreply.github.com> | 2020-07-20 12:02:45 +0200 |
commit | 68cba1e81a6bc971e0cd0be535232cc99756cd81 (patch) | |
tree | 6e78aa1aecac8d718c42db926a2ac1bd0ce402f6 /core/src | |
parent | 13edb873db122e2088207ca10b94382e30875636 (diff) | |
download | dokka-68cba1e81a6bc971e0cd0be535232cc99756cd81.tar.gz dokka-68cba1e81a6bc971e0cd0be535232cc99756cd81.tar.bz2 dokka-68cba1e81a6bc971e0cd0be535232cc99756cd81.zip |
Align json representation of filepaths
Diffstat (limited to 'core/src')
-rw-r--r-- | core/src/main/kotlin/utilities/json.kt | 26 | ||||
-rw-r--r-- | core/src/test/kotlin/utilities/DokkaConfigurationJsonTest.kt | 11 |
2 files changed, 22 insertions, 15 deletions
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>(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>(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>(SourceRootImpl::class.java) { + override fun deserialize(p: JsonParser, ctxt: DeserializationContext): SourceRootImpl { + return SourceRootImpl(p.text) } } diff --git a/core/src/test/kotlin/utilities/DokkaConfigurationJsonTest.kt b/core/src/test/kotlin/utilities/DokkaConfigurationJsonTest.kt index d0cb55a1..e954c82c 100644 --- a/core/src/test/kotlin/utilities/DokkaConfigurationJsonTest.kt +++ b/core/src/test/kotlin/utilities/DokkaConfigurationJsonTest.kt @@ -38,12 +38,8 @@ class DokkaConfigurationJsonTest { "moduleName": "customModuleName", "sourceSetName": "customSourceSetName" }, - "classpath": [], - "sourceRoots": [ - { - "path": "customSourceRoot" - } - ] + "sourceRoots": [ "customSourceRoot" ], + "classpath": [ "classpath/custom1.jar", "classpath/custom2.jar" ] } ] } @@ -58,7 +54,8 @@ class DokkaConfigurationJsonTest { DokkaSourceSetImpl( moduleDisplayName = "customModuleDisplayName", sourceRoots = listOf(SourceRootImpl("customSourceRoot")), - sourceSetID = DokkaSourceSetID("customModuleName", "customSourceSetName") + sourceSetID = DokkaSourceSetID("customModuleName", "customSourceSetName"), + classpath = listOf("classpath/custom1.jar", "classpath/custom2.jar") ) ) ), |