CLOVIS
03/27/2026, 8:30 PM{
"type": "Point",
"coordinates": [
5.2,
7.3
]
}
Polygon :
{
"type": "Polygon",
"coordinates": [
[
[
0,
0
],
[
10,
0
],
[
10,
10
],
[
0,
10
],
[
0,
0
]
],
[
[
2,
2
],
[
8,
2
],
[
8,
8
],
[
2,
8
],
[
2,
2
]
]
]
}
(and 5 other types that follow the same logic)
I implemented each type separately using surrogates. However, I also need a polymorphic serializer that uses the type field to decide which to decide which is which. I don't know how to write that serializer.hfhbd
03/27/2026, 9:53 PMCLOVIS
03/27/2026, 10:34 PM{
"type": "Point",
"value": {
"type": "Point",
"coordinates": [ … ]
}
}CLOVIS
03/27/2026, 10:52 PM@LowLevelApi
object Serializer : KSerializer<Geo> {
@OptIn(InternalSerializationApi::class)
override val descriptor: SerialDescriptor
get() = buildSerialDescriptor("opensavvy.ktmongo.bson.types.Geo", SerialKind.CONTEXTUAL) {
element("Point", Point.serializer().descriptor)
element("LineString", LineString.serializer().descriptor)
element("Polygon", Polygon.serializer().descriptor)
element("MultiPoint", MultiPoint.serializer().descriptor)
element("MultiLineString", MultiLineString.serializer().descriptor)
element("MultiPolygon", MultiPolygon.serializer().descriptor)
}
override fun serialize(encoder: Encoder, value: Geo) {
when (value) {
is Point -> encoder.encodeSerializableValue(Point.serializer(), value)
is LineString -> encoder.encodeSerializableValue(LineString.serializer(), value)
is Polygon -> encoder.encodeSerializableValue(Polygon.serializer(), value)
is MultiPoint -> encoder.encodeSerializableValue(MultiPoint.serializer(), value)
is MultiLineString -> encoder.encodeSerializableValue(MultiLineString.serializer(), value)
is MultiPolygon -> encoder.encodeSerializableValue(MultiPolygon.serializer(), value)
}
}
override fun deserialize(decoder: Decoder): Geo {
TODO("Not yet implemented")
}
}
No idea how to write the deserializer though.ephemient
03/28/2026, 10:11 PMCLOVIS
03/29/2026, 8:32 AM{
"type": "Point",
"value": {
"type": "Point",
"coordinates": [ … ]
}
}ephemient
03/29/2026, 4:22 PMCLOVIS
03/29/2026, 4:23 PMephemient
03/29/2026, 4:24 PMCLOVIS
03/29/2026, 4:25 PMephemient
03/30/2026, 5:22 PMCLOVIS
03/30/2026, 6:28 PMCLOVIS
03/30/2026, 6:29 PMCLOVIS
03/30/2026, 6:30 PMefemoney
04/11/2026, 2:23 AMefemoney
04/11/2026, 2:30 AM