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
db013c94
Unverified
Commit
db013c94
authored
Apr 29, 2020
by
Niels Lohmann
Committed by
GitHub
Apr 29, 2020
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #2071 from nlohmann/issue2067
Properly pass serialize_binary to dump function
parents
b1fe6ee0
2e5727d7
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
34 additions
and
20 deletions
+34
-20
include/nlohmann/detail/output/serializer.hpp
include/nlohmann/detail/output/serializer.hpp
+8
-8
include/nlohmann/json.hpp
include/nlohmann/json.hpp
+2
-2
single_include/nlohmann/json.hpp
single_include/nlohmann/json.hpp
+10
-10
test/src/unit-regression.cpp
test/src/unit-regression.cpp
+14
-0
No files found.
include/nlohmann/detail/output/serializer.hpp
View file @
db013c94
...
...
@@ -127,7 +127,7 @@ class serializer
o
->
write_character
(
'\"'
);
dump_escaped
(
i
->
first
,
ensure_ascii
);
o
->
write_characters
(
"
\"
: "
,
3
);
dump
(
i
->
second
,
true
,
ensure_ascii
,
indent_step
,
new_indent
);
dump
(
i
->
second
,
true
,
ensure_ascii
,
indent_step
,
new_indent
,
serialize_binary
);
o
->
write_characters
(
",
\n
"
,
2
);
}
...
...
@@ -138,7 +138,7 @@ class serializer
o
->
write_character
(
'\"'
);
dump_escaped
(
i
->
first
,
ensure_ascii
);
o
->
write_characters
(
"
\"
: "
,
3
);
dump
(
i
->
second
,
true
,
ensure_ascii
,
indent_step
,
new_indent
);
dump
(
i
->
second
,
true
,
ensure_ascii
,
indent_step
,
new_indent
,
serialize_binary
);
o
->
write_character
(
'\n'
);
o
->
write_characters
(
indent_string
.
c_str
(),
current_indent
);
...
...
@@ -155,7 +155,7 @@ class serializer
o
->
write_character
(
'\"'
);
dump_escaped
(
i
->
first
,
ensure_ascii
);
o
->
write_characters
(
"
\"
:"
,
2
);
dump
(
i
->
second
,
false
,
ensure_ascii
,
indent_step
,
current_indent
);
dump
(
i
->
second
,
false
,
ensure_ascii
,
indent_step
,
current_indent
,
serialize_binary
);
o
->
write_character
(
','
);
}
...
...
@@ -165,7 +165,7 @@ class serializer
o
->
write_character
(
'\"'
);
dump_escaped
(
i
->
first
,
ensure_ascii
);
o
->
write_characters
(
"
\"
:"
,
2
);
dump
(
i
->
second
,
false
,
ensure_ascii
,
indent_step
,
current_indent
);
dump
(
i
->
second
,
false
,
ensure_ascii
,
indent_step
,
current_indent
,
serialize_binary
);
o
->
write_character
(
'}'
);
}
...
...
@@ -197,14 +197,14 @@ class serializer
i
!=
val
.
m_value
.
array
->
cend
()
-
1
;
++
i
)
{
o
->
write_characters
(
indent_string
.
c_str
(),
new_indent
);
dump
(
*
i
,
true
,
ensure_ascii
,
indent_step
,
new_indent
);
dump
(
*
i
,
true
,
ensure_ascii
,
indent_step
,
new_indent
,
serialize_binary
);
o
->
write_characters
(
",
\n
"
,
2
);
}
// last element
assert
(
not
val
.
m_value
.
array
->
empty
());
o
->
write_characters
(
indent_string
.
c_str
(),
new_indent
);
dump
(
val
.
m_value
.
array
->
back
(),
true
,
ensure_ascii
,
indent_step
,
new_indent
);
dump
(
val
.
m_value
.
array
->
back
(),
true
,
ensure_ascii
,
indent_step
,
new_indent
,
serialize_binary
);
o
->
write_character
(
'\n'
);
o
->
write_characters
(
indent_string
.
c_str
(),
current_indent
);
...
...
@@ -218,13 +218,13 @@ class serializer
for
(
auto
i
=
val
.
m_value
.
array
->
cbegin
();
i
!=
val
.
m_value
.
array
->
cend
()
-
1
;
++
i
)
{
dump
(
*
i
,
false
,
ensure_ascii
,
indent_step
,
current_indent
);
dump
(
*
i
,
false
,
ensure_ascii
,
indent_step
,
current_indent
,
serialize_binary
);
o
->
write_character
(
','
);
}
// last element
assert
(
not
val
.
m_value
.
array
->
empty
());
dump
(
val
.
m_value
.
array
->
back
(),
false
,
ensure_ascii
,
indent_step
,
current_indent
);
dump
(
val
.
m_value
.
array
->
back
(),
false
,
ensure_ascii
,
indent_step
,
current_indent
,
serialize_binary
);
o
->
write_character
(
']'
);
}
...
...
include/nlohmann/json.hpp
View file @
db013c94
...
...
@@ -2237,11 +2237,11 @@ class basic_json
if
(
indent
>=
0
)
{
s
.
dump
(
*
this
,
true
,
ensure_ascii
,
static_cast
<
unsigned
int
>
(
indent
),
serialize_binary
);
s
.
dump
(
*
this
,
true
,
ensure_ascii
,
static_cast
<
unsigned
int
>
(
indent
),
0
,
serialize_binary
);
}
else
{
s
.
dump
(
*
this
,
false
,
ensure_ascii
,
0
,
serialize_binary
);
s
.
dump
(
*
this
,
false
,
ensure_ascii
,
0
,
0
,
serialize_binary
);
}
return
result
;
...
...
single_include/nlohmann/json.hpp
View file @
db013c94
...
...
@@ -14760,7 +14760,7 @@ class serializer
o
->
write_character
(
'\"'
);
dump_escaped
(
i
->
first
,
ensure_ascii
);
o
->
write_characters
(
"
\"
: "
,
3
);
dump
(
i
->
second
,
true
,
ensure_ascii
,
indent_step
,
new_indent
);
dump
(
i
->
second
,
true
,
ensure_ascii
,
indent_step
,
new_indent
,
serialize_binary
);
o
->
write_characters
(
",
\n
"
,
2
);
}
...
...
@@ -14771,7 +14771,7 @@ class serializer
o
->
write_character
(
'\"'
);
dump_escaped
(
i
->
first
,
ensure_ascii
);
o
->
write_characters
(
"
\"
: "
,
3
);
dump
(
i
->
second
,
true
,
ensure_ascii
,
indent_step
,
new_indent
);
dump
(
i
->
second
,
true
,
ensure_ascii
,
indent_step
,
new_indent
,
serialize_binary
);
o
->
write_character
(
'\n'
);
o
->
write_characters
(
indent_string
.
c_str
(),
current_indent
);
...
...
@@ -14788,7 +14788,7 @@ class serializer
o
->
write_character
(
'\"'
);
dump_escaped
(
i
->
first
,
ensure_ascii
);
o
->
write_characters
(
"
\"
:"
,
2
);
dump
(
i
->
second
,
false
,
ensure_ascii
,
indent_step
,
current_indent
);
dump
(
i
->
second
,
false
,
ensure_ascii
,
indent_step
,
current_indent
,
serialize_binary
);
o
->
write_character
(
','
);
}
...
...
@@ -14798,7 +14798,7 @@ class serializer
o
->
write_character
(
'\"'
);
dump_escaped
(
i
->
first
,
ensure_ascii
);
o
->
write_characters
(
"
\"
:"
,
2
);
dump
(
i
->
second
,
false
,
ensure_ascii
,
indent_step
,
current_indent
);
dump
(
i
->
second
,
false
,
ensure_ascii
,
indent_step
,
current_indent
,
serialize_binary
);
o
->
write_character
(
'}'
);
}
...
...
@@ -14830,14 +14830,14 @@ class serializer
i
!=
val
.
m_value
.
array
->
cend
()
-
1
;
++
i
)
{
o
->
write_characters
(
indent_string
.
c_str
(),
new_indent
);
dump
(
*
i
,
true
,
ensure_ascii
,
indent_step
,
new_indent
);
dump
(
*
i
,
true
,
ensure_ascii
,
indent_step
,
new_indent
,
serialize_binary
);
o
->
write_characters
(
",
\n
"
,
2
);
}
// last element
assert
(
not
val
.
m_value
.
array
->
empty
());
o
->
write_characters
(
indent_string
.
c_str
(),
new_indent
);
dump
(
val
.
m_value
.
array
->
back
(),
true
,
ensure_ascii
,
indent_step
,
new_indent
);
dump
(
val
.
m_value
.
array
->
back
(),
true
,
ensure_ascii
,
indent_step
,
new_indent
,
serialize_binary
);
o
->
write_character
(
'\n'
);
o
->
write_characters
(
indent_string
.
c_str
(),
current_indent
);
...
...
@@ -14851,13 +14851,13 @@ class serializer
for
(
auto
i
=
val
.
m_value
.
array
->
cbegin
();
i
!=
val
.
m_value
.
array
->
cend
()
-
1
;
++
i
)
{
dump
(
*
i
,
false
,
ensure_ascii
,
indent_step
,
current_indent
);
dump
(
*
i
,
false
,
ensure_ascii
,
indent_step
,
current_indent
,
serialize_binary
);
o
->
write_character
(
','
);
}
// last element
assert
(
not
val
.
m_value
.
array
->
empty
());
dump
(
val
.
m_value
.
array
->
back
(),
false
,
ensure_ascii
,
indent_step
,
current_indent
);
dump
(
val
.
m_value
.
array
->
back
(),
false
,
ensure_ascii
,
indent_step
,
current_indent
,
serialize_binary
);
o
->
write_character
(
']'
);
}
...
...
@@ -17723,11 +17723,11 @@ class basic_json
if
(
indent
>=
0
)
{
s
.
dump
(
*
this
,
true
,
ensure_ascii
,
static_cast
<
unsigned
int
>
(
indent
),
serialize_binary
);
s
.
dump
(
*
this
,
true
,
ensure_ascii
,
static_cast
<
unsigned
int
>
(
indent
),
0
,
serialize_binary
);
}
else
{
s
.
dump
(
*
this
,
false
,
ensure_ascii
,
0
,
serialize_binary
);
s
.
dump
(
*
this
,
false
,
ensure_ascii
,
0
,
0
,
serialize_binary
);
}
return
result
;
...
...
test/src/unit-regression.cpp
View file @
db013c94
...
...
@@ -1904,6 +1904,20 @@ TEST_CASE("regression tests")
const
auto
result
=
json
::
diff
(
source
,
target
);
CHECK
(
result
.
dump
()
==
R"([{"op":"add","path":"/foo/-","value":"3"}])"
);
}
SECTION
(
"issue #2067 - cannot serialize binary data to text JSON"
)
{
const
unsigned
char
data
[]
=
{
0x81
,
0xA4
,
0x64
,
0x61
,
0x74
,
0x61
,
0xC4
,
0x0F
,
0x33
,
0x30
,
0x30
,
0x32
,
0x33
,
0x34
,
0x30
,
0x31
,
0x30
,
0x37
,
0x30
,
0x35
,
0x30
,
0x31
,
0x30
};
json
j
=
json
::
from_msgpack
(
data
,
sizeof
(
data
)
/
sizeof
(
data
[
0
]));
CHECK_NOTHROW
(
j
.
dump
(
4
,
// Indent
' '
,
// Indent char
false
,
// Ensure ascii
json
::
error_handler_t
::
strict
,
// Error
true
// Allow binary data
)
);
}
}
#if not defined(JSON_NOEXCEPTION)
...
...
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