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 library is published to data2viz space repository.
- Add the data2viz maven repository:
repositories {
maven { url = uri("https://maven.pkg.jetbrains.space/data2viz/p/maven/public") }
}
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.6'
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>