fix lint warnings

This commit is contained in:
davotoula
2025-12-02 12:57:56 +01:00
parent 24bd1d0c97
commit 70b36d64b5
@@ -20,6 +20,7 @@
*/ */
package com.vitorpamplona.quartz.nip11RelayInfo package com.vitorpamplona.quartz.nip11RelayInfo
import com.vitorpamplona.quartz.utils.Log
import kotlinx.serialization.ExperimentalSerializationApi import kotlinx.serialization.ExperimentalSerializationApi
import kotlinx.serialization.KSerializer import kotlinx.serialization.KSerializer
import kotlinx.serialization.builtins.ListSerializer import kotlinx.serialization.builtins.ListSerializer
@@ -42,30 +43,30 @@ object FlexibleIntListSerializer : KSerializer<List<Int>?> {
override fun deserialize(decoder: Decoder): List<Int>? { override fun deserialize(decoder: Decoder): List<Int>? {
require(decoder is JsonDecoder) { "This serializer can only be used with Json format" } require(decoder is JsonDecoder) { "This serializer can only be used with Json format" }
val element = decoder.decodeJsonElement() return when (val element = decoder.decodeJsonElement()) {
return when {
// Handle JSON null // Handle JSON null
element is JsonNull -> null is JsonNull -> null
// Handle array format (spec-compliant): [1, 2, 3] // Handle array format (spec-compliant): [1, 2, 3]
element is JsonArray -> { is JsonArray -> {
element.mapNotNull { arrayElement -> element.mapNotNull { arrayElement ->
try { try {
arrayElement.jsonPrimitive.int arrayElement.jsonPrimitive.int
} catch (e: Exception) { } catch (e: Exception) {
// Skip elements that aren't valid integers (strings, booleans, floats, etc.) // Skip elements that aren't valid integers (strings, booleans, floats, etc.)
Log.w("FlexibleIntListSerializer", "Invalid element in array: $arrayElement", e)
null null
} }
} }
} }
// Handle single integer format (malformed but found in the wild): 1 // Handle single integer format (malformed but found in the wild): 1
element is JsonPrimitive && !element.isString -> { is JsonPrimitive if !element.isString -> {
try { try {
listOf(element.int) listOf(element.int)
} catch (e: Exception) { } catch (e: Exception) {
// Can't parse as integer (e.g., float, boolean), treat as missing data // Can't parse as integer (e.g., float, boolean), treat as missing data
Log.w("FlexibleIntListSerializer", "Invalid primitive: $element", e)
null null
} }
} }