Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix show_json to serialize empty NamedTuple #293

Merged
merged 1 commit into from
Dec 11, 2019
Merged
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
Fix show_json to serialize empty NamedTuple
  • Loading branch information
0x005c committed Oct 24, 2019
commit f88c85668c613edfc28ce75061d60186bbdea0c7
10 changes: 5 additions & 5 deletions src/Writer.jl
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,9 @@ CompositeTypeWrapper(x) = CompositeTypeWrapper(x, propertynames(x))
lower(x)

Return a value of a JSON-encodable primitive type that `x` should be lowered
into before encoding as JSON. Supported types are: `AbstractDict` to JSON
objects, `Tuple` and `AbstractVector` to JSON arrays, `AbstractArray` to nested
JSON arrays, `AbstractString`, `Symbol`, `Enum`, or `Char` to JSON string,
into before encoding as JSON. Supported types are: `AbstractDict` and `NamedTuple`
to JSON objects, `Tuple` and `AbstractVector` to JSON arrays, `AbstractArray` to
nested JSON arrays, `AbstractString`, `Symbol`, `Enum`, or `Char` to JSON string,
`Integer` and `AbstractFloat` to JSON number, `Bool` to JSON boolean, and
`Nothing` to JSON null, or any other types with a `show_json` method defined.

Expand Down Expand Up @@ -265,9 +265,9 @@ end
show_json(io::SC, ::CS, ::Nothing) = show_null(io)
show_json(io::SC, ::CS, ::Missing) = show_null(io)

function show_json(io::SC, s::CS, a::AbstractDict)
function show_json(io::SC, s::CS, x::Union{AbstractDict, NamedTuple})
begin_object(io)
for kv in a
for kv in pairs(x)
show_pair(io, s, kv)
end
end_object(io)
Expand Down