I wonder why the following de-serialisation code does not work.
In the Geometry struct, if I remove one of the types (Vector{Float64} or Vector{Vector{Float64}), it works.
They appear to be conflicting somehow.
If I change the definition of ‘coordinates’ to the following, it works.
Union{Vector{Any},Vector{Vector{Float64}},Nothing}
Here is the code:
import Pkg; Pkg.add("JSON3")
using JSON3
struct Geometry
# The following commented-out definition works
# coordinates::Union{Vector{Float64}, Nothing}
# The following commented-out definition also works
# coordinates::Union{Vector{Any},Vector{Vector{Float64}},Nothing}
# But the following definition does not work.
coordinates::Union{Vector{Float64},Vector{Vector{Float64}},Nothing}
type::Union{String, Nothing}
end
struct Feature
feature_id::Union{String, Nothing}
layer_id::Union{String, Nothing}
feature_type::Union{String, Nothing}
type::Union{String, Nothing}
properties::Union{Dict{String, Any}, Nothing}
geometry::Union{Geometry, Nothing}
end
text = "{\"type\":\"Feature\", \"geometry\":{\"type\":\"Point\", \"coordinates\":[145.7758519805272, -36.76519129485044]}, \"feature_id\":\"INTERSECTION&&3\", \"layer_id\":\"INTERSECTION\", \"feature_type\":\"POINT\", \"properties\":{\"HexIndexes\":[606831691595513900]}}"
test = JSON3.read(text, Feature)
@info test.geometry