toJson

inline fun <T : GeoJsonObject> T.toJson(): String(source)

Converts this GeoJsonObject to a JSON string representation.

When called on Feature or FeatureCollection objects where the type is not fully known at compile time (e.g., (feature as GeoJsonObject).toJson()), the serializer for custom property types is selected at runtime using kotlinx.serialization's runtime serializer lookup. This has important constraints:

  • Classes with generic type parameters will fail (e.g., property type Map<String, String>)

  • External serializers generated with @Serializer(forClass = ) are not looked up consistently

  • Serializers for classes with named companion objects are not looked up consistently

  • Behavior may differ between JVM, JS, and Native platforms

To work around these constraints when the compile-time type is not available, either:

Return

A JSON string representing this GeoJSON object.

See also

Throws

if serialization fails.