Skip to content
This repository has been archived by the owner on Dec 25, 2024. It is now read-only.

Commit

Permalink
Merge pull request #118 from tinglesoftware/dependabot/gradle/com.goo…
Browse files Browse the repository at this point in the history
…gle.code.gson-gson-2.11.0

Bump com.google.code.gson:gson from 2.10.1 to 2.11.0
  • Loading branch information
sethonyango authored May 21, 2024
2 parents 1e5e7cb + 42e4b76 commit f737871
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 8 deletions.
2 changes: 1 addition & 1 deletion abstractions/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,31 +1,44 @@
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<Date>, JsonSerializer<Date> {
class ISO8601DateAdapter : JsonDeserializer<Date>, JsonSerializer<Date> {

@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
}

}

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))
}
}

0 comments on commit f737871

Please sign in to comment.