GSON (de)serialization fails for CameraOptions and StyleDescriptor

As part of our application, we provide objects such as the MapOptions and RoutePlanningOptions in JSON format. Luckily, (de)serialization is already provided by the SDK(s). For some classes, however, this seems to have been misconfigured, leading to some strange behavior. For the two cases below, can you see if this can be resolved s.t. I can remove the manual solutions for these two cases?


Specifically, when you take a CameraOptions object and use gson to do .toJson(), the properties are renamed to a, b, c, d and e, and lose their original name. The same happens the other way around, when using gson.fromJson I need to provide the property names a-e instead of the actual names. They currently (0.44.0) map as follows:

a --> position
b --> zoom
c --> tilt
d --> rotation
e --> fieldOfView


When passing a custom style descriptor through the MapOptions, I realised they got ignored (uri and darkUri remained empty, even though they were defined by these exact names in the JSON that was parsed). I.e. executing the following code:


I get the following:


Which is obviously wrong. There’s also no clear way to actually provide the StyleDescriptor as a JSON input String.

What I ended up doing for now is provide Gson with a custom StyleDescriptorDeserializer as follows:

class StyleDescriptorDeserializer : JsonDeserializer<StyleDescriptor> {
    override fun deserialize(
        json: JsonElement,
        typeOfT: Type?,
        context: JsonDeserializationContext?
    ): StyleDescriptor {
        val o = json.asJsonObject

        val uri = Uri.parse(o.get("uri").asString)
        val darkUri = if (o.has("darkUri") && !o["darkUri"].isJsonNull) Uri.parse(o.get("darkUri").asString) else null
        val layerMappingUri = if (o.has("layerMappingUri") && !o["layerMappingUri"].isJsonNull) Uri.parse(o.get("layerMappingUri").asString) else null
        val darkLayerMappingUri = if (o.has("darkLayerMappingUri") && !o["darkLayerMappingUri"].isJsonNull) Uri.parse(o.get("darkLayerMappingUri").asString) else null
        return StyleDescriptor(
            uri = uri,
            darkUri = darkUri,
            layerMappingUri = layerMappingUri,
            darkLayerMappingUri = darkLayerMappingUri,

Which correctly parses the serialized JSON objects I provide.