Skip to content

Unexpected deserialization difference between Mac and Linux #2338

@wbuck

Description

@wbuck

What is the issue you have?

When deserializing the following json from a file on macOS

{
    "SaveAllImages": true,
    "SaveOnlyFailedImages": false,
    "RedThreshold": 215,
    "MaxRedThreshold": 255,
    "BlueThreshold": 215,
    "MaxBlueThreshold": 255,
    "BlobFilterArea": true,
    "BlobMinAreaPx": 2000,
    "BlobMaxAreaPx": 6000,
    "BlobMinThreshold": 10,
    "BlobMaxThreshold": 10000,
    "BlobFilterCircularity": true,
    "BlobMinCircularity": 0.6,
    "BlobMaxCircularity": 1.0
}

I get an object (which is expected)

{
    "SaveAllImages": true,
    "SaveOnlyFailedImages": false,
    "RedThreshold": 215,
    "MaxRedThreshold": 255,
    "BlueThreshold": 215,
    "MaxBlueThreshold": 255,
    "BlobFilterArea": true,
    "BlobMinAreaPx": 2000,
    "BlobMaxAreaPx": 6000,
    "BlobMinThreshold": 10,
    "BlobMaxThreshold": 10000,
    "BlobFilterCircularity": true,
    "BlobMinCircularity": 0.6,
    "BlobMaxCircularity": 1.0
}

When I run this same code, using the same json file in a docker container running Debian I get an array (unexpected)

 [{
     "SaveAllImages": true,
     "SaveOnlyFailedImages": false,
     "RedThreshold": 215,
     "MaxRedThreshold": 255,
     "BlueThreshold": 215,
     "MaxBlueThreshold": 255,
     "BlobFilterArea": true,
     "BlobMinAreaPx": 2000,
     "BlobMaxAreaPx": 6000,
     "BlobMinThreshold": 10,
     "BlobMaxThreshold": 10000,
     "BlobFilterCircularity": true,
     "BlobMinCircularity": 0.6,
     "BlobMaxCircularity": 1.0
}]

This of course causes an exception be to thrown:

[json.exception.type_error.306] cannot use value() with array

Can you provide a small but working code example?

Reading the file

    std::ifstream file{ config };
    if ( !file.is_open( ) )
    {
        throw create_error( 
            "Get configuration error: Failed to open file {}\n", config );
    }

   // This succeeds.
    try { return json::parse( file ); }
    catch( const json::exception& ex )
    {
        throw create_error( 
            "Get configuration error: Deserialization failed {}\n", ex.what( ) );
    } 

Reading a property

// This throws the exception specified above.
double threshold{ json_reader.value( "BlueThreshold", 215.0 ) };

What is the expected behavior?

I expect deserialization to be the same for both platforms.

And what is the actual behavior instead?

On macOS I get a json object back, on Linux I get an array back.

Which compiler and operating system are you using?

  • Compiler: g++ (Linux) and clang (macOS)

  • Operating system:

  • Host: macOS Catalina

  • Container: Debian

Which version of the library did you use?

  • latest release version 3.9.0
  • other release - please state the version: 3.7.3 (Installed from vcpkg)
  • the develop branch

I'm currently exposing the json file to the container via osxfs

Metadata

Metadata

Assignees

No one assigned

    Labels

    kind: bugsolution: duplicatethe issue is a duplicate; refer to the linked issue insteadstate: needs more infothe author of the issue needs to provide more details

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions