|
81 | 81 | function standardizeZDTStrings!(T, interm::Dict)
|
82 | 82 |
|
83 | 83 | for (name, typ) in zip(fieldnames(T), T.types)
|
84 |
| - if typ <: ZonedDateTime |
| 84 | + if typ <: ZonedDateTime && haskey(interm, name) |
85 | 85 | namestr = string(name)
|
86 | 86 | interm[namestr] = getStandardZDTString(interm[namestr])
|
87 | 87 | end
|
|
144 | 144 | $SIGNATURES
|
145 | 145 | Should be a highly reusable function for any transcoding of intermediate type (or dict) to a desired output type.
|
146 | 146 |
|
| 147 | +Notes: |
| 148 | +- Using Base.@kwdef and JSON3.jl probably has better conversion logic than this function. |
| 149 | +- This function was written to reduce dependency on Unmarshal.jl which was becoming stale. |
| 150 | +
|
| 151 | +DevNotes |
| 152 | +- See if this function just be deprecated to use JSON3 or similar. |
| 153 | +- Do better with Union{Nothing, T} types (if this function is not replaced by JSON3) |
| 154 | +
|
147 | 155 | examples
|
148 | 156 | ```julia
|
149 | 157 | Base.@kwdef struct HardType
|
@@ -200,6 +208,7 @@ function transcodeType(
|
200 | 208 | # specializations as inner functions (don't have to be inners)
|
201 | 209 | # these few special cases came up with examples below, note recursions
|
202 | 210 | _instance(S::Type, x) = S(x)
|
| 211 | + _instance(S::Type{Union{Nothing, UUID}}, x::String) = UUID(x) # special case |
203 | 212 | _instance(_::Type{S}, x::S) where S = x # if ambiguous, delete and do alternative `_instance(S::Type, x) = S===Any ? x : S(x)`
|
204 | 213 | _instance(S::Type{I}, x::AbstractString) where I <: Number = Base.parse(I, x)
|
205 | 214 | _instance(S::Type{E}, x::AbstractVector) where E <: AbstractVector = _instance.(eltype(E),x)
|
@@ -452,7 +461,8 @@ function unpackVariable(
|
452 | 461 | interm = _doparse(bdeInter) # JSON.parse(bdeInter) # bdeInter
|
453 | 462 | objType = getfield(DistributedFactorGraphs, Symbol(dataElemTypes[k]))
|
454 | 463 | standardizeZDTStrings!(objType, interm)
|
455 |
| - fullVal = Unmarshal.unmarshal(objType, interm) |
| 464 | + fullVal = transcodeType(objType, interm) |
| 465 | + # fullVal = Unmarshal.unmarshal(objType, interm) |
456 | 466 | variable.dataDict[k] = fullVal
|
457 | 467 | end
|
458 | 468 | end
|
|
0 commit comments