Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
J
json
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Libraries
json
Commits
347e77bd
Unverified
Commit
347e77bd
authored
Jul 21, 2018
by
Niels Lohmann
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
🚑
fix for #1169
parent
04372a8c
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
62 additions
and
0 deletions
+62
-0
include/nlohmann/detail/conversions/from_json.hpp
include/nlohmann/detail/conversions/from_json.hpp
+10
-0
single_include/nlohmann/json.hpp
single_include/nlohmann/json.hpp
+10
-0
test/src/unit-conversions.cpp
test/src/unit-conversions.cpp
+42
-0
No files found.
include/nlohmann/detail/conversions/from_json.hpp
View file @
347e77bd
...
@@ -22,6 +22,16 @@ namespace nlohmann
...
@@ -22,6 +22,16 @@ namespace nlohmann
{
{
namespace
detail
namespace
detail
{
{
template
<
typename
BasicJsonType
>
void
from_json
(
const
BasicJsonType
&
j
,
typename
std
::
nullptr_t
&
n
)
{
if
(
JSON_UNLIKELY
(
not
j
.
is_null
()))
{
JSON_THROW
(
type_error
::
create
(
302
,
"type must be null, but is "
+
std
::
string
(
j
.
type_name
())));
}
n
=
nullptr
;
}
// overloads for basic_json template parameters
// overloads for basic_json template parameters
template
<
typename
BasicJsonType
,
typename
ArithmeticType
,
template
<
typename
BasicJsonType
,
typename
ArithmeticType
,
enable_if_t
<
std
::
is_arithmetic
<
ArithmeticType
>
::
value
and
enable_if_t
<
std
::
is_arithmetic
<
ArithmeticType
>
::
value
and
...
...
single_include/nlohmann/json.hpp
View file @
347e77bd
...
@@ -952,6 +952,16 @@ namespace nlohmann
...
@@ -952,6 +952,16 @@ namespace nlohmann
{
{
namespace
detail
namespace
detail
{
{
template
<
typename
BasicJsonType
>
void
from_json
(
const
BasicJsonType
&
j
,
typename
std
::
nullptr_t
&
n
)
{
if
(
JSON_UNLIKELY
(
not
j
.
is_null
()))
{
JSON_THROW
(
type_error
::
create
(
302
,
"type must be null, but is "
+
std
::
string
(
j
.
type_name
())));
}
n
=
nullptr
;
}
// overloads for basic_json template parameters
// overloads for basic_json template parameters
template
<
typename
BasicJsonType
,
typename
ArithmeticType
,
template
<
typename
BasicJsonType
,
typename
ArithmeticType
,
enable_if_t
<
std
::
is_arithmetic
<
ArithmeticType
>
::
value
and
enable_if_t
<
std
::
is_arithmetic
<
ArithmeticType
>
::
value
and
...
...
test/src/unit-conversions.cpp
View file @
347e77bd
...
@@ -433,6 +433,48 @@ TEST_CASE("value conversion")
...
@@ -433,6 +433,48 @@ TEST_CASE("value conversion")
#endif
#endif
}
}
SECTION
(
"get null (implicit)"
)
{
std
::
nullptr_t
n
;
json
j
(
n
);
std
::
nullptr_t
n2
=
j
;
CHECK
(
n2
==
n
);
}
SECTION
(
"get null (explicit)"
)
{
std
::
nullptr_t
n
;
json
j
(
n
);
auto
n2
=
j
.
get
<
std
::
nullptr_t
>
();
CHECK
(
n2
==
n
);
CHECK_THROWS_AS
(
json
(
json
::
value_t
::
string
).
get
<
std
::
nullptr_t
>
(),
json
::
type_error
&
);
CHECK_THROWS_AS
(
json
(
json
::
value_t
::
object
).
get
<
std
::
nullptr_t
>
(),
json
::
type_error
&
);
CHECK_THROWS_AS
(
json
(
json
::
value_t
::
array
).
get
<
std
::
nullptr_t
>
(),
json
::
type_error
&
);
CHECK_THROWS_AS
(
json
(
json
::
value_t
::
boolean
).
get
<
std
::
nullptr_t
>
(),
json
::
type_error
&
);
CHECK_THROWS_AS
(
json
(
json
::
value_t
::
number_integer
).
get
<
std
::
nullptr_t
>
(),
json
::
type_error
&
);
CHECK_THROWS_AS
(
json
(
json
::
value_t
::
number_unsigned
).
get
<
std
::
nullptr_t
>
(),
json
::
type_error
&
);
CHECK_THROWS_AS
(
json
(
json
::
value_t
::
number_float
).
get
<
std
::
nullptr_t
>
(),
json
::
type_error
&
);
CHECK_THROWS_WITH
(
json
(
json
::
value_t
::
string
).
get
<
std
::
nullptr_t
>
(),
"[json.exception.type_error.302] type must be null, but is string"
);
CHECK_THROWS_WITH
(
json
(
json
::
value_t
::
object
).
get
<
std
::
nullptr_t
>
(),
"[json.exception.type_error.302] type must be null, but is object"
);
CHECK_THROWS_WITH
(
json
(
json
::
value_t
::
array
).
get
<
std
::
nullptr_t
>
(),
"[json.exception.type_error.302] type must be null, but is array"
);
CHECK_THROWS_WITH
(
json
(
json
::
value_t
::
boolean
).
get
<
std
::
nullptr_t
>
(),
"[json.exception.type_error.302] type must be null, but is boolean"
);
CHECK_THROWS_WITH
(
json
(
json
::
value_t
::
number_integer
).
get
<
std
::
nullptr_t
>
(),
"[json.exception.type_error.302] type must be null, but is number"
);
CHECK_THROWS_WITH
(
json
(
json
::
value_t
::
number_unsigned
).
get
<
std
::
nullptr_t
>
(),
"[json.exception.type_error.302] type must be null, but is number"
);
CHECK_THROWS_WITH
(
json
(
json
::
value_t
::
number_float
).
get
<
std
::
nullptr_t
>
(),
"[json.exception.type_error.302] type must be null, but is number"
);
}
SECTION
(
"get a string (implicit)"
)
SECTION
(
"get a string (implicit)"
)
{
{
json
::
string_t
s_reference
{
"Hello world"
};
json
::
string_t
s_reference
{
"Hello world"
};
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment