Skip to content

[US642] JSON Patch Query preparations - use JsonPath instead of JsonPointer#1

Merged
piotrdytkowski merged 9 commits intomasterfrom
US642-json-patch-query
Jan 27, 2022
Merged

[US642] JSON Patch Query preparations - use JsonPath instead of JsonPointer#1
piotrdytkowski merged 9 commits intomasterfrom
US642-json-patch-query

Conversation

@piotrdytkowski
Copy link
Copy Markdown
Owner

No description provided.

DocumentContext nodeContext = JsonPath.parse(node.deepCopy());

final JsonNode parentNode = nodeContext.read(jsonPath);
if (parentNode == null)
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would put { } around, same applies to other one-liner ifs

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That should be done for all one liner ifs.

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

throw new JsonPatchException(BUNDLE.getMessage(
"jsonPatch.noSuchPath"));
public JsonNode apply(final JsonNode node) throws JsonPatchException {
String jsonPath = JsonPathParser.tmfStringToJsonPath(from);
Copy link
Copy Markdown

@lukaszgawel lukaszgawel Jan 26, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here is no final keyword, line below (and other places) it is. Is there a specific reason/convention for that? I can live with no final in front of local vars.

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, it was just me being a bit frivolous with final, fixed

if (parentNode.isMissingNode())
throw new JsonPatchException(BUNDLE.getMessage(
"jsonPatch.noSuchParent"));
final int lastSlashIndex = path.lastIndexOf('/');
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we have a test with paths like
/this/is/my/path
and
/this/is/my/path/

Will both work?

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

First path obviously works.
Technically the second path leads to an element with name equal to empty string, inside a node with name "path", this is currently not working in json path anyway, I filed a ticket for it and it's on our channel.
Our implementation might work with it, but tests are commented out due to that bug.


import java.io.IOException;

public class AddQueryOperationTest extends Object {
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

extends Object isn't it by default?

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a bit ugly, because I couldn't ignore a test in testng. It's a special case, because annotation is in a superclass, so two standard methods I used didn't work (or actually worked intermittently).
I added a comment:
// TODO extend with JsonPatchOperationTest and uncomment constructor when this test needs to be active, couldn't ignore it otherway

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I tried @ignore from testng and @test(enabled = false)

public class AddQueryOperationTest extends Object {

public AddQueryOperationTest() throws IOException {
//super("query/add");
Copy link
Copy Markdown

@lukaszgawel lukaszgawel Jan 26, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do we need it? (similar in other *OperationTest classes)

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Commented above

return "$";
}
final String jsonPath = "$" + path.replace('/', '.')
.replaceAll("\\.(\\d+)\\.", ".[$1].")
Copy link
Copy Markdown

@meehaws meehaws Jan 26, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we move those regexps to final statics fields and give them meaningful description?

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, done

@piotrdytkowski piotrdytkowski merged commit 95b036b into master Jan 27, 2022
@piotrdytkowski piotrdytkowski changed the title [US642] JSON Patch Query [US642] JSON Patch Query preparations - use JsonPath instead of JsonPointer Jan 27, 2022
@piotrdytkowski piotrdytkowski deleted the US642-json-patch-query branch February 2, 2022 12:47
gravity9piotr added a commit that referenced this pull request Feb 8, 2022
[US642] Update project settings (#3)
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

Successfully merging this pull request may close these issues.

3 participants