Skip to content

Additional cast methods for JsonValue #401

@MikeEdgar

Description

@MikeEdgar

As of 1.1, the JsonValue interface provides convenience methods to cast the value to JsonObject and JsonArray. Is there a reason to limit things to those two cases?

Currently, the approach to get a value via a pointer looks like:

JsonObject obj = ...;
String target = ((JsonString) obj.getValue("/some/path/0/to/my/string")).getString();

It would be slightly nicer for the following:

JsonObject obj = ...;
String target = obj.getValue("/some/path/0/to/my/string").asJsonString().getString();

Similarly, methods for asJsonNumber and asJsonBoolean, perhaps with overloads that tolerate the ValueType of NULL with a default argument.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions