Skip to content

Commit a5d3599

Browse files
quinnjclaude
andauthored
Add structlike(::Type{BigInt/BigFloat}) = false (#38)
BigInt and BigFloat are mutable structs in Julia, but they should be treated as primitive/non-struct types for serialization purposes. Without this, packages like JSON.jl fail when trying to parse numbers into BigInt or BigFloat because StructUtils routes them to makestruct instead of lift. Fixes JuliaIO/JSON.jl#424 Co-authored-by: Claude Opus 4.5 <noreply@anthropic.com>
1 parent 27df92b commit a5d3599

File tree

2 files changed

+11
-0
lines changed

2 files changed

+11
-0
lines changed

src/StructUtils.jl

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -248,6 +248,8 @@ structlike(::Type{Symbol}) = false
248248
structlike(::Type{Regex}) = false
249249
structlike(::Type{<:Dates.TimeType}) = false
250250
structlike(::Type{Number}) = false
251+
structlike(::Type{BigInt}) = false
252+
structlike(::Type{BigFloat}) = false
251253
structlike(::Type{Nothing}) = false
252254
structlike(::Type{Missing}) = false
253255
structlike(::Type{UUID}) = false

test/runtests.jl

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -326,6 +326,15 @@ end
326326
@test StructUtils.make(Dict{Symbol, Int}, (;)) == Dict{Symbol, Int}()
327327
end
328328

329+
@testset "BigInt/BigFloat structlike" begin
330+
# BigInt and BigFloat are mutable structs in Julia, but should be treated
331+
# as non-struct types for serialization purposes (JuliaIO/JSON.jl#424)
332+
@test StructUtils.structlike(BigInt) == false
333+
@test StructUtils.structlike(BigFloat) == false
334+
@test StructUtils.structlike(StructUtils.DefaultStyle(), BigInt) == false
335+
@test StructUtils.structlike(StructUtils.DefaultStyle(), BigFloat) == false
336+
end
337+
329338
@testset "keyeq with Tuple" begin
330339
# Test basic tuple functionality
331340
@test StructUtils.keyeq(:a, ("a", "b", "c"))

0 commit comments

Comments
 (0)