4242
4343is_deep_explode (sctx:: StyleCtx ) = sctx. name == " deepObject" && sctx. is_explode
4444
45- function deep_object_to_array (src:: Dict )
45+ function deep_object_to_array (src:: AbstractDict )
4646 keys_are_int = all (key -> occursin (r" ^\d +$" , key), keys (src))
4747 if keys_are_int
4848 sorted_keys = sort (collect (keys (src)), by= x-> parse (Int, x))
5858
5959to_json (o) = JSON. json (o)
6060
61- from_json (:: Type{Union{Nothing,T}} , json:: Dict {String,Any} ; stylectx= nothing ) where {T} = from_json (T, json; stylectx)
62- from_json (:: Type{T} , json:: Dict {String,Any} ; stylectx= nothing ) where {T} = from_json (T (), json; stylectx)
63- from_json (:: Type{T} , json:: Dict {String,Any} ; stylectx= nothing ) where {T <: Dict } = convert (T, json)
64- from_json (:: Type{T} , j:: Dict {String,Any} ; stylectx= nothing ) where {T <: String } = to_json (j)
65- from_json (:: Type{Any} , j:: Dict {String,Any} ; stylectx= nothing ) = j
61+ from_json (:: Type{Union{Nothing,T}} , json:: AbstractDict {String,Any} ; stylectx= nothing ) where {T} = from_json (T, json; stylectx)
62+ from_json (:: Type{T} , json:: AbstractDict {String,Any} ; stylectx= nothing ) where {T} = from_json (T (), json; stylectx)
63+ from_json (:: Type{T} , json:: AbstractDict {String,Any} ; stylectx= nothing ) where {T <: Dict } = convert (T, Dict {String,Any} ( json) )
64+ from_json (:: Type{T} , j:: AbstractDict {String,Any} ; stylectx= nothing ) where {T <: String } = to_json (j)
65+ from_json (:: Type{Any} , j:: AbstractDict {String,Any} ; stylectx= nothing ) = j
6666from_json (:: Type{Vector{T}} , j:: Vector{Any} ; stylectx= nothing ) where {T} = j
6767
68- function from_json (:: Type{Vector{T}} , json:: Dict {String, Any} ; stylectx= nothing ) where {T}
68+ function from_json (:: Type{Vector{T}} , json:: AbstractDict {String, Any} ; stylectx= nothing ) where {T}
6969 if ! isnothing (stylectx) && is_deep_explode (stylectx)
7070 cvt = deep_object_to_array (json)
7171 if isa (cvt, Vector)
@@ -78,7 +78,7 @@ function from_json(::Type{Vector{T}}, json::Dict{String, Any}; stylectx=nothing)
7878 end
7979end
8080
81- function from_json (o:: T , json:: Dict {String,Any} ;stylectx= nothing ) where {T <: UnionAPIModel }
81+ function from_json (o:: T , json:: AbstractDict {String,Any} ;stylectx= nothing ) where {T <: UnionAPIModel }
8282 return from_json (o, :value , json;stylectx)
8383end
8484
@@ -88,16 +88,16 @@ function from_json(o::T, val::Union{String,Real};stylectx=nothing) where {T <: U
8888 return o
8989end
9090
91- function from_json (o:: T , json:: Dict {String,Any} ;stylectx= nothing ) where {T <: APIModel }
91+ function from_json (o:: T , json:: AbstractDict {String,Any} ;stylectx= nothing ) where {T <: APIModel }
9292 jsonkeys = [Symbol (k) for k in keys (json)]
9393 for name in intersect (propertynames (o), jsonkeys)
9494 from_json (o, name, json[String (name)];stylectx)
9595 end
9696 return o
9797end
9898
99- function from_json (o:: T , name:: Symbol , json:: Dict {String,Any} ;stylectx= nothing ) where {T <: APIModel }
100- ftype = (T <: UnionAPIModel ) ? property_type (T, name, json) : property_type (T, name)
99+ function from_json (o:: T , name:: Symbol , json:: AbstractDict {String,Any} ;stylectx= nothing ) where {T <: APIModel }
100+ ftype = (T <: UnionAPIModel ) ? property_type (T, name, Dict {String,Any} ( json) ) : property_type (T, name)
101101 fval = from_json (ftype, json; stylectx)
102102 setfield! (o, name, convert (ftype, fval))
103103 return o
0 commit comments