Skip to content

Commit 8259a8c

Browse files
authored
breaking: Feature.id is a JsonPrimitive to support numbers and strings (#274)
1 parent f6fbc08 commit 8259a8c

File tree

13 files changed

+1124
-22
lines changed

13 files changed

+1124
-22
lines changed

geojson/api/geojson.api

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -36,24 +36,24 @@ public final class org/maplibre/spatialk/geojson/BoundingBox$Companion {
3636
public final class org/maplibre/spatialk/geojson/Feature : org/maplibre/spatialk/geojson/GeoJsonObject {
3737
public static final field Companion Lorg/maplibre/spatialk/geojson/Feature$Companion;
3838
public fun <init> (Lorg/maplibre/spatialk/geojson/Geometry;Ljava/lang/Object;)V
39-
public fun <init> (Lorg/maplibre/spatialk/geojson/Geometry;Ljava/lang/Object;Ljava/lang/String;)V
40-
public fun <init> (Lorg/maplibre/spatialk/geojson/Geometry;Ljava/lang/Object;Ljava/lang/String;Lorg/maplibre/spatialk/geojson/BoundingBox;)V
41-
public synthetic fun <init> (Lorg/maplibre/spatialk/geojson/Geometry;Ljava/lang/Object;Ljava/lang/String;Lorg/maplibre/spatialk/geojson/BoundingBox;ILkotlin/jvm/internal/DefaultConstructorMarker;)V
39+
public fun <init> (Lorg/maplibre/spatialk/geojson/Geometry;Ljava/lang/Object;Lkotlinx/serialization/json/JsonPrimitive;)V
40+
public fun <init> (Lorg/maplibre/spatialk/geojson/Geometry;Ljava/lang/Object;Lkotlinx/serialization/json/JsonPrimitive;Lorg/maplibre/spatialk/geojson/BoundingBox;)V
41+
public synthetic fun <init> (Lorg/maplibre/spatialk/geojson/Geometry;Ljava/lang/Object;Lkotlinx/serialization/json/JsonPrimitive;Lorg/maplibre/spatialk/geojson/BoundingBox;ILkotlin/jvm/internal/DefaultConstructorMarker;)V
4242
public final fun component1 ()Lorg/maplibre/spatialk/geojson/Geometry;
4343
public final fun component2 ()Ljava/lang/Object;
44-
public final fun component3 ()Ljava/lang/String;
44+
public final fun component3 ()Lkotlinx/serialization/json/JsonPrimitive;
4545
public final fun component4 ()Lorg/maplibre/spatialk/geojson/BoundingBox;
4646
public static final fun containsProperty (Lorg/maplibre/spatialk/geojson/Feature;Ljava/lang/String;)Z
47-
public final fun copy (Lorg/maplibre/spatialk/geojson/Geometry;Ljava/lang/Object;Ljava/lang/String;Lorg/maplibre/spatialk/geojson/BoundingBox;)Lorg/maplibre/spatialk/geojson/Feature;
48-
public static synthetic fun copy$default (Lorg/maplibre/spatialk/geojson/Feature;Lorg/maplibre/spatialk/geojson/Geometry;Ljava/lang/Object;Ljava/lang/String;Lorg/maplibre/spatialk/geojson/BoundingBox;ILjava/lang/Object;)Lorg/maplibre/spatialk/geojson/Feature;
47+
public final fun copy (Lorg/maplibre/spatialk/geojson/Geometry;Ljava/lang/Object;Lkotlinx/serialization/json/JsonPrimitive;Lorg/maplibre/spatialk/geojson/BoundingBox;)Lorg/maplibre/spatialk/geojson/Feature;
48+
public static synthetic fun copy$default (Lorg/maplibre/spatialk/geojson/Feature;Lorg/maplibre/spatialk/geojson/Geometry;Ljava/lang/Object;Lkotlinx/serialization/json/JsonPrimitive;Lorg/maplibre/spatialk/geojson/BoundingBox;ILjava/lang/Object;)Lorg/maplibre/spatialk/geojson/Feature;
4949
public fun equals (Ljava/lang/Object;)Z
5050
public static final fun fromJson (Ljava/lang/String;)Lorg/maplibre/spatialk/geojson/Feature;
5151
public static final fun fromJsonOrNull (Ljava/lang/String;)Lorg/maplibre/spatialk/geojson/Feature;
5252
public fun getBbox ()Lorg/maplibre/spatialk/geojson/BoundingBox;
5353
public static final fun getBooleanProperty (Lorg/maplibre/spatialk/geojson/Feature;Ljava/lang/String;)Ljava/lang/Boolean;
5454
public static final fun getDoubleProperty (Lorg/maplibre/spatialk/geojson/Feature;Ljava/lang/String;)Ljava/lang/Double;
5555
public final fun getGeometry ()Lorg/maplibre/spatialk/geojson/Geometry;
56-
public final fun getId ()Ljava/lang/String;
56+
public final fun getId ()Lkotlinx/serialization/json/JsonPrimitive;
5757
public static final fun getIntProperty (Lorg/maplibre/spatialk/geojson/Feature;Ljava/lang/String;)Ljava/lang/Integer;
5858
public final fun getProperties ()Ljava/lang/Object;
5959
public static final fun getStringProperty (Lorg/maplibre/spatialk/geojson/Feature;Ljava/lang/String;)Ljava/lang/String;
@@ -584,11 +584,14 @@ public final class org/maplibre/spatialk/geojson/dsl/FeatureBuilder {
584584
public final fun build ()Lorg/maplibre/spatialk/geojson/Feature;
585585
public final fun getBbox ()Lorg/maplibre/spatialk/geojson/BoundingBox;
586586
public final fun getGeometry ()Lorg/maplibre/spatialk/geojson/Geometry;
587-
public final fun getId ()Ljava/lang/String;
587+
public final fun getId ()Lkotlinx/serialization/json/JsonPrimitive;
588588
public final fun getProperties ()Ljava/lang/Object;
589589
public final fun setBbox (Lorg/maplibre/spatialk/geojson/BoundingBox;)V
590590
public final fun setGeometry (Lorg/maplibre/spatialk/geojson/Geometry;)V
591+
public final fun setId (D)V
592+
public final fun setId (J)V
591593
public final fun setId (Ljava/lang/String;)V
594+
public final fun setId (Lkotlinx/serialization/json/JsonPrimitive;)V
592595
public final fun setProperties (Ljava/lang/Object;)V
593596
}
594597

geojson/api/geojson.klib.api

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -104,13 +104,16 @@ final class <#A: org.maplibre.spatialk.geojson/Geometry?, #B: kotlin/Any?> org.m
104104
final fun <get-geometry>(): #A // org.maplibre.spatialk.geojson.dsl/FeatureBuilder.geometry.<get-geometry>|<get-geometry>(){}[0]
105105
final fun <set-geometry>(#A) // org.maplibre.spatialk.geojson.dsl/FeatureBuilder.geometry.<set-geometry>|<set-geometry>(1:0){}[0]
106106
final var id // org.maplibre.spatialk.geojson.dsl/FeatureBuilder.id|{}id[0]
107-
final fun <get-id>(): kotlin/String? // org.maplibre.spatialk.geojson.dsl/FeatureBuilder.id.<get-id>|<get-id>(){}[0]
108-
final fun <set-id>(kotlin/String?) // org.maplibre.spatialk.geojson.dsl/FeatureBuilder.id.<set-id>|<set-id>(kotlin.String?){}[0]
107+
final fun <get-id>(): kotlinx.serialization.json/JsonPrimitive? // org.maplibre.spatialk.geojson.dsl/FeatureBuilder.id.<get-id>|<get-id>(){}[0]
108+
final fun <set-id>(kotlinx.serialization.json/JsonPrimitive?) // org.maplibre.spatialk.geojson.dsl/FeatureBuilder.id.<set-id>|<set-id>(kotlinx.serialization.json.JsonPrimitive?){}[0]
109109
final var properties // org.maplibre.spatialk.geojson.dsl/FeatureBuilder.properties|{}properties[0]
110110
final fun <get-properties>(): #B // org.maplibre.spatialk.geojson.dsl/FeatureBuilder.properties.<get-properties>|<get-properties>(){}[0]
111111
final fun <set-properties>(#B) // org.maplibre.spatialk.geojson.dsl/FeatureBuilder.properties.<set-properties>|<set-properties>(1:1){}[0]
112112

113113
final fun build(): org.maplibre.spatialk.geojson/Feature<#A, #B> // org.maplibre.spatialk.geojson.dsl/FeatureBuilder.build|build(){}[0]
114+
final fun setId(kotlin/Double) // org.maplibre.spatialk.geojson.dsl/FeatureBuilder.setId|setId(kotlin.Double){}[0]
115+
final fun setId(kotlin/Long) // org.maplibre.spatialk.geojson.dsl/FeatureBuilder.setId|setId(kotlin.Long){}[0]
116+
final fun setId(kotlin/String) // org.maplibre.spatialk.geojson.dsl/FeatureBuilder.setId|setId(kotlin.String){}[0]
114117
}
115118

116119
final class <#A: org.maplibre.spatialk.geojson/Geometry?, #B: kotlin/Any?> org.maplibre.spatialk.geojson.dsl/FeatureCollectionBuilder { // org.maplibre.spatialk.geojson.dsl/FeatureCollectionBuilder|null[0]
@@ -158,22 +161,22 @@ final class <#A: out org.maplibre.spatialk.geojson/Geometry> org.maplibre.spatia
158161
}
159162

160163
final class <#A: out org.maplibre.spatialk.geojson/Geometry?, #B: out kotlin/Any?> org.maplibre.spatialk.geojson/Feature : org.maplibre.spatialk.geojson/GeoJsonObject { // org.maplibre.spatialk.geojson/Feature|null[0]
161-
constructor <init>(#A, #B, kotlin/String? = ..., org.maplibre.spatialk.geojson/BoundingBox? = ...) // org.maplibre.spatialk.geojson/Feature.<init>|<init>(1:0;1:1;kotlin.String?;org.maplibre.spatialk.geojson.BoundingBox?){}[0]
164+
constructor <init>(#A, #B, kotlinx.serialization.json/JsonPrimitive? = ..., org.maplibre.spatialk.geojson/BoundingBox? = ...) // org.maplibre.spatialk.geojson/Feature.<init>|<init>(1:0;1:1;kotlinx.serialization.json.JsonPrimitive?;org.maplibre.spatialk.geojson.BoundingBox?){}[0]
162165

163166
final val bbox // org.maplibre.spatialk.geojson/Feature.bbox|{}bbox[0]
164167
final fun <get-bbox>(): org.maplibre.spatialk.geojson/BoundingBox? // org.maplibre.spatialk.geojson/Feature.bbox.<get-bbox>|<get-bbox>(){}[0]
165168
final val geometry // org.maplibre.spatialk.geojson/Feature.geometry|{}geometry[0]
166169
final fun <get-geometry>(): #A // org.maplibre.spatialk.geojson/Feature.geometry.<get-geometry>|<get-geometry>(){}[0]
167170
final val id // org.maplibre.spatialk.geojson/Feature.id|{}id[0]
168-
final fun <get-id>(): kotlin/String? // org.maplibre.spatialk.geojson/Feature.id.<get-id>|<get-id>(){}[0]
171+
final fun <get-id>(): kotlinx.serialization.json/JsonPrimitive? // org.maplibre.spatialk.geojson/Feature.id.<get-id>|<get-id>(){}[0]
169172
final val properties // org.maplibre.spatialk.geojson/Feature.properties|{}properties[0]
170173
final fun <get-properties>(): #B // org.maplibre.spatialk.geojson/Feature.properties.<get-properties>|<get-properties>(){}[0]
171174

172175
final fun component1(): #A // org.maplibre.spatialk.geojson/Feature.component1|component1(){}[0]
173176
final fun component2(): #B // org.maplibre.spatialk.geojson/Feature.component2|component2(){}[0]
174-
final fun component3(): kotlin/String? // org.maplibre.spatialk.geojson/Feature.component3|component3(){}[0]
177+
final fun component3(): kotlinx.serialization.json/JsonPrimitive? // org.maplibre.spatialk.geojson/Feature.component3|component3(){}[0]
175178
final fun component4(): org.maplibre.spatialk.geojson/BoundingBox? // org.maplibre.spatialk.geojson/Feature.component4|component4(){}[0]
176-
final fun copy(#A = ..., #B = ..., kotlin/String? = ..., org.maplibre.spatialk.geojson/BoundingBox? = ...): org.maplibre.spatialk.geojson/Feature<#A, #B> // org.maplibre.spatialk.geojson/Feature.copy|copy(1:0;1:1;kotlin.String?;org.maplibre.spatialk.geojson.BoundingBox?){}[0]
179+
final fun copy(#A = ..., #B = ..., kotlinx.serialization.json/JsonPrimitive? = ..., org.maplibre.spatialk.geojson/BoundingBox? = ...): org.maplibre.spatialk.geojson/Feature<#A, #B> // org.maplibre.spatialk.geojson/Feature.copy|copy(1:0;1:1;kotlinx.serialization.json.JsonPrimitive?;org.maplibre.spatialk.geojson.BoundingBox?){}[0]
177180
final fun equals(kotlin/Any?): kotlin/Boolean // org.maplibre.spatialk.geojson/Feature.equals|equals(kotlin.Any?){}[0]
178181
final fun hashCode(): kotlin/Int // org.maplibre.spatialk.geojson/Feature.hashCode|hashCode(){}[0]
179182
final fun toString(): kotlin/String // org.maplibre.spatialk.geojson/Feature.toString|toString(){}[0]

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

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ import org.maplibre.spatialk.geojson.serialization.FeatureSerializer
2727
* @property geometry A [Geometry] object contained within the [Feature].
2828
* @property properties Additional properties about this [Feature]. It should be serializable into a
2929
* [JsonObject].
30-
* @property id An optionally included string that commonly identifies this [Feature].
30+
* @property id An optionally included string or number that commonly identifies this [Feature].
3131
* @see FeatureCollection
3232
*/
3333
@Serializable(with = FeatureSerializer::class)
@@ -36,12 +36,20 @@ public data class Feature<out G : Geometry?, out P : @Serializable Any?>
3636
constructor(
3737
public val geometry: G,
3838
public val properties: P,
39-
public val id: String? = null,
39+
public val id: FeatureId? = null,
4040
override val bbox: BoundingBox? = null,
4141
) : GeoJsonObject {
4242

43+
init {
44+
require(id == null || id.isString || id.content.matches(numberRegex)) {
45+
"Feature.id must be a string or a base-10 number; got $id"
46+
}
47+
}
48+
4349
/** Factory methods for creating and serializing [Feature] objects. */
4450
public companion object {
51+
private val numberRegex = Regex("""^-?\d+(\.\d+)?$""")
52+
4553
/**
4654
* Deserializes a [Feature] from a JSON string.
4755
*
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
package org.maplibre.spatialk.geojson
2+
3+
import kotlinx.serialization.Serializable
4+
import kotlinx.serialization.json.JsonPrimitive
5+
import org.maplibre.spatialk.geojson.serialization.FeatureIdSerializer
6+
7+
/**
8+
* Represents the identifier for a GeoJSON Feature. According to the GeoJSON specification, a
9+
* Feature may have an identifier that can be a string or number.
10+
*
11+
* When serializing to/from a non-JSON format, the identifier will be serialized as a string,
12+
* including quotes if it's not a number.
13+
*/
14+
public typealias FeatureId = @Serializable(with = FeatureIdSerializer::class) JsonPrimitive

geojson/src/commonMain/kotlin/org/maplibre/spatialk/geojson/dsl/FeatureBuilder.kt

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,10 @@ package org.maplibre.spatialk.geojson.dsl
22

33
import kotlinx.serialization.Serializable
44
import kotlinx.serialization.json.JsonObject
5+
import kotlinx.serialization.json.JsonPrimitive
56
import org.maplibre.spatialk.geojson.BoundingBox
67
import org.maplibre.spatialk.geojson.Feature
8+
import org.maplibre.spatialk.geojson.FeatureId
79
import org.maplibre.spatialk.geojson.Geometry
810

911
/**
@@ -25,9 +27,36 @@ public class FeatureBuilder<G : Geometry?, P : @Serializable Any?>(
2527
public var geometry: G,
2628
public var properties: P,
2729
) {
28-
public var id: String? = null
30+
public var id: FeatureId? = null
2931
public var bbox: BoundingBox? = null
3032

33+
/**
34+
* Sets the Feature identifier using a string value.
35+
*
36+
* @param value The string identifier value.
37+
*/
38+
public fun setId(value: String) {
39+
this.id = JsonPrimitive(value)
40+
}
41+
42+
/**
43+
* Sets the Feature identifier using a long value.
44+
*
45+
* @param value The long integer identifier value.
46+
*/
47+
public fun setId(value: Long) {
48+
this.id = JsonPrimitive(value)
49+
}
50+
51+
/**
52+
* Sets the Feature identifier using a double value.
53+
*
54+
* @param value The double identifier value.
55+
*/
56+
public fun setId(value: Double) {
57+
this.id = JsonPrimitive(value)
58+
}
59+
3160
/**
3261
* Builds the [Feature] from the configured values.
3362
*
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
package org.maplibre.spatialk.geojson.serialization
2+
3+
import kotlinx.serialization.KSerializer
4+
import kotlinx.serialization.descriptors.SerialDescriptor
5+
import kotlinx.serialization.encoding.Decoder
6+
import kotlinx.serialization.encoding.Encoder
7+
import kotlinx.serialization.json.Json
8+
import kotlinx.serialization.json.JsonDecoder
9+
import kotlinx.serialization.json.JsonEncoder
10+
import kotlinx.serialization.json.JsonPrimitive
11+
import org.maplibre.spatialk.geojson.FeatureId
12+
13+
internal object FeatureIdSerializer : KSerializer<FeatureId> {
14+
private val jsonDelegate = JsonPrimitive.serializer()
15+
16+
override val descriptor: SerialDescriptor = jsonDelegate.descriptor
17+
18+
override fun serialize(encoder: Encoder, value: FeatureId) =
19+
if (encoder is JsonEncoder) jsonDelegate.serialize(encoder, value)
20+
else encoder.encodeString(Json.encodeToString(value))
21+
22+
override fun deserialize(decoder: Decoder): FeatureId =
23+
if (decoder is JsonDecoder) jsonDelegate.deserialize(decoder)
24+
else Json.decodeFromString(jsonDelegate, decoder.decodeString())
25+
}

geojson/src/commonMain/kotlin/org/maplibre/spatialk/geojson/serialization/FeatureSerializer.kt

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ import kotlinx.serialization.encoding.encodeStructure
1818
import kotlinx.serialization.json.JsonEncoder
1919
import org.maplibre.spatialk.geojson.BoundingBox
2020
import org.maplibre.spatialk.geojson.Feature
21+
import org.maplibre.spatialk.geojson.FeatureId
2122
import org.maplibre.spatialk.geojson.Geometry
2223

2324
internal class FeatureSerializer<T : Geometry?, P : @Serializable Any?>(
@@ -27,7 +28,7 @@ internal class FeatureSerializer<T : Geometry?, P : @Serializable Any?>(
2728
private val serialName: String = "Feature"
2829
private val typeSerializer = String.serializer()
2930
private val bboxSerializer = BoundingBox.serializer().nullable
30-
private val idSerializer = String.serializer().nullable
31+
private val idSerializer = FeatureIdSerializer.nullable
3132

3233
// special sentinel for nullable values
3334
private val uninitialized = Any()
@@ -67,7 +68,7 @@ internal class FeatureSerializer<T : Geometry?, P : @Serializable Any?>(
6768
var bbox: BoundingBox? = null
6869
var geometry: Any? = uninitialized
6970
var properties: Any? = uninitialized
70-
var id: String? = null
71+
var id: FeatureId? = null
7172

7273
if (decodeSequentially()) {
7374
type = decodeSerializableElement(descriptor, 0, typeSerializer)

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

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -321,6 +321,69 @@ class FeatureTest {
321321
)
322322
}
323323

324+
@Test
325+
fun testIntegerId() {
326+
val numericIdJson =
327+
"""
328+
{
329+
"type": "Feature",
330+
"geometry": {
331+
"type": "Point",
332+
"coordinates": [125.6, 10.1]
333+
},
334+
"properties": null,
335+
"id": 123
336+
}
337+
"""
338+
.trimIndent()
339+
340+
val feature = Feature.fromJson<Point, Nothing?>(numericIdJson)
341+
assertEquals(JsonPrimitive(123L), feature.id)
342+
assertJsonEquals(numericIdJson, feature.toJson())
343+
}
344+
345+
@Test
346+
fun testFloatingId() {
347+
val numericIdJson =
348+
"""
349+
{
350+
"type": "Feature",
351+
"geometry": {
352+
"type": "Point",
353+
"coordinates": [125.6, 10.1]
354+
},
355+
"properties": null,
356+
"id": 123.45
357+
}
358+
"""
359+
.trimIndent()
360+
361+
val feature = Feature.fromJson<Point, Nothing?>(numericIdJson)
362+
assertEquals(JsonPrimitive(123.45), feature.id)
363+
assertJsonEquals(numericIdJson, feature.toJson())
364+
}
365+
366+
@Test
367+
fun testStringId() {
368+
val stringIdJson =
369+
"""
370+
{
371+
"type": "Feature",
372+
"geometry": {
373+
"type": "Point",
374+
"coordinates": [125.6, 10.1]
375+
},
376+
"properties": null,
377+
"id": "test-id"
378+
}
379+
"""
380+
.trimIndent()
381+
382+
val feature = Feature.fromJson<Point, Nothing?>(stringIdJson)
383+
assertEquals(JsonPrimitive("test-id"), feature.id)
384+
assertJsonEquals(stringIdJson, feature.toJson())
385+
}
386+
324387
@Test
325388
fun testNullGeometry() {
326389
val nullJson = """{"type": "Feature", "geometry": null, "properties": null}"""

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -686,7 +686,7 @@ class KotlinDocsTest {
686686
// --8<-- [start:dslFeatureKt]
687687
val feature =
688688
buildFeature(geometry = Point(-75.0, 45.0)) {
689-
id = "point1"
689+
setId("point1")
690690
bbox = BoundingBox(-76.9, 44.1, -74.2, 45.7)
691691
properties = buildJsonObject {
692692
put("name", "Hello World")

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

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import kotlinx.serialization.Serializable
99
import kotlinx.serialization.cbor.Cbor
1010
import kotlinx.serialization.decodeFromByteArray
1111
import kotlinx.serialization.encodeToByteArray
12+
import kotlinx.serialization.json.JsonPrimitive
1213
import kotlinx.serialization.protobuf.ProtoBuf
1314
import org.maplibre.spatialk.geojson.dsl.buildLineString
1415

@@ -32,8 +33,13 @@ class NonJsonFormatTest {
3233
private val testFeatureClassProps = Feature(testLineString, ExampleProps())
3334

3435
private val testFeatureCollectionNullProps = FeatureCollection(testFeatureNullProps)
36+
3537
private val testFeatureCollectionClassProps = FeatureCollection(testFeatureClassProps)
3638

39+
private val testFeatureIdString = Feature(null, null, id = JsonPrimitive("test-id"))
40+
private val testFeatureIdLong = Feature(null, null, id = JsonPrimitive(123L))
41+
private val testFeatureIdDouble = Feature(null, null, id = JsonPrimitive(123.45))
42+
3743
private inline fun <reified T> assertRoundTrip(format: BinaryFormat, value: T) {
3844
val encoded = format.encodeToByteArray(value)
3945
val decoded = format.decodeFromByteArray<T>(encoded)
@@ -53,6 +59,13 @@ class NonJsonFormatTest {
5359
@Test
5460
fun testCborFeatureCollectionProps() = assertRoundTrip(Cbor, testFeatureCollectionClassProps)
5561

62+
@Test
63+
fun testCborFeatureId() {
64+
assertRoundTrip(Cbor, testFeatureIdString)
65+
assertRoundTrip(Cbor, testFeatureIdLong)
66+
assertRoundTrip(Cbor, testFeatureIdDouble)
67+
}
68+
5669
@Test fun testProtobufGeometry() = assertRoundTrip(ProtoBuf, testLineString)
5770

5871
// Below are disabled because ProtoBuf doesn't support null collection types
@@ -75,4 +88,12 @@ class NonJsonFormatTest {
7588
@Ignore
7689
fun testProtobufFeatureCollectionProps() =
7790
assertRoundTrip(ProtoBuf, testFeatureCollectionClassProps)
91+
92+
@Test
93+
@Ignore
94+
fun testProtobufFeatureId() {
95+
assertRoundTrip(ProtoBuf, testFeatureIdString)
96+
assertRoundTrip(ProtoBuf, testFeatureIdLong)
97+
assertRoundTrip(ProtoBuf, testFeatureIdDouble)
98+
}
7899
}

0 commit comments

Comments
 (0)