Skip to content

Conversion from alt_json to json produces incorrect result #3425

Description

@falbrechtskirchinger

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?

Activity

  1. added a commit that references this issue on Apr 12, 2022
    ea64a6e
  2. changed the title [-]Conversion from alt_json to json fails to compile[/-] [+]Conversion from alt_json to json produces incorrect result[/+] on Apr 15, 2022
  3. added 2 commits that reference this issue on Jun 3, 2022
    e9c8560
    84ced9b
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions