Skip to content

Can not use JsonNode.with() / .withArray() with JsonPointer #3511

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
timnick-snow opened this issue Jun 7, 2022 · 3 comments
Closed

Can not use JsonNode.with() / .withArray() with JsonPointer #3511

timnick-snow opened this issue Jun 7, 2022 · 3 comments

Comments

@timnick-snow
Copy link

I found #393 and tried to add nodes based on Pointers using the with()/withArray() method, but failed.

    @Test
    public void fun4() throws Exception{
        String json = """
                {
                "k1":"v1",
                "k2":"v2",
                "k3":{
                  "c1":"cv1"
                  }
                }
                """;

        var mapper = new ObjectMapper();
        ObjectNode node = (ObjectNode) mapper.readTree(json);
        ArrayNode arrayNode = node.withArray("/k3/c2");
        arrayNode.add("value_0");

        System.out.println(node);
        assert node.at("/k3/c2/0").asText().equals("value_0");
    }
@timnick-snow timnick-snow added the to-evaluate Issue that has been received but not yet evaluated label Jun 7, 2022
@timnick-snow
Copy link
Author

It looks like the with() method doesn't support JsonPointer. If not, can add support?

@cowtowncoder cowtowncoder added 2.14 and removed to-evaluate Issue that has been received but not yet evaluated labels Jun 7, 2022
@cowtowncoder
Copy link
Member

Yes, that sounds like a good idea, so add:

  • JsonNode.with(JsonPointer)
  • JsonNode.withArray(JsonPointer)

(unfortunately it is not possible to change semantics of existing methods that take String since that would change semantics)

@cowtowncoder cowtowncoder changed the title Pointer based add not work Can not use JsonNode.with() / .withArray() with JsonPointer Jun 7, 2022
@cowtowncoder
Copy link
Member

Oh. Actually we already have #1980 which would do this. Closing this issue, work tracked via #1980.
I don't think it needs to wait until Jackson 3.0, if I have time can add in 2.14.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants