diff --git a/REQUIRE b/REQUIRE index 6463e31..1992b52 100644 --- a/REQUIRE +++ b/REQUIRE @@ -1,2 +1,2 @@ julia 0.5 -Compat 0.24.0 +Compat 0.31.0 diff --git a/bench/bench.jl b/bench/bench.jl index 48e6a16..cfc3eca 100755 --- a/bench/bench.jl +++ b/bench/bench.jl @@ -16,7 +16,7 @@ function bench(f, simulate=false) JSON.parsefile(fp) toq() else - data = readstring(fp) + data = read(fp, String) tic() JSON.Parser.parse(data) toq() diff --git a/src/Common.jl b/src/Common.jl index 05da8b3..282b78b 100644 --- a/src/Common.jl +++ b/src/Common.jl @@ -5,6 +5,10 @@ module Common using Compat +# The expression head to use for constructing types. +# TODO: Remove this hack when 0.5 support is dropped. +const STRUCTHEAD = VERSION < v"0.7.0-DEV.1263" ? :type : :struct + include("bytes.jl") include("errors.jl") diff --git a/src/Parser.jl b/src/Parser.jl index 91cf8c7..d6a289b 100644 --- a/src/Parser.jl +++ b/src/Parser.jl @@ -18,13 +18,13 @@ isjsondigit(b::UInt8) = DIGIT_ZERO ≤ b ≤ DIGIT_NINE @compat abstract type ParserState end -eval(Expr(:type, true, :(MemoryParserState <: ParserState), +eval(Expr(Common.STRUCTHEAD, true, :(MemoryParserState <: ParserState), quote utf8data::Vector{UInt8} s::Int end)) -eval(Expr(:type, true, :(StreamingParserState{T <: IO} <: ParserState), +eval(Expr(Common.STRUCTHEAD, true, :(StreamingParserState{T <: IO} <: ParserState), quote io::T cur::UInt8 @@ -390,7 +390,7 @@ end function parsefile{T<:Associative}(filename::AbstractString; dicttype::Type{T}=Dict{String, Any}, use_mmap=true) sz = filesize(filename) open(filename) do io - s = use_mmap ? String(Mmap.mmap(io, Vector{UInt8}, sz)) : readstring(io) + s = use_mmap ? String(Mmap.mmap(io, Vector{UInt8}, sz)) : read(io, String) parse(s; dicttype=dicttype) end end diff --git a/src/Serializations.jl b/src/Serializations.jl index 070ef60..0d88c58 100644 --- a/src/Serializations.jl +++ b/src/Serializations.jl @@ -8,6 +8,7 @@ implementations, as they relate to JSON. module Serializations using Compat +using ..Common """ A `Serialization` defines how objects are lowered to JSON format. @@ -24,7 +25,7 @@ packages explicitly defining `JSON.show_json` for this serialization, or by the which case `Serialization` should be subtyped. """ CommonSerialization -eval(Expr(:type, false, :(StandardSerialization <: CommonSerialization), +eval(Expr(Common.STRUCTHEAD, false, :(StandardSerialization <: CommonSerialization), quote end)) @doc """ The `StandardSerialization` defines a common, standard JSON serialization format diff --git a/src/Writer.jl b/src/Writer.jl index 9bcb57a..1b3601f 100644 --- a/src/Writer.jl +++ b/src/Writer.jl @@ -5,7 +5,7 @@ using ..Common using ..Serializations: Serialization, StandardSerialization, CommonSerialization -eval(Expr(:type, false, :(CompositeTypeWrapper{T}), +eval(Expr(Common.STRUCTHEAD, false, :(CompositeTypeWrapper{T}), quote wrapped::T fns::Vector{Symbol} @@ -16,7 +16,7 @@ Internal JSON.jl implementation detail; do not depend on this type. A JSON primitive that wraps around any composite type to enable `Dict`-like serialization. """ CompositeTypeWrapper -CompositeTypeWrapper(x) = CompositeTypeWrapper(x, fieldnames(x)) +CompositeTypeWrapper(x) = CompositeTypeWrapper(x, fieldnames(typeof(x))) """ lower(x) @@ -76,7 +76,7 @@ to the stream. """ @compat abstract type JSONContext <: StructuralContext end -eval(Expr(:type, true, :(PrettyContext{T<:IO} <: JSONContext), +eval(Expr(Common.STRUCTHEAD, true, :(PrettyContext{T<:IO} <: JSONContext), quote io::T step::Int # number of spaces to step @@ -91,7 +91,7 @@ unwinds during serialization. """ PrettyContext PrettyContext(io::IO, step) = PrettyContext(io, step, 0, false) -eval(Expr(:type, true, :(CompactContext{T<:IO} <: JSONContext), +eval(Expr(Common.STRUCTHEAD, true, :(CompactContext{T<:IO} <: JSONContext), quote io::T first::Bool @@ -103,7 +103,7 @@ For compact printing, which in JSON is fully recursive. """ CompactContext CompactContext(io::IO) = CompactContext(io, false) -eval(Expr(:type, false, :(StringContext{T<:IO} <: IO), +eval(Expr(Common.STRUCTHEAD, false, :(StringContext{T<:IO} <: IO), quote io::T end)) @@ -314,7 +314,7 @@ Serialize a multidimensional array to JSON in column-major format. That is, """ function show_json{T,n}(io::SC, s::CS, A::AbstractArray{T,n}) begin_array(io) - newdims = ntuple(_ -> :, Val{n - 1}) + newdims = ntuple(_ -> :, n - 1) for j in indices(A, n) show_element(io, s, view(A, newdims..., j)) end diff --git a/test/json-checker.jl b/test/json-checker.jl index 48acc44..0acd960 100644 --- a/test/json-checker.jl +++ b/test/json-checker.jl @@ -23,6 +23,6 @@ for i in 1:27 file = "roundtrip$(lpad(i, 2, 0)).json" filepath = joinpath(JSON_DATA_DIR, "roundtrip", file) - rt = roundtrip(readstring(filepath)) + rt = roundtrip(read(filepath, String)) @test rt == roundtrip(rt) end diff --git a/test/json-samples.jl b/test/json-samples.jl index 5750da7..2df326f 100644 --- a/test/json-samples.jl +++ b/test/json-samples.jl @@ -298,7 +298,7 @@ colors3 = "{ twitter = "{\"results\":[ - {\"text\":\"@twitterapi http:\/\/tinyurl.com\/ctrefg\", + {\"text\":\"@twitterapi http://tinyurl.com/ctrefg\", \"to_user_id\":396524, \"to_user\":\"TwitterAPI\", \"from_user\":\"jkoum\", @@ -310,8 +310,8 @@ twitter = "{\"results\":[ \"id\":1478555574, \"from_user_id\":1833773, \"iso_language_code\":\"nl\", - \"source\":\"twitter<\/a>\", - \"profile_image_url\":\"http:\/\/s3.amazonaws.com\/twitter_production\/profile_images\/118412707\/2522215727_a5f07da155_b_normal.jpg\", + \"source\":\"twitter\", + \"profile_image_url\":\"http://s3.amazonaws.com/twitter_production/profile_images/118412707/2522215727_a5f07da155_b_normal.jpg\", \"created_at\":\"Wed, 08 Apr 2009 19:22:10 +0000\"}], \"since_id\":0, \"max_id\":1480307926, @@ -380,7 +380,7 @@ const flickr = """{ "link": "http://www.flickr.com/photos/33112458@N08/3081564649/in/pool-998875@N22", "media": {"m":"http://farm4.static.flickr.com/3037/3081564649_4a6569750c_m.jpg"}, "date_taken": "2008-12-04T04:43:03-08:00", - "description": "
Talk On Travel<\/a> has added a photo to the pool:<\/p> <\/a><\/p> ",
+ "description": " Talk On Travel has added a photo to the pool: