✨ Add Snapshot.ignore(String... jsonPaths) method#10
✨ Add Snapshot.ignore(String... jsonPaths) method#10ftes wants to merge 1 commit intojson-snapshot:masterfrom
Snapshot.ignore(String... jsonPaths) method#10Conversation
|
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 ;). |
There was a problem hiding this comment.
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.
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.
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.
Any way to do this without an extra dependency?
Jackson already uses JsonPointers, 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.
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.
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: