Skip to content

Commit b08773b

Browse files
fix unknown type fallback serialization of empty feature collection (#286)
Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
1 parent ed11992 commit b08773b

File tree

2 files changed

+17
-1
lines changed

2 files changed

+17
-1
lines changed

geojson/src/commonMain/kotlin/org/maplibre/spatialk/geojson/GeoJson.kt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,9 @@ public data object GeoJson {
5252
is FeatureCollection<*, *> ->
5353
FeatureCollection.serializer(
5454
Geometry.serializer().nullable,
55-
when (val props = obj.features.firstNotNullOf { it.properties }) {
55+
when (
56+
val props = obj.features.firstNotNullOfOrNull { it.properties }
57+
) {
5658
is JsonObject? -> JsonObject.serializer().nullable
5759
else -> {
5860
@OptIn(InternalSerializationApi::class)

geojson/src/commonTest/kotlin/org/maplibre/spatialk/geojson/FeatureCollectionTest.kt

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -404,6 +404,20 @@ class FeatureCollectionTest {
404404
}
405405
}
406406

407+
@Test
408+
fun emptyStarProjection() {
409+
// should fall back to JsonObject properties
410+
val features: FeatureCollection<*, *> = featureCollectionOf()
411+
val json =
412+
"""
413+
{
414+
"type": "FeatureCollection",
415+
"features": []
416+
}
417+
"""
418+
assertJsonEquals(json, features.toJson())
419+
}
420+
407421
companion object {
408422
private const val SAMPLE_FEATURECOLLECTION = "sample-featurecollection.json"
409423
private const val SAMPLE_FEATURECOLLECTION_BBOX = "sample-feature-collection-with-bbox.json"

0 commit comments

Comments
 (0)