Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Conversion from alt_json to json produces incorrect result #3425

Open
falbrechtskirchinger opened this issue Apr 6, 2022 · 0 comments · May be fixed by #3518
Open

Conversion from alt_json to json produces incorrect result #3425

falbrechtskirchinger opened this issue Apr 6, 2022 · 0 comments · May be fixed by #3518

Comments

@falbrechtskirchinger
Copy link
Contributor

falbrechtskirchinger commented Apr 6, 2022

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?

falbrechtskirchinger added a commit to falbrechtskirchinger/json that referenced this issue Apr 12, 2022
A unit test in unit-alt_string.cpp converts a json object to an alt_json
object. During the json_pointer refactor this failed to compile and was
commented out.
The failure can no longer be reproduced with the current code.

This commit restores the test to its originally proposed form.

Closes nlohmann#3425.
@falbrechtskirchinger falbrechtskirchinger changed the title Conversion from alt_json to json fails to compile Conversion from alt_json to json produces incorrect result Apr 15, 2022
falbrechtskirchinger added a commit to falbrechtskirchinger/json that referenced this issue Jun 3, 2022
Add wrapper types to encode conversion target value types and to_json
overloads to perform the conversions.

Fixes nlohmann#3425.
falbrechtskirchinger added a commit to falbrechtskirchinger/json that referenced this issue Jun 4, 2022
Add wrapper types to encode conversion target value types and to_json
overloads to perform the conversions.

Fixes nlohmann#3425.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
1 participant