Skip to content

Add JsonNode.asArray() and JsonNode.asObject() #2343

Description

@victornoel

In the same way that there is various methods to manipulate a JsonNode to one of its potential real type (String, boolean, etc), there should be asArray() and asObject() available.

Currently the only way to retrieve a JsonNode as an ObjectNode or an ArrayNode is with the two methods with(String) and withArray(String) (even though in 2.9 their return type is broken).

But for example when manipulating an ArrayNode, it is not possible to get its elements as ArrayNode or ObjectNode (or I didn't find the way to do it).

I would expect to be able, for example, to do:

for(JsonNode node: anArrayNode) {
  node.asObject().set("a", new TextNode("b"));
}

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    3.1node-configRelated to JSTEP-7 Node config/feature

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions