This project goal is to provide GeoJson deserialization for kotlin multiplatform (JVM, JS).
The specific format of GeoJson files does not allow the use of kotlinx.serialization. JS and JVM implementations are completely distinct but they share the same base objects and interfaces.
JVM implementation is based on the project GeoJson-Jackson.
The project is deployed on jcenter
so you have to define it in your repositories.
repositories {
jcenter()
}
The project is deployed using Gradle metadata. You can use the dependency on Gradle Metadata. Depending on your platform (JS or JVM) the correct artifact will be imported.
compile 'io.data2viz.geojson:core:0.6.2'
The JS version is available in both modes, Legacy
and IR
.
You can then use the String extension toGeoJsonObject to transform any String into a GeoJsonObject:
val featureCollection = json.toGeoJsonObject() as FeatureCollection
If you deserialize a FeatureCollection that have properties (main use case) you need to pass a function that transform the properties in a specific domain object.
class CountryProperties(val name: String, val id: Int)
val countries = countriesGeoJson.toFeatures {
CountryProperties(stringProperty("name"), intProperty("id"))
}
You then retrieve a list of Pair<Feature, CountryPropertiess>