diff --git a/README.md b/README.md index 4365b8b..89488a3 100644 --- a/README.md +++ b/README.md @@ -37,7 +37,7 @@ JSON.json(j) ```julia JSON.print(io::IO, s::AbstractString) JSON.print(io::IO, s::Union{Integer, AbstractFloat}) -JSON.print(io::IO, n::Void) +JSON.print(io::IO, n::Nothing) JSON.print(io::IO, b::Bool) JSON.print(io::IO, a::Associative) JSON.print(io::IO, v::AbstractVector) diff --git a/REQUIRE b/REQUIRE index 0d9397e..4f9b8e2 100644 --- a/REQUIRE +++ b/REQUIRE @@ -1,3 +1,3 @@ julia 0.6 -Compat 0.37.0 +Compat 0.44.0 Nullables 0.0.1 diff --git a/bench/micro.jl b/bench/micro.jl index 4ed0532..50a1ffc 100644 --- a/bench/micro.jl +++ b/bench/micro.jl @@ -12,13 +12,13 @@ suite["pretty-print"] = BenchmarkGroup(["serialize"]) struct CustomListType x::Int y::Float64 - z::Union{CustomListType, Void} + z::Union{CustomListType, Nothing} end struct CustomTreeType x::String - y::Union{CustomTreeType, Void} - z::Union{CustomTreeType, Void} + y::Union{CustomTreeType, Nothing} + z::Union{CustomTreeType, Nothing} end list(x) = x == 0 ? nothing : CustomListType(1, 1.0, list(x - 1)) diff --git a/src/Parser.jl b/src/Parser.jl index b75c09c..de04aa0 100644 --- a/src/Parser.jl +++ b/src/Parser.jl @@ -129,7 +129,7 @@ function _error(message::AbstractString, ps::MemoryParserState) orig = String(ps.utf8data) lines = _count_before(orig, '\n', ps.s) # Replace all special multi-line/multi-space characters with a space. - strnl = replace(orig, r"[\b\f\n\r\t\s]", " ") + strnl = replace(orig, r"[\b\f\n\r\t\s]" => " ") li = (ps.s > 20) ? ps.s - 9 : 1 # Left index ri = min(endof(orig), ps.s + 20) # Right index error(message * @@ -316,7 +316,7 @@ end Parse an integer from the given bytes vector, starting at `from` and ending at the byte before `to`. Bytes enclosed should all be ASCII characters. """ -function int_from_bytes(pc::ParserContext{<:Associative,IntType}, +function int_from_bytes(pc::ParserContext{<:AbstractDict,IntType}, ps::ParserState, bytes::Vector{UInt8}, from::Int, @@ -377,11 +377,11 @@ end function unparameterize_type(T::Type) - candidate = typeintersect(T, Associative{String, Any}) + candidate = typeintersect(T, AbstractDict{String, Any}) candidate <: Union{} ? T : candidate end -function parse(str::AbstractString; dicttype::Type{<:Associative}=Dict{String,Any}, inttype::Type{<:Real}=Int64) +function parse(str::AbstractString; dicttype::Type{<:AbstractDict}=Dict{String,Any}, inttype::Type{<:Real}=Int64) pc = ParserContext{unparameterize_type(dicttype), inttype}() ps = MemoryParserState(Vector{UInt8}(String(str)), 1) v = parse_value(pc, ps) @@ -392,15 +392,15 @@ function parse(str::AbstractString; dicttype::Type{<:Associative}=Dict{String,An v end -function parse(io::IO; dicttype::Type{<:Associative}=Dict{String,Any}, inttype::Type{<:Real}=Int64) +function parse(io::IO; dicttype::Type{<:AbstractDict}=Dict{String,Any}, inttype::Type{<:Real}=Int64) pc = ParserContext{unparameterize_type(dicttype), inttype}() ps = StreamingParserState(io) parse_value(pc, ps) end -function parsefile(filename::AbstractString; - dicttype::Type{<:Associative}=Dict{String, Any}, - inttype::Type{<:Real}=Int64, +function parsefile(filename::AbstractString; + dicttype::Type{<:AbstractDict}=Dict{String, Any}, + inttype::Type{<:Real}=Int64, use_mmap=true) sz = filesize(filename) open(filename) do io diff --git a/src/Writer.jl b/src/Writer.jl index 68d1043..daed7d5 100644 --- a/src/Writer.jl +++ b/src/Writer.jl @@ -1,5 +1,6 @@ module Writer +using Compat using Compat.Dates using Nullables using ..Common @@ -10,6 +11,7 @@ if VERSION >= v"0.7.0-DEV.2915" using Unicode end + """ Internal JSON.jl implementation detail; do not depend on this type. @@ -27,11 +29,11 @@ CompositeTypeWrapper(x) = CompositeTypeWrapper(x, fieldnames(typeof(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: `Associative` to JSON +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, `Integer` and `AbstractFloat` to JSON number, `Bool` to JSON boolean, and -`Void` to JSON null, or any other types with a `show_json` method defined. +`Nothing` to JSON null, or any other types with a `show_json` method defined. Extensions of this method should preserve the property that the return value is one of the aforementioned types. If first lowering to some intermediate type is @@ -263,7 +265,7 @@ function show_json(io::SC, s::CS, x::Union{Integer, AbstractFloat}) end end -show_json(io::SC, ::CS, ::Void) = show_null(io) +show_json(io::SC, ::CS, ::Nothing) = show_null(io) function show_json(io::SC, s::CS, a::Nullable) if isnull(a) @@ -273,7 +275,7 @@ function show_json(io::SC, s::CS, a::Nullable) end end -function show_json(io::SC, s::CS, a::Associative) +function show_json(io::SC, s::CS, a::AbstractDict) begin_object(io) for kv in a show_pair(io, s, kv) @@ -310,7 +312,7 @@ Serialize a multidimensional array to JSON in column-major format. That is, function show_json(io::SC, s::CS, A::AbstractArray{<:Any,n}) where n begin_array(io) newdims = ntuple(_ -> :, n - 1) - for j in indices(A, n) + for j in Compat.axes(A, n) show_element(io, s, view(A, newdims..., j)) end end_array(io) diff --git a/test/runtests.jl b/test/runtests.jl index 8d1f013..a591754 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -52,7 +52,7 @@ end end @testset "Integration" begin - # ::Void values should be encoded as null + # ::Nothing values should be encoded as null testDict = Dict("a" => nothing) nothingJson = JSON.json(testDict) nothingDict = JSON.parse(nothingJson)