I am trying to set a property for my feature which is a list of string objects. Which for the feature has to be converted to a jsonElement. But when I try to get the result I get a serialization error for a ArrayList instead.
The error is the following:
Request error kotlinx.serialization.SerializationException: Serializer for class 'ArrayList' is not found.
Mark the class as @Serializable or provide the serializer explicitly.
at kotlinx.serialization.internal.PlatformKt.serializerNotRegistered(Platform.kt:32)
at kotlinx.serialization.SerializersKt__SerializersJvmKt.serializer(SerializersJvm.kt:59)
at kotlinx.serialization.SerializersKt.serializer(Unknown Source)
With the following code:
private fun buildFeature(id: String?, geometry: Geometry, stations: List<String>): Feature {
val feature = Feature(geometry = geometry, id = id)
if (stations.isNotEmpty()) {
feature.setJsonProperty("stations", asJsonObject(stations))
}
return feature
}
The asJsonObject is from the HTTP4K library with the following code from them:
override fun asJsonObject(input: Any): JsonElement =
json.encodeToJsonElement(json.serializersModule.serializer(input::class.java), input)
The Feature GeoJson object is from the Spatial K geojson
library. What needs to be changed or added for the serialization to work?