Project

General

Profile

Actions

Support #8402

closed

Json::Array cast problem

Added by Emeric Poupon almost 3 years ago. Updated almost 3 years ago.

Status:
Closed
Priority:
Normal
Assignee:
-
Target version:
-
Start date:
04/22/2021
Due date:
% Done:

0%

Estimated time:

Description

Hello,

Using Wt 4.5.0, I have a Json::Value that I want to be converted into an Array:

    void parseValue(const Wt::Json::Value& value)
    {
        switch (value.type())
        {
        case Wt::Json::Type::Array:
          {
            const Wt::Json::Array& array {static_cast<const Wt::Json::Array&>(value)}; // works fine
            // const Wt::Json::Array& array {value}; // returns an array of size 1, which contains itself an array of size 1 (if using the same inner cast), etc.
           ...

Maybe I missed something in your cast operators and constructors, but not explicitly casting here leads to very weird questionable behaviors.

Actions #1

Updated by Korneel Dumon almost 3 years ago

Hi Emeric,

I think this is more of a c++ pitfall than an api error. The initializer list constructor takes precedence over implicit conversion. The problem goes away if you use round braces. Even better is to use assignment, since this avoids creation of a temporary object:
const Wt::Json::Array& array = value;

Actions #2

Updated by Emeric Poupon almost 3 years ago

Hello!
Ah I missed this constructor indeed!
Ok I understand your point then.

Actions #3

Updated by Roel Standaert almost 3 years ago

  • Tracker changed from Bug to Support
  • Status changed from New to Closed
Actions

Also available in: Atom PDF