Throw type_error.321 for discarded values in to_bon8 (#5802)

write_bon8_value silently skipped discarded values, but the array/object
count marker still counted them, so [1, discarded] produced 82 91: a marker
announcing two elements followed by one. Throw type_error.321 like the other
binary writers do, at any nesting level.

Signed-off-by: Niels Lohmann <mail@nlohmann.me>
This commit is contained in:
Niels Lohmann authored and GitHub committed 2026-10-11 08:22:00 +02:00
1 parent 6197341a21
commit 74a03dec84
5 files changed
+62 -5

No files matched your search

+5 -1
View File
@@ -22538,6 +22538,8 @@ class binary_writer
/*!
@param[in] j JSON value to serialize
@throw type_error.321 if @a j or a value nested in it is discarded
*/
void write_bon8(const BasicJsonType& j)
{
@@ -24299,6 +24301,8 @@ class binary_writer
@param[in] j JSON value to serialize
@param[in,out] string_open whether the output ends with a non-empty
string that has not been terminated with 0xFF
@throw type_error.321 if @a j or a value nested in it is discarded
*/
void write_bon8_value(const BasicJsonType& j, bool& string_open)
{
@@ -24407,7 +24411,7 @@ class binary_writer
case value_t::discarded:
default:
break;
throw_on_discarded(j, "BON8");
}
}