From 36a40dda0ebb3c7d59b803d0c58c976f8ad2c170 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Tue, 21 May 2024 04:58:22 +0000 Subject: [PATCH 1/2] --- updated-dependencies: - dependency-name: com.google.code.gson:gson dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] --- abstractions/build.gradle | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/abstractions/build.gradle b/abstractions/build.gradle index a20ab04..de33a10 100644 --- a/abstractions/build.gradle +++ b/abstractions/build.gradle @@ -54,7 +54,7 @@ dependencies { api "androidx.legacy:legacy-preference-v14:1.0.0" api 'androidx.annotation:annotation:1.7.1' - api 'com.google.code.gson:gson:2.10.1' + api 'com.google.code.gson:gson:2.11.0' api 'com.squareup.okhttp3:okhttp:4.12.0' api 'com.squareup.okhttp3:logging-interceptor:4.12.0' api "org.jetbrains.kotlinx:kotlinx-coroutines-play-services:1.8.1" From 42e4b7675bfbbe5dce95822b2262f63d90124515 Mon Sep 17 00:00:00 2001 From: Seth Onyango Date: Tue, 21 May 2024 10:04:14 +0300 Subject: [PATCH 2/2] Refactor ISO8601DateAdapter class to remove unnecessary inheritance and improve readability --- .../tingle/api/adapters/ISO8601DateAdapter.kt | 27 ++++++++++++++----- 1 file changed, 20 insertions(+), 7 deletions(-) diff --git a/abstractions/src/main/java/software/tingle/api/adapters/ISO8601DateAdapter.kt b/abstractions/src/main/java/software/tingle/api/adapters/ISO8601DateAdapter.kt index a9ebebd..c51edea 100644 --- a/abstractions/src/main/java/software/tingle/api/adapters/ISO8601DateAdapter.kt +++ b/abstractions/src/main/java/software/tingle/api/adapters/ISO8601DateAdapter.kt @@ -1,23 +1,32 @@ package software.tingle.api.adapters -import com.google.gson.* +import com.google.gson.JsonDeserializationContext +import com.google.gson.JsonDeserializer +import com.google.gson.JsonElement +import com.google.gson.JsonPrimitive +import com.google.gson.JsonSerializationContext +import com.google.gson.JsonSerializer import com.google.gson.internal.bind.util.ISO8601Utils import java.lang.reflect.Type import java.text.ParseException import java.text.ParsePosition -import java.util.* +import java.util.Date /** * A @[JsonDeserializer] that (de)serializes a @[Date] in ISO8601. * Internally it utilizes @[ISO8601Utils] which is ported from Jackson databind */ -class ISO8601DateAdapter : ISO8601Utils(), JsonDeserializer, JsonSerializer { +class ISO8601DateAdapter : JsonDeserializer, JsonSerializer { @Synchronized - override fun deserialize(jsonElement: JsonElement, type: Type, jsonDeserializationContext: JsonDeserializationContext): Date? { + override fun deserialize( + jsonElement: JsonElement, + type: Type, + jsonDeserializationContext: JsonDeserializationContext + ): Date? { return try { - parse(jsonElement.asString, ParsePosition(0)) + ISO8601Utils.parse(jsonElement.asString, ParsePosition(0)) } catch (e: ParseException) { e.printStackTrace() null @@ -25,7 +34,11 @@ class ISO8601DateAdapter : ISO8601Utils(), JsonDeserializer, JsonSerialize } - override fun serialize(date: Date, type: Type, jsonSerializationContext: JsonSerializationContext): JsonElement { - return JsonPrimitive(format(date)) + override fun serialize( + date: Date, + type: Type, + jsonSerializationContext: JsonSerializationContext + ): JsonElement { + return JsonPrimitive(ISO8601Utils.format(date)) } } \ No newline at end of file