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
60144198
Unverified
Commit
60144198
authored
May 12, 2020
by
Niels Lohmann
Browse files
Options
Browse Files
Download
Plain Diff
Merge branches 'develop' and 'issue2082' of
https://github.com/nlohmann/json
into issue2082
parents
5c428470
1de30bc6
Changes
6
Show whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
46 additions
and
45 deletions
+46
-45
.travis.yml
.travis.yml
+4
-3
README.md
README.md
+1
-0
cmake/download_test_data.cmake
cmake/download_test_data.cmake
+1
-1
test/Makefile
test/Makefile
+6
-3
test/src/unit-noexcept.cpp
test/src/unit-noexcept.cpp
+9
-9
test/src/unit-udt.cpp
test/src/unit-udt.cpp
+25
-29
No files found.
.travis.yml
View file @
60144198
...
...
@@ -95,16 +95,17 @@ matrix:
-
os
:
linux
compiler
:
gcc
dist
:
bionic
addons
:
apt
:
sources
:
[
'
ubuntu-toolchain-r-test'
]
packages
:
[
'
g++-
4.9
'
,
'
ninja-build'
]
packages
:
[
'
g++-
7
'
,
'
ninja-build'
]
before_script
:
-
pip install --user cpp-coveralls
after_success
:
-
coveralls --build-root test --include include/nlohmann --gcov 'gcov-
4.9
' --gcov-options '\-lp'
-
coveralls --build-root test --include include/nlohmann --gcov 'gcov-
7
' --gcov-options '\-lp'
env
:
-
COMPILER=g++-
4.9
-
COMPILER=g++-
7
-
CMAKE_OPTIONS=-DJSON_Coverage=ON
-
MULTIPLE_HEADERS=ON
...
...
README.md
View file @
60144198
...
...
@@ -11,6 +11,7 @@
[
![Try online
](
https://img.shields.io/badge/try-online-blue.svg
)
](https://wandbox.org/permlink/3lCHrFUZANONKv7a)
[
![Documentation
](
https://img.shields.io/badge/docs-doxygen-blue.svg
)
](http://nlohmann.github.io/json)
[
![GitHub license
](
https://img.shields.io/badge/license-MIT-blue.svg
)
](https://raw.githubusercontent.com/nlohmann/json/master/LICENSE.MIT)
[
![FOSSA Status
](
https://app.fossa.com/api/projects/git%2Bgithub.com%2Fnlohmann%2Fjson.svg?type=shield
)
](https://app.fossa.com/projects/git%2Bgithub.com%2Fnlohmann%2Fjson?ref=badge_shield)
[
![GitHub Releases
](
https://img.shields.io/github/release/nlohmann/json.svg
)
](https://github.com/nlohmann/json/releases)
[
![GitHub Downloads
](
https://img.shields.io/github/downloads/nlohmann/json/total
)
](https://github.com/nlohmann/json/releases)
[
![GitHub Issues
](
https://img.shields.io/github/issues/nlohmann/json.svg
)
](http://github.com/nlohmann/json/issues)
...
...
cmake/download_test_data.cmake
View file @
60144198
...
...
@@ -11,4 +11,4 @@ add_custom_target(download_test_data
)
# create a header with the path to the downloaded test data
file
(
WRITE
${
CMAKE_BINARY_DIR
}
/include/test_data.hpp
"#define TEST_DATA_DIRECTORY
\"
${
CMAKE_BINARY_DIR
}
/json_test_data
\"
"
)
file
(
WRITE
${
CMAKE_BINARY_DIR
}
/include/test_data.hpp
"#define TEST_DATA_DIRECTORY
\"
${
CMAKE_BINARY_DIR
}
/json_test_data
\"
\n
"
)
test/Makefile
View file @
60144198
...
...
@@ -57,7 +57,10 @@ TESTCASES = $(patsubst src/unit-%.cpp,test-%,$(wildcard src/unit-*.cpp))
all
:
$(TESTCASES)
clean
:
rm
-fr
json_unit
$(OBJECTS)
$(SOURCES:.cpp=.gcno)
$(SOURCES:.cpp=.gcda)
$(TESTCASES)
$(FUZZERS)
rm
-fr
json_unit
$(OBJECTS)
$(SOURCES:.cpp=.gcno)
$(SOURCES:.cpp=.gcda)
$(TESTCASES)
$(FUZZERS)
test_data.hpp
test_data.hpp
:
@
echo
"#define TEST_DATA_DIRECTORY"
>
$@
##############################################################################
# single test file
...
...
@@ -67,7 +70,7 @@ json_unit: $(OBJECTS) ../single_include/nlohmann/json.hpp thirdparty/doctest/doc
@
echo
"[CXXLD]
$@
"
@
$(CXX)
$(CXXFLAGS)
$(LDFLAGS)
$(OBJECTS)
-o
$@
%.o
:
%.cpp ../single_include/nlohmann/json.hpp thirdparty/doctest/doctest.h
%.o
:
%.cpp ../single_include/nlohmann/json.hpp thirdparty/doctest/doctest.h
test_data.hpp
@
echo
"[CXX]
$@
"
@
$(CXX)
$(CXXFLAGS)
$(CPPFLAGS)
-c
$<
-o
$@
...
...
@@ -76,7 +79,7 @@ json_unit: $(OBJECTS) ../single_include/nlohmann/json.hpp thirdparty/doctest/doc
# individual test cases
##############################################################################
test-%
:
src/unit-%.o src/unit.o ../single_include/nlohmann/json.hpp thirdparty/doctest/doctest.h
test-%
:
src/unit-%.o src/unit.o ../single_include/nlohmann/json.hpp thirdparty/doctest/doctest.h
test_data.hpp
@
echo
"[CXXLD]
$@
"
@
$(CXX)
$(CXXFLAGS)
$(CPPFLAGS)
$(LDFLAGS)
$<
src/unit.o
-o
$@
...
...
test/src/unit-noexcept.cpp
View file @
60144198
...
...
@@ -46,20 +46,20 @@ void to_json(json&, pod) noexcept;
void
to_json
(
json
&
,
pod_bis
);
void
from_json
(
const
json
&
,
pod
)
noexcept
;
void
from_json
(
const
json
&
,
pod_bis
);
static
json
j
;
static
json
*
j
;
static_assert
(
noexcept
(
json
{}),
""
);
static_assert
(
noexcept
(
nlohmann
::
to_json
(
j
,
2
)),
""
);
static_assert
(
noexcept
(
nlohmann
::
to_json
(
j
,
2.5
)),
""
);
static_assert
(
noexcept
(
nlohmann
::
to_json
(
j
,
true
)),
""
);
static_assert
(
noexcept
(
nlohmann
::
to_json
(
j
,
test
{})),
""
);
static_assert
(
noexcept
(
nlohmann
::
to_json
(
j
,
pod
{})),
""
);
static_assert
(
not
noexcept
(
nlohmann
::
to_json
(
j
,
pod_bis
{})),
""
);
static_assert
(
noexcept
(
nlohmann
::
to_json
(
*
j
,
2
)),
""
);
static_assert
(
noexcept
(
nlohmann
::
to_json
(
*
j
,
2.5
)),
""
);
static_assert
(
noexcept
(
nlohmann
::
to_json
(
*
j
,
true
)),
""
);
static_assert
(
noexcept
(
nlohmann
::
to_json
(
*
j
,
test
{})),
""
);
static_assert
(
noexcept
(
nlohmann
::
to_json
(
*
j
,
pod
{})),
""
);
static_assert
(
not
noexcept
(
nlohmann
::
to_json
(
*
j
,
pod_bis
{})),
""
);
static_assert
(
noexcept
(
json
(
2
)),
""
);
static_assert
(
noexcept
(
json
(
test
{})),
""
);
static_assert
(
noexcept
(
json
(
pod
{})),
""
);
static_assert
(
noexcept
(
j
.
get
<
pod
>
()),
""
);
static_assert
(
not
noexcept
(
j
.
get
<
pod_bis
>
()),
""
);
static_assert
(
noexcept
(
j
->
get
<
pod
>
()),
""
);
static_assert
(
not
noexcept
(
j
->
get
<
pod_bis
>
()),
""
);
static_assert
(
noexcept
(
json
(
pod
{})),
""
);
}
...
...
test/src/unit-udt.cpp
View file @
60144198
...
...
@@ -95,19 +95,19 @@ namespace udt
{
// templates because of the custom_json tests (see below)
template
<
typename
BasicJsonType
>
void
to_json
(
BasicJsonType
&
j
,
age
a
)
static
void
to_json
(
BasicJsonType
&
j
,
age
a
)
{
j
=
a
.
m_val
;
}
template
<
typename
BasicJsonType
>
void
to_json
(
BasicJsonType
&
j
,
const
name
&
n
)
static
void
to_json
(
BasicJsonType
&
j
,
const
name
&
n
)
{
j
=
n
.
m_val
;
}
template
<
typename
BasicJsonType
>
void
to_json
(
BasicJsonType
&
j
,
country
c
)
static
void
to_json
(
BasicJsonType
&
j
,
country
c
)
{
switch
(
c
)
{
...
...
@@ -124,54 +124,54 @@ void to_json(BasicJsonType& j, country c)
}
template
<
typename
BasicJsonType
>
void
to_json
(
BasicJsonType
&
j
,
const
person
&
p
)
static
void
to_json
(
BasicJsonType
&
j
,
const
person
&
p
)
{
j
=
BasicJsonType
{{
"age"
,
p
.
m_age
},
{
"name"
,
p
.
m_name
},
{
"country"
,
p
.
m_country
}};
}
void
to_json
(
nlohmann
::
json
&
j
,
const
address
&
a
)
static
void
to_json
(
nlohmann
::
json
&
j
,
const
address
&
a
)
{
j
=
a
.
m_val
;
}
void
to_json
(
nlohmann
::
json
&
j
,
const
contact
&
c
)
static
void
to_json
(
nlohmann
::
json
&
j
,
const
contact
&
c
)
{
j
=
json
{{
"person"
,
c
.
m_person
},
{
"address"
,
c
.
m_address
}};
}
void
to_json
(
nlohmann
::
json
&
j
,
const
contact_book
&
cb
)
static
void
to_json
(
nlohmann
::
json
&
j
,
const
contact_book
&
cb
)
{
j
=
json
{{
"name"
,
cb
.
m_book_name
},
{
"contacts"
,
cb
.
m_contacts
}};
}
// operators
bool
operator
==
(
age
lhs
,
age
rhs
)
static
bool
operator
==
(
age
lhs
,
age
rhs
)
{
return
lhs
.
m_val
==
rhs
.
m_val
;
}
bool
operator
==
(
const
address
&
lhs
,
const
address
&
rhs
)
static
bool
operator
==
(
const
address
&
lhs
,
const
address
&
rhs
)
{
return
lhs
.
m_val
==
rhs
.
m_val
;
}
bool
operator
==
(
const
name
&
lhs
,
const
name
&
rhs
)
static
bool
operator
==
(
const
name
&
lhs
,
const
name
&
rhs
)
{
return
lhs
.
m_val
==
rhs
.
m_val
;
}
bool
operator
==
(
const
person
&
lhs
,
const
person
&
rhs
)
static
bool
operator
==
(
const
person
&
lhs
,
const
person
&
rhs
)
{
return
std
::
tie
(
lhs
.
m_name
,
lhs
.
m_age
)
==
std
::
tie
(
rhs
.
m_name
,
rhs
.
m_age
);
}
bool
operator
==
(
const
contact
&
lhs
,
const
contact
&
rhs
)
static
bool
operator
==
(
const
contact
&
lhs
,
const
contact
&
rhs
)
{
return
std
::
tie
(
lhs
.
m_person
,
lhs
.
m_address
)
==
std
::
tie
(
rhs
.
m_person
,
rhs
.
m_address
);
}
bool
operator
==
(
const
contact_book
&
lhs
,
const
contact_book
&
rhs
)
static
bool
operator
==
(
const
contact_book
&
lhs
,
const
contact_book
&
rhs
)
{
return
std
::
tie
(
lhs
.
m_book_name
,
lhs
.
m_contacts
)
==
std
::
tie
(
rhs
.
m_book_name
,
rhs
.
m_contacts
);
...
...
@@ -182,19 +182,19 @@ bool operator==(const contact_book& lhs, const contact_book& rhs)
namespace
udt
{
template
<
typename
BasicJsonType
>
void
from_json
(
const
BasicJsonType
&
j
,
age
&
a
)
static
void
from_json
(
const
BasicJsonType
&
j
,
age
&
a
)
{
a
.
m_val
=
j
.
template
get
<
int
>();
}
template
<
typename
BasicJsonType
>
void
from_json
(
const
BasicJsonType
&
j
,
name
&
n
)
static
void
from_json
(
const
BasicJsonType
&
j
,
name
&
n
)
{
n
.
m_val
=
j
.
template
get
<
std
::
string
>();
}
template
<
typename
BasicJsonType
>
void
from_json
(
const
BasicJsonType
&
j
,
country
&
c
)
static
void
from_json
(
const
BasicJsonType
&
j
,
country
&
c
)
{
const
auto
str
=
j
.
template
get
<
std
::
string
>();
static
const
std
::
map
<
std
::
string
,
country
>
m
=
...
...
@@ -210,25 +210,25 @@ void from_json(const BasicJsonType& j, country& c)
}
template
<
typename
BasicJsonType
>
void
from_json
(
const
BasicJsonType
&
j
,
person
&
p
)
static
void
from_json
(
const
BasicJsonType
&
j
,
person
&
p
)
{
p
.
m_age
=
j
[
"age"
].
template
get
<
age
>();
p
.
m_name
=
j
[
"name"
].
template
get
<
name
>();
p
.
m_country
=
j
[
"country"
].
template
get
<
country
>();
}
void
from_json
(
const
nlohmann
::
json
&
j
,
address
&
a
)
static
void
from_json
(
const
nlohmann
::
json
&
j
,
address
&
a
)
{
a
.
m_val
=
j
.
get
<
std
::
string
>
();
}
void
from_json
(
const
nlohmann
::
json
&
j
,
contact
&
c
)
static
void
from_json
(
const
nlohmann
::
json
&
j
,
contact
&
c
)
{
c
.
m_person
=
j
[
"person"
].
get
<
person
>
();
c
.
m_address
=
j
[
"address"
].
get
<
address
>
();
}
void
from_json
(
const
nlohmann
::
json
&
j
,
contact_book
&
cb
)
static
void
from_json
(
const
nlohmann
::
json
&
j
,
contact_book
&
cb
)
{
cb
.
m_book_name
=
j
[
"name"
].
get
<
name
>
();
cb
.
m_contacts
=
j
[
"contacts"
].
get
<
std
::
vector
<
contact
>>
();
...
...
@@ -621,29 +621,29 @@ struct non_pod
};
template
<
typename
BasicJsonType
>
void
to_json
(
BasicJsonType
&
j
,
const
non_pod
&
np
)
static
void
to_json
(
BasicJsonType
&
j
,
const
non_pod
&
np
)
{
j
=
np
.
s
;
}
template
<
typename
BasicJsonType
>
void
from_json
(
const
BasicJsonType
&
j
,
non_pod
&
np
)
static
void
from_json
(
const
BasicJsonType
&
j
,
non_pod
&
np
)
{
np
.
s
=
j
.
template
get
<
std
::
string
>();
}
bool
operator
==
(
small_pod
lhs
,
small_pod
rhs
)
noexcept
static
bool
operator
==
(
small_pod
lhs
,
small_pod
rhs
)
noexcept
{
return
std
::
tie
(
lhs
.
begin
,
lhs
.
middle
,
lhs
.
end
)
==
std
::
tie
(
rhs
.
begin
,
rhs
.
middle
,
rhs
.
end
);
}
bool
operator
==
(
const
non_pod
&
lhs
,
const
non_pod
&
rhs
)
noexcept
static
bool
operator
==
(
const
non_pod
&
lhs
,
const
non_pod
&
rhs
)
noexcept
{
return
lhs
.
s
==
rhs
.
s
;
}
std
::
ostream
&
operator
<<
(
std
::
ostream
&
os
,
small_pod
l
)
st
atic
st
d
::
ostream
&
operator
<<
(
std
::
ostream
&
os
,
small_pod
l
)
{
return
os
<<
"begin: "
<<
l
.
begin
<<
", middle: "
<<
l
.
middle
<<
", end: "
<<
l
.
end
;
}
...
...
@@ -691,8 +691,6 @@ struct another_adl_serializer
TEST_CASE
(
"custom serializer that does adl by default"
*
doctest
::
test_suite
(
"udt"
))
{
using
json
=
nlohmann
::
json
;
auto
me
=
udt
::
person
{{
23
},
{
"theo"
},
udt
::
country
::
france
};
json
j
=
me
;
...
...
@@ -706,8 +704,6 @@ TEST_CASE("custom serializer that does adl by default" * doctest::test_suite("ud
TEST_CASE
(
"different basic_json types conversions"
)
{
using
json
=
nlohmann
::
json
;
SECTION
(
"null"
)
{
json
j
;
...
...
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