mapbox-maps-ios icon indicating copy to clipboard operation
mapbox-maps-ios copied to clipboard

JSON expression parse with object

Open mfazekas opened this issue 2 years ago • 0 comments

Environment

  • Xcode version: 14.3.1 (14E300c)
  • iOS version: 17.0
  • Devices affected: Simulator iPhone 14 Pro
  • Maps SDK Version: #main (cf286de094c7bd413697ab67da0d5866f790009e)

Observed behavior and steps to reproduce

let expressionString =
        """
        [
            "get",
            "akey",
            ["literal",
                {
                    "akey":"aval",
                    "bkey":"bval",
                }
            ]
        ]
        """
        
        let expressionData = expressionString.data(using: .utf8)!
        let expression = try! JSONDecoder().decode(Expression.self, from: expressionData)
        print("?? decode expression \(expression) from \(expressionString)")

Expected behavior

I'd expect that the object is parsed as the argument to literal. But instead I get an empty format expression:

?? decode expression [get, akey, [literal, format(MapboxMaps.FormatOptions(fontScaleValue: nil, textFontValue: nil, textColorValue: nil))]] from [
    "get",
    "akey",
    ["literal",
        {
            "akey":"aval",
            "bkey":"bval",
        }
    ]
]

Also if I serialise the expression I get:

       let coded = try! JSONEncoder().encode(expression)
        print("=> coded as: \(coded) \(String(data: coded, encoding: .utf8))")
Optional("[\"get\",\"akey\",[\"literal\",{}]]")

Notes / preliminary analysis

Additional links and references

mfazekas avatar Jul 11 '23 20:07 mfazekas