Skip to content

Commit f5daf26

Browse files
committed
Fix for "Lib can not be used with Jackson 2.10.0 or later" json-snapshot#27
Slightly change the json formatter. Means that one might have to search&replace all existing snap files (if "strict" matching is used)
1 parent 09eaf2a commit f5daf26

File tree

4 files changed

+55
-65
lines changed

4 files changed

+55
-65
lines changed

src/main/java/io/github/jsonSnapshot/SnapshotMatcher.java

+2-12
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@
2424
import com.fasterxml.jackson.core.util.DefaultIndenter;
2525
import com.fasterxml.jackson.core.util.DefaultPrettyPrinter;
2626
import com.fasterxml.jackson.core.util.DefaultPrettyPrinter.Indenter;
27-
import com.fasterxml.jackson.core.util.Separators;
2827
import com.fasterxml.jackson.databind.ObjectMapper;
2928
import com.fasterxml.jackson.databind.SerializationFeature;
3029

@@ -128,17 +127,8 @@ static Function<Object, String> defaultJsonFunction() {
128127
}
129128

130129
private static PrettyPrinter buildDefaultPrettyPrinter() {
131-
DefaultPrettyPrinter pp =
132-
new DefaultPrettyPrinter("") {
133-
@Override
134-
public DefaultPrettyPrinter withSeparators(Separators separators) {
135-
this._separators = separators;
136-
this._objectFieldValueSeparatorWithSpaces =
137-
separators.getObjectFieldValueSeparator() + " ";
138-
return this;
139-
}
140-
};
141-
Indenter lfOnlyIndenter = new DefaultIndenter(" ", "\n");
130+
final Indenter lfOnlyIndenter = new DefaultIndenter(" ", "\n");
131+
final DefaultPrettyPrinter pp = new DefaultPrettyPrinter("");
142132
pp.indentArraysWith(lfOnlyIndenter);
143133
pp.indentObjectsWith(lfOnlyIndenter);
144134
return pp;

src/test/java/io/github/jsonSnapshot/BackwardCompatilbleTest.snap

+14-14
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,19 @@
11
io.github.jsonSnapshot.BackwardCompatilbleTest.shouldExtractArgsFromFakeMethodWithComplexObject=[
22
{
3-
"FakeObject.fakeMethodWithComplexObject": [
3+
"FakeObject.fakeMethodWithComplexObject" : [
44
{
5-
"arg0": {
6-
"id": "idMock"
5+
"arg0" : {
6+
"id" : "idMock"
77
}
88
}
99
]
1010
},
1111
{
12-
"FakeObject.fakeMethodWithComplexObject": [
12+
"FakeObject.fakeMethodWithComplexObject" : [
1313
{
14-
"arg0": {
15-
"id": "idMock",
16-
"name": "nameMock"
14+
"arg0" : {
15+
"id" : "idMock",
16+
"name" : "nameMock"
1717
}
1818
}
1919
]
@@ -23,18 +23,18 @@ io.github.jsonSnapshot.BackwardCompatilbleTest.shouldExtractArgsFromFakeMethodWi
2323

2424
io.github.jsonSnapshot.BackwardCompatilbleTest.shouldExtractArgsFromMethod=[
2525
{
26-
"FakeObject.fakeMethod": [
26+
"FakeObject.fakeMethod" : [
2727
{
28-
"arg0": "test1",
29-
"arg1": 1,
30-
"arg2": [
28+
"arg0" : "test1",
29+
"arg1" : 1,
30+
"arg2" : [
3131
"listTest1"
3232
]
3333
},
3434
{
35-
"arg0": "test2",
36-
"arg1": 2,
37-
"arg2": [
35+
"arg0" : "test2",
36+
"arg1" : 2,
37+
"arg2" : [
3838
"listTest1",
3939
"listTest2"
4040
]
Original file line numberDiff line numberDiff line change
@@ -1,52 +1,52 @@
11
io.github.jsonSnapshot.SnapshotIntegrationTest.shouldMatchSnapshotFour=[
22
{
3-
"id": "anyId4",
4-
"value": 4,
5-
"name": "any\n\n\nName4"
3+
"id" : "anyId4",
4+
"value" : 4,
5+
"name" : "any\n\n\nName4"
66
}
77
]
88

99

1010
io.github.jsonSnapshot.SnapshotIntegrationTest.shouldMatchSnapshotInsidePrivateMethod=[
1111
{
12-
"id": "anyPrivate",
13-
"value": 5,
14-
"name": "anyPrivate"
12+
"id" : "anyPrivate",
13+
"value" : 5,
14+
"name" : "anyPrivate"
1515
}
1616
]
1717

1818

1919
io.github.jsonSnapshot.SnapshotIntegrationTest.shouldMatchSnapshotOne=[
2020
{
21-
"id": "anyId1",
22-
"value": 1,
23-
"name": "anyName1"
21+
"id" : "anyId1",
22+
"value" : 1,
23+
"name" : "anyName1"
2424
}
2525
]
2626

2727

2828
io.github.jsonSnapshot.SnapshotIntegrationTest.shouldMatchSnapshotThree=[
2929
{
30-
"id": "anyId3",
31-
"value": 3,
32-
"name": "anyName3"
30+
"id" : "anyId3",
31+
"value" : 3,
32+
"name" : "anyName3"
3333
}
3434
]
3535

3636

3737
io.github.jsonSnapshot.SnapshotIntegrationTest.shouldMatchSnapshotTwo=[
3838
{
39-
"id": "anyId2",
40-
"value": 2,
41-
"name": "anyName2"
39+
"id" : "anyId2",
40+
"value" : 2,
41+
"name" : "anyName2"
4242
}
4343
]
4444

4545

4646
io.github.jsonSnapshot.SnapshotIntegrationTest.shouldThrowSnapshotMatchException=[
4747
{
48-
"id": "anyId5",
49-
"value": 5,
50-
"name": "anyName5"
48+
"id" : "anyId5",
49+
"value" : 5,
50+
"name" : "anyName5"
5151
}
5252
]

src/test/java/io/github/jsonSnapshot/SnapshotUtilsTest.snap

+21-21
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
11
io.github.jsonSnapshot.SnapshotUtilsTest.shouldExtractArgsFromFakeMethod=[
22
{
3-
"FakeObject.fakeMethod": [
3+
"FakeObject.fakeMethod" : [
44
{
5-
"arg0": "test1",
6-
"arg1": 1,
7-
"arg2": [
5+
"arg0" : "test1",
6+
"arg1" : 1,
7+
"arg2" : [
88
"listTest1"
99
]
1010
},
1111
{
12-
"arg0": "test2",
13-
"arg1": 2,
14-
"arg2": [
12+
"arg0" : "test2",
13+
"arg1" : 2,
14+
"arg2" : [
1515
"listTest1",
1616
"listTest2"
1717
]
@@ -23,20 +23,20 @@ io.github.jsonSnapshot.SnapshotUtilsTest.shouldExtractArgsFromFakeMethod=[
2323

2424
io.github.jsonSnapshot.SnapshotUtilsTest.shouldExtractArgsFromFakeMethodWithComplexFakeObject=[
2525
{
26-
"FakeObject.fakeMethodWithComplexObject": [
26+
"FakeObject.fakeMethodWithComplexObject" : [
2727
{
28-
"arg0": {
29-
"id": "idMock"
28+
"arg0" : {
29+
"id" : "idMock"
3030
}
3131
}
3232
]
3333
},
3434
{
35-
"FakeObject.fakeMethodWithComplexObject": [
35+
"FakeObject.fakeMethodWithComplexObject" : [
3636
{
37-
"arg0": {
38-
"id": "idMock",
39-
"name": "nameMock"
37+
"arg0" : {
38+
"id" : "idMock",
39+
"name" : "nameMock"
4040
}
4141
}
4242
]
@@ -46,20 +46,20 @@ io.github.jsonSnapshot.SnapshotUtilsTest.shouldExtractArgsFromFakeMethodWithComp
4646

4747
io.github.jsonSnapshot.SnapshotUtilsTest.shouldExtractArgsFromFakeMethodWithComplexObject=[
4848
{
49-
"FakeObject.fakeMethodWithComplexFakeObject": [
49+
"FakeObject.fakeMethodWithComplexFakeObject" : [
5050
{
51-
"arg0": {
52-
"id": "idMock"
51+
"arg0" : {
52+
"id" : "idMock"
5353
}
5454
}
5555
]
5656
},
5757
{
58-
"FakeObject.fakeMethodWithComplexFakeObject": [
58+
"FakeObject.fakeMethodWithComplexFakeObject" : [
5959
{
60-
"arg0": {
61-
"id": "idMock",
62-
"name": "nameMock"
60+
"arg0" : {
61+
"id" : "idMock",
62+
"name" : "nameMock"
6363
}
6464
}
6565
]

0 commit comments

Comments
 (0)