From 26803fd6f6499445a4c842a4c2ef3c361f952d90 Mon Sep 17 00:00:00 2001 From: Vladimir Shefer Date: Mon, 17 Aug 2020 11:21:59 +0300 Subject: [PATCH 1/2] Replace .typeName with .simpleName. Method .typeName available since 28 api level, when 21+ api is used --- KotlinOutputFiles/DateFactory.kt | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/KotlinOutputFiles/DateFactory.kt b/KotlinOutputFiles/DateFactory.kt index 165eca2..c6e44d4 100644 --- a/KotlinOutputFiles/DateFactory.kt +++ b/KotlinOutputFiles/DateFactory.kt @@ -7,9 +7,14 @@ import java.lang.reflect.Type class DateFactory : JsonAdapter.Factory { override fun create(type: Type, annotations: MutableSet, moshi: Moshi): JsonAdapter<*>? { - return when (type.typeName) { - DateTime::class.java.typeName -> DateTimeJsonAdapter(getPatterns(annotations)) - LocalDate::class.java.typeName -> LocalDateJsonAdapter(getPatterns(annotations)) + val typeName = when(type) { + is Class<*> -> type.canonicalName + else -> type.toString() + } + + return when (typeName) { + DateTime::class.java.canonicalName -> DateTimeJsonAdapter(getPatterns(annotations)) + LocalDate::class.java.canonicalName -> LocalDateJsonAdapter(getPatterns(annotations)) else -> null } } From 6213910a50de98b1b1fadaec504646c816f27369 Mon Sep 17 00:00:00 2001 From: Vladimir Shefer Date: Mon, 17 Aug 2020 11:29:43 +0300 Subject: [PATCH 2/2] Replace MutableSet with Set parameter --- KotlinOutputFiles/DateFactory.kt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/KotlinOutputFiles/DateFactory.kt b/KotlinOutputFiles/DateFactory.kt index c6e44d4..1f719f5 100644 --- a/KotlinOutputFiles/DateFactory.kt +++ b/KotlinOutputFiles/DateFactory.kt @@ -6,7 +6,7 @@ import java.lang.reflect.Type class DateFactory : JsonAdapter.Factory { - override fun create(type: Type, annotations: MutableSet, moshi: Moshi): JsonAdapter<*>? { + override fun create(type: Type, annotations: Set, moshi: Moshi): JsonAdapter<*>? { val typeName = when(type) { is Class<*> -> type.canonicalName else -> type.toString() @@ -19,7 +19,7 @@ class DateFactory : JsonAdapter.Factory { } } - private fun getPatterns(annotations: MutableSet) = annotations + private fun getPatterns(annotations: Set) = annotations .map { it as? Format } .firstOrNull() ?.patterns