Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 22 additions & 15 deletions src/http.jl
Original file line number Diff line number Diff line change
Expand Up @@ -83,48 +83,55 @@ _conv(x, ::Type{T}) where T = conv(x, T)

conv(x::String, ::Type{String}) = x

function conv(j::JSON3.Object, ::Type{Union{Nothing, T}}) where {T}
if j == nothing
return nothing
end
return conv(j, T)
end

function conv(j::JSON3.Object, ::Type{T}) where {T}
# e/g/ (:id, :company_id, :company_external_id, :site_id, :site_external_id, :job_title, :job_id, :status,
# :first_name, :last_name, :phone, :email, :address, :address_2, :city, :state, :country,
# :zipcode, :rating, :contact_preference, :tags, :system_tags, :applied_at, :hired_at,
# :start_date, :source, :archived_at, :created_at, :updated_at)
fn = fieldnames(T)
ft = fieldtypes(T)

# @show T
ks = keys(j)
fields = []
# @show j.updated_at
# @show j.applied_at
for (f,t) in zip(fn, ft)
# @show f, j[f], t
# @show f, t
if f in ks
try
push!(fields, _conv(j[f], t))
res = _conv(j[f], t)
push!(fields, res)
catch e
val = j[f]
actual_type = typeof(val)
error("Error converting field ``$f'' of type ``$t'' and value ``$val'' and actual type $actual_type: $e")
push!(fields, missing)
println("[CONV] Error converting field ``$f'' of type ``$t'' and value ``$val'' and actual type $actual_type: $e, current json: $j")
flush(stdout)
throw("[CONV] Error converting field ``$f'' of type ``$t'' and value ``$val'' and actual type $actual_type: $e, current json: $j")
end
else # F is not in ks
try
res = _conv(nothing, t) # If t is a maybe, this might still be dispatchable
push!(fields, res)
catch e
println("[CONV] Error converting field ``$f'' of type ``$t'' and value ``nothing'': $e, current json: $j")
flush(stdout)
throw("[CONV] Error converting field ``$f'' of type ``$t'' and value ``nothing'': $e, current json: $j")
end
elseif t isa Maybe
push!(fields, nothing)
else
error("missing field $f")
field_dict[f] = missing
end
end
# @show field_dict
return T(fields...)::T
end


function conv(j::JSON3.Object, ::Type{Union{Nothing, T}}) where {T}
if j == nothing
return nothing
end
return conv(j, T)
end



Expand Down