Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
J
json
Project
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Chen Yisong
json
Commits
f1482d1f
Commit
f1482d1f
authored
Jan 14, 2017
by
Théo DELRIEU
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
more tests in unit-udt
parent
f2c71faf
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
11 additions
and
3 deletions
+11
-3
unit-udt.cpp
test/src/unit-udt.cpp
+11
-3
No files found.
test/src/unit-udt.cpp
View file @
f1482d1f
...
@@ -394,15 +394,22 @@ namespace nlohmann
...
@@ -394,15 +394,22 @@ namespace nlohmann
template
<>
template
<>
struct
adl_serializer
<
std
::
vector
<
float
>>
struct
adl_serializer
<
std
::
vector
<
float
>>
{
{
static
void
to_json
(
json
&
j
,
std
::
vector
<
float
>
const
&
)
using
type
=
std
::
vector
<
float
>
;
static
void
to_json
(
json
&
j
,
type
const
&
)
{
{
j
=
"hijacked!"
;
j
=
"hijacked!"
;
}
}
static
void
from_json
(
json
const
&
,
std
::
vector
<
float
>
&
opt
)
static
void
from_json
(
json
const
&
,
type
&
opt
)
{
{
opt
=
{
42.0
,
42.0
,
42.0
};
opt
=
{
42.0
,
42.0
,
42.0
};
}
}
// preferred version
static
type
from_json
(
json
const
&
)
{
return
{
4.0
,
5.0
,
6.0
};
}
};
};
}
}
...
@@ -411,7 +418,8 @@ TEST_CASE("even supported types can be specialized", "[udt]")
...
@@ -411,7 +418,8 @@ TEST_CASE("even supported types can be specialized", "[udt]")
json
j
=
std
::
vector
<
float
>
{
1.0
,
2.0
,
3.0
};
json
j
=
std
::
vector
<
float
>
{
1.0
,
2.0
,
3.0
};
CHECK
(
j
.
dump
()
==
R"("hijacked!")"
);
CHECK
(
j
.
dump
()
==
R"("hijacked!")"
);
auto
f
=
j
.
get
<
std
::
vector
<
float
>>
();
auto
f
=
j
.
get
<
std
::
vector
<
float
>>
();
CHECK
((
f
==
std
::
vector
<
float
>
{
42.0
,
42.0
,
42.0
}));
// the single argument from_json method is preferred
CHECK
((
f
==
std
::
vector
<
float
>
{
4.0
,
5.0
,
6.0
}));
}
}
namespace
nlohmann
namespace
nlohmann
...
...
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