Skip to content

Commit

Permalink
Only do objectid comparisons for mutable types
Browse files Browse the repository at this point in the history
  • Loading branch information
quinnj committed Sep 22, 2024
1 parent 567d372 commit b575918
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/json.jl
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ end
end
end
# check if the lowered value is in our objectid set
if val in f.objids
if ismutabletype(typeof(val)) && val in f.objids
# if so, it's a circular reference! so we just write `null`
pos = _null(buf, pos)
else
Expand Down Expand Up @@ -243,7 +243,7 @@ function json!(buf, pos, x, style::AbstractJSONStyle=JSONStyle(), allownan=false
ref = Ref(pos)
# use an IdSet to keep track of circular references
objids = objids === nothing ? Base.IdSet{Any}() : objids
push!(objids, x)
ismutabletype(typeof(x)) && push!(objids, x)
c = WriteClosure{typeof(style), al, typeof(x)}(buf, Base.unsafe_convert(Ptr{Int}, ref), ind, depth + 1, style, allownan, jsonlines, objids)
GC.@preserve ref StructUtils.applyeach(style, c, x)
# get updated pos
Expand Down

0 comments on commit b575918

Please sign in to comment.