Skip to content
This repository was archived by the owner on Aug 8, 2023. It is now read-only.
This repository was archived by the owner on Aug 8, 2023. It is now read-only.

sparse arrays aren't being handled correctly in Android Expression conversion #11749

Closed

Description

@cammace

When trying to serialize JSON to a jsonArray and use the convert method, if the JSON string has an empty element , ,, the Map SDK throws a runtime exception https://github.com/mapbox/mapbox-gl-native/blob/release-boba/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/expressions/Expression.java#L3677 since when I use GSON to serialize, this value becomes a null element.

cc: @mapbox/maps-android

Activity

  1. added
    Android
    on Apr 20, 2018
  2. tobrun commented on Apr 24, 2018

    @tobrun
    Member

    Can you show a code snippet or example data of what you are trying to convert?

  3. cammace commented on Apr 24, 2018

    @cammace
    ContributorAuthor

    Sure, so can actually reproduce this issue in mapbox/mapbox-plugins-android#455, the somewhat modified expression JSON:

    ["step", ["zoom"], 0.0, , 13.0, ["get", "{name_ru}"]]
    

    gets converted to:

    ["step",["zoom"],0.0,null,13.0,["get","{name_ru}"]]
    

    when I use GSON to convert it back to a JsonArray.

  4. jfirebaugh commented on Apr 24, 2018

    @jfirebaugh
    Contributor

    ["step", ["zoom"], 0.0, , 13.0, ["get", "{name_ru}"]] isn't a valid expression (it's not valid JSON, for one thing). Where did that come from?

  5. cammace commented on Apr 24, 2018

    @cammace
    ContributorAuthor

    sorry, before modifying anything the expressions was written like:

    ["step", ["zoom"], 0.0, , 13.0, {name_ru}]
    

    which is also not valid JSON, #11659 is an issue. To be more specific where this expression is coming from, the default Mapbox Streets style when grabbing the state-label-lg layer, converting the expression to an array and then printing it to log using Arrays.toString().

  6. 1ec5 commented on Apr 25, 2018

    @1ec5
    Contributor

    #11659 is purely about {token} syntax embedded in strings in valid JSON, stuff like this:

    ["step", ["zoom"], 0.0, "", 13.0, "{name_ru}"]

    What you’re seeing with Arrays.toString() is probably a lossy string representation that isn’t intended to be valid JSON. (This is reminiscent of what you see in Objective-C when you try to po an array in LLDB.) You might get better results with Arrays.deepToString(), but the map SDK’s own Expression.toString() sounds like it outputs a valid JSON-encoded string.

  7. cammace commented on Apr 25, 2018

    @cammace
    ContributorAuthor

    Right, using toString ultimately results in the same JSON string representation

    ["step", ["zoom"], 0.0, , 13.0, {name_en}]

    In this ticket I'm mearly pointing out that when I use GSON after modifying the JSON to reserialize it into a JsonArray object passable into the Expression convert method, GSON interprets the 0.0, , 13.0 to 0.0, null, 13.0 which isn't accepted by the converter method.

  8. 1ec5 commented on Apr 25, 2018

    @1ec5
    Contributor

    OK, if the conversion to a string isn’t at issue, then something along the way is interpreting the empty string as a null, which is incorrect.

  9. cammace commented on Apr 26, 2018

    @cammace
    ContributorAuthor

    then something along the way is interpreting the empty string as a null

    So you're saying the empty string is valid JSON since it's inside the array? Shouldn't null also be acceptable in this case then as well and be treated the same?

  10. 1ec5 commented on Apr 26, 2018

    @1ec5
    Contributor

    I don’t think you can validly set text-field to null in a style JSON file. The empty string is the way that a symbol layer indicates it has no text-field. So a stop value of null inside a step expression would be similarly invalid.

  11. cammace commented on Apr 30, 2018

    @cammace
    ContributorAuthor

    Ahhh, I see. In that case issue #11158 should resolve this issue. for now, a solution for this I suppose would be writing a custom serializer for empty strings so that GSON doesn't automatically assume the field is null.

    @tobrun do you want to merge this ticket with #11158 or leave open to ensure we include a test case for this?

  12. tobrun commented on May 2, 2018

    @tobrun
    Member

    #11158 will solve this use-case and don't see a reason to double track this. Closing.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Androidbug

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions