Skip to content

Can we please get containsKey back? #2217

@hoeken

Description

@hoeken

I know and love the Null Object Pattern, but there are a few situations where containsKey() is a better choice.

For example, when you are checking if a member exists, but that member is a zero, then the if statement will evaulate to false:

  if (input["tank_level"]) {
    float level = input["tank_level"];
    wm.setTankLevel(level);
  }

I know there is the .is<> syntax, but semantically it is not nearly as clear as containsKey and is a lot more verbose.

  if (input["tank_level"].is<JsonVariantConst>()) {
    float level = input["tank_level"];
    wm.setTankLevel(level);
  }

It seems completely arbitrary to force the user to use one syntax over the other when you could simply provide access to both.

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions