-
Notifications
You must be signed in to change notification settings - Fork 101
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add JSON.lower for a better serialization API (#151)
Closes #150. - Introduce `JSON.lower`, designed to be overloaded, that converts an object to another “primitive” object that `JSON` can serialize (`Dict`, `Array`, etc.). - In the generic `JSON._print` fallback, call `JSON.lower` instead of the current dumping behaviour - Add a generic `JSON.lower` fallback that does the current dumping behaviour - Rename `JSON._print` to `JSON._writejson`, and add a deprecated fallback to a new `JSON._print` with no methods defined
- Loading branch information
Showing
4 changed files
with
135 additions
and
62 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
if isdefined(Base, :Dates) | ||
@test JSON.json(Date(2016, 8, 3)) == "\"2016-08-03\"" | ||
end | ||
|
||
@test JSON.json(:x) == "\"x\"" | ||
@test_throws ArgumentError JSON.json(Base) | ||
|
||
immutable Type151{T} | ||
x::T | ||
end | ||
|
||
@test JSON.json(Type151) == "\"Type151{T}\"" | ||
|
||
JSON.lower{T}(v::Type151{T}) = @compat Dict(:type => T, :value => v.x) | ||
@test JSON.parse(JSON.json(Type151(1.0))) == @compat Dict( | ||
"type" => "Float64", | ||
"value" => 1.0) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters