From b57591862008561780cdc7c912b6d86203766d48 Mon Sep 17 00:00:00 2001 From: Jacob Quinn Date: Sun, 22 Sep 2024 00:12:00 -0600 Subject: [PATCH] Only do objectid comparisons for mutable types --- src/json.jl | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/json.jl b/src/json.jl index 5e8d5e9..1714d2f 100644 --- a/src/json.jl +++ b/src/json.jl @@ -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 @@ -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