Skip to content

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

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

Merged
merged 9 commits into from
Jan 27, 2022

Conversation

piotrdytkowski
Copy link
Owner

No description provided.

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

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

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

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
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

@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
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

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
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 {

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
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
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

@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
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

@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
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