You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository was archived by the owner on Aug 8, 2023. It is now read-only.
Repository navigation
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
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().
#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.
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.
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?
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.
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?
Activity
tobrun commentedon Apr 24, 2018
Can you show a code snippet or example data of what you are trying to convert?
cammace commentedon Apr 24, 2018
Sure, so can actually reproduce this issue in mapbox/mapbox-plugins-android#455, the somewhat modified expression JSON:
gets converted to:
when I use GSON to convert it back to a JsonArray.
jfirebaugh commentedon Apr 24, 2018
["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?cammace commentedon Apr 24, 2018
sorry, before modifying anything the expressions was written like:
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-lglayer, converting the expression to an array and then printing it to log usingArrays.toString().1ec5 commentedon Apr 25, 2018
#11659 is purely about
{token}syntax embedded in strings in valid JSON, stuff like this: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 topoan array in LLDB.) You might get better results withArrays.deepToString(), but the map SDK’s ownExpression.toString()sounds like it outputs a valid JSON-encoded string.cammace commentedon Apr 25, 2018
Right, using
toStringultimately results in the same JSON string representationIn 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.0to0.0, null, 13.0which isn't accepted by the converter method.1ec5 commentedon Apr 25, 2018
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.cammace commentedon Apr 26, 2018
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?
1ec5 commentedon Apr 26, 2018
I don’t think you can validly set
text-fieldtonullin a style JSON file. The empty string is the way that a symbol layer indicates it has notext-field. So a stop value ofnullinside astepexpression would be similarly invalid.cammace commentedon Apr 30, 2018
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?
tobrun commentedon May 2, 2018
#11158 will solve this use-case and don't see a reason to double track this. Closing.