-
Notifications
You must be signed in to change notification settings - Fork 16
✨ Add Snapshot.ignore(String... jsonPaths)
method
#10
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
base: master
Are you sure you want to change the base?
Conversation
Hey @andrebonna, sorry for taking so long to get back to you. This seems like a better solution than my original PR so hopefully it was for the better ;). |
@@ -69,11 +81,38 @@ private String getRawSnapshot(Collection<String> rawSnapshots) { | |||
return null; | |||
} | |||
|
|||
private Object ignorePaths(Object input) { | |||
DocumentContext context = JsonPath.using(new GsonJsonProvider()).parse(gsonForIgnoringPaths.toJsonTree(input)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Considered alternative: Using a GSON ExclusionStrategy
. However, such a strategy has no notion of the path to a field. The methods in the interface only allow finding the type of the containing class and the name of each field.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Consider changing JSON parser lib to Jackson. We changed default lib from GSON to Jackson due to issue #9
There are some conflicting files as well! |
1fc6c9c
to
f020f04
Compare
I rebased and updated the MR. Switched to Jackson. |
.stream() | ||
.map(delta -> delta.toString() + "\n") | ||
.reduce(String::concat) | ||
.get(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Avoid formatting-only changes
<dependency> | ||
<groupId>com.jayway.jsonpath</groupId> | ||
<artifactId>json-path</artifactId> | ||
<version>2.4.0</version> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Any way to do this without an extra dependency?
Jackson already uses JsonPointer
s, maybe that could be used to specify ignored elements as well?
return Arrays.asList(current).stream() | ||
.map(this::ignorePaths) | ||
.collect(Collectors.toList()) | ||
.toArray(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Stream#toArray(Object[]::new)
?
public void shouldMatchSnapshotAndIgnoreSeveralNestedFieldsMethod() { | ||
FakeObject grandChild = FakeObject.builder().id("grandChild7").value(7).build(); | ||
FakeObject child = FakeObject.builder().id("child7").value(7).fakeObject(grandChild).build(); | ||
expect(FakeObject.builder().id("anyId7").value(7).name("anyName7").fakeObject(child).build()) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd extract creation of test data into a variable, maybe something like:
FakeObject testObject = FakeObject.builder()
.id("anyId7").value(7)
.name("anyName7").fakeObject(FakeObject.builder()
.id("child7").value(7)
.fakeObject(FakeObject.builder()
.id("grandChild7").value(7)
.build()
).build()
).build().
This superseeds #7.
Advantages: