json
json copied to clipboard
Conversion from alt_json to json produces incorrect result
A proposed unit test for unit-alt-string.cpp contained the following code:
alt_json j = R"(
{
"foo": ["bar", "baz"]
}
)"_json;
This conversion compiles but fails to produce the expected result. Instead, the resulting object is in fact the following array:
[[[102,111,111],[[98,97,114],[98,97,122]]]]
The test can be further reduced to this:
alt_json j = json::object();
Resulting in:
[]
The cause is the incorrect selection of this to_json() function for CompatibleArrayType = std::map<...>.
template < typename BasicJsonType, typename CompatibleArrayType,
enable_if_t < is_compatible_array_type<BasicJsonType,
CompatibleArrayType>::value&&
!is_compatible_object_type<BasicJsonType, CompatibleArrayType>::value&&
!is_compatible_string_type<BasicJsonType, CompatibleArrayType>::value&&
!std::is_same<typename BasicJsonType::binary_t, CompatibleArrayType>::value&&
!is_basic_json<CompatibleArrayType>::value,
int > = 0 >
void to_json(BasicJsonType& j, const CompatibleArrayType& arr)
{
external_constructor<value_t::array>::construct(j, arr);
}
I suspect an error in is_constructible_object_type and will investigate.
The requirements placed on object_t, string_t, etc. should be clearly documented. Maybe a trait like is_sax would help?