fix Jackson deserialization for empty Filters and add regression test

This commit is contained in:
greenart7c3
2026-01-30 07:31:38 -03:00
parent 85e9984153
commit 247e30beed
2 changed files with 16 additions and 7 deletions
@@ -52,15 +52,15 @@ class ManualFilterDeserializer {
}
return Filter(
ids = jsonObject.get("ids").mapNotNull { it.asTextOrNull() },
authors = jsonObject.get("authors").mapNotNull { it.asTextOrNull() },
kinds = jsonObject.get("kinds").mapNotNull { it.asIntOrNull() },
ids = jsonObject.get("ids")?.mapNotNull { it.asTextOrNull() },
authors = jsonObject.get("authors")?.mapNotNull { it.asTextOrNull() },
kinds = jsonObject.get("kinds")?.mapNotNull { it.asIntOrNull() },
tags = tagsIn.associateWith { jsonObject.get(it).mapNotNull { it.asTextOrNull() } },
tagsAll = tagsAll.associateWith { jsonObject.get(it).mapNotNull { it.asTextOrNull() } },
since = jsonObject.get("since").asLongOrNull(),
until = jsonObject.get("until").asLongOrNull(),
limit = jsonObject.get("limit").asIntOrNull(),
search = jsonObject.get("search").asTextOrNull(),
since = jsonObject.get("since")?.asLongOrNull(),
until = jsonObject.get("until")?.asLongOrNull(),
limit = jsonObject.get("limit")?.asIntOrNull(),
search = jsonObject.get("search")?.asTextOrNull(),
)
}
}
@@ -21,6 +21,7 @@
package com.vitorpamplona.quartz.nip01Core.jackson
import com.vitorpamplona.quartz.nip01Core.core.Event
import com.vitorpamplona.quartz.nip01Core.relay.filters.Filter
import com.vitorpamplona.quartz.nip01Core.signers.EventTemplate
import com.vitorpamplona.quartz.nip51Lists.followList.FollowListEvent
import com.vitorpamplona.quartz.nip59Giftwrap.rumors.Rumor
@@ -152,4 +153,12 @@ class JacksonMapperTest {
assertContentEquals(tag, deserialized.tags[index])
}
}
@Test
fun shouldNotThrowExceptionWhenDeserializingEmptyFilter() {
val json = Filter().toJson()
val deserialized = JacksonMapper.fromJsonTo<Filter>(json)
assertEquals(deserialized.ids, null)
}
}