forked from GAumala/KotlinSnapshot
-
-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Json based serialization format (#46)
* Get a compatible version of the serialization using json but with a custom serializer that adds the class to every type. Not every scenario is working properly, but we are close enough * Customize date serialization * Customize the dates serialization * Add some new scenarios to the serialization using complex nested maps * Update consumers * Update documentation, make the gson serialization format reusable from outside the library and configure the linter to do not evaluate the only java class we have in the project * Change the date format to use a different serialization scheme * Remove the timezone from the date information * Add --info to the travis execution * Force the timezone to be utc when serializing java.util.Date instances * Fix formatting issues * Add changelog section to the documentation * Don't serialize raw strigns as json * Rename the class json key type * Change the date format to use ISO8601 with millis * Fix ktlint issues
- Loading branch information
Showing
41 changed files
with
848 additions
and
101 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
6 changes: 5 additions & 1 deletion
6
...Package_the snap test name will be inferred even the test class doesn't have package.snap
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,5 @@ | ||
Developer(name=Davide, yearsInTheCompany=4) | ||
{ | ||
"__class__": "Developer", | ||
"name": "Davide", | ||
"yearsInTheCompany": 4 | ||
} |
6 changes: 5 additions & 1 deletion
6
...snap_test_name_will_be_inferred_in_test_cases_named_with_spec_if_it_is_not_specified.snap
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,5 @@ | ||
Developer(name=Sergio, yearsInTheCompany=2) | ||
{ | ||
"__class__": "Developer", | ||
"name": "Sergio", | ||
"yearsInTheCompany": 2 | ||
} |
6 changes: 5 additions & 1 deletion
6
...pshot.core.InferenceNameTest_the snap test name will be inferred even if uses spaces.snap
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,5 @@ | ||
Developer(name=Toni, yearsInTheCompany=1) | ||
{ | ||
"__class__": "Developer", | ||
"name": "Toni", | ||
"yearsInTheCompany": 1 | ||
} |
6 changes: 5 additions & 1 deletion
6
...snap_test_name_will_be_inferred_in_test_cases_named_with_test_if_it_is_not_specified.snap
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,5 @@ | ||
Developer(name=Pedro, yearsInTheCompany=3) | ||
{ | ||
"__class__": "Developer", | ||
"name": "Pedro", | ||
"yearsInTheCompany": 3 | ||
} |
2 changes: 1 addition & 1 deletion
2
...hot.core.KotlinSerializationTest_should serialize Date object with time and timezone.snap
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
2007-12-03T18:46:19.333 | ||
"2007-12-03T18:46:19.111Z" |
2 changes: 1 addition & 1 deletion
2
...pshot__/com.karumi.kotlinsnapshot.core.KotlinSerializationTest_should serialize Date.snap
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
2007-12-03T00:00 | ||
"2007-12-03T00:00:00.000Z" |
7 changes: 6 additions & 1 deletion
7
...karumi.kotlinsnapshot.core.KotlinSerializationTest_should serialize LocalDate object.snap
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,6 @@ | ||
2007-12-03 | ||
{ | ||
"__class__": "LocalDate", | ||
"year": 2007, | ||
"month": 12, | ||
"day": 3 | ||
} |
17 changes: 16 additions & 1 deletion
17
...mi.kotlinsnapshot.core.KotlinSerializationTest_should serialize LocalDateTime object.snap
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,16 @@ | ||
2007-12-03T10:15:30 | ||
{ | ||
"__class__": "LocalDateTime", | ||
"date": { | ||
"__class__": "LocalDate", | ||
"year": 2007, | ||
"month": 12, | ||
"day": 3 | ||
}, | ||
"time": { | ||
"__class__": "LocalTime", | ||
"hour": 10, | ||
"minute": 15, | ||
"second": 30, | ||
"nano": 0 | ||
} | ||
} |
1 change: 0 additions & 1 deletion
1
....karumi.kotlinsnapshot.core.KotlinSerializationTest_should serialize a LinkedHashMap.snap
This file was deleted.
Oops, something went wrong.
8 changes: 7 additions & 1 deletion
8
...linSerializationTest_should serialize a class with a kotlin object of a sealed class.snap
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,7 @@ | ||
Request(isSuccess=false, networkError=NotFound) | ||
{ | ||
"__class__": "Request", | ||
"isSuccess": false, | ||
"networkError": { | ||
"__class__": "NotFound" | ||
} | ||
} |
68 changes: 68 additions & 0 deletions
68
...tionTest_should serialize a complex map with any object inside including nested maps.snap
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
{ | ||
"__class__": "LinkedHashMap", | ||
"string": "pedro", | ||
"int": 11, | ||
"long": 111, | ||
"float": 1111.0, | ||
"double": 11111.0, | ||
"user class": { | ||
"__class__": "User", | ||
"id": 2, | ||
"name": "fran" | ||
}, | ||
"address class without user": { | ||
"__class__": "Address", | ||
"postalCode": { | ||
"__class__": "PostCode", | ||
"value": 2 | ||
}, | ||
"streetName": "Elm Street" | ||
}, | ||
"address class with user": { | ||
"__class__": "Address", | ||
"postalCode": { | ||
"__class__": "PostCode", | ||
"value": 2 | ||
}, | ||
"streetName": "Elm Street", | ||
"user": { | ||
"__class__": "User", | ||
"id": 9, | ||
"name": "Sherlok" | ||
} | ||
}, | ||
"complex map": { | ||
"__class__": "LinkedHashMap", | ||
"string": "pedro", | ||
"int": 11, | ||
"long": 111, | ||
"float": 1111.0, | ||
"double": 11111.0, | ||
"user class": { | ||
"__class__": "User", | ||
"id": 2, | ||
"name": "fran" | ||
}, | ||
"address class without user": { | ||
"__class__": "Address", | ||
"postalCode": { | ||
"__class__": "PostCode", | ||
"value": 2 | ||
}, | ||
"streetName": "Elm Street" | ||
}, | ||
"address class with user": { | ||
"__class__": "Address", | ||
"postalCode": { | ||
"__class__": "PostCode", | ||
"value": 2 | ||
}, | ||
"streetName": "Elm Street", | ||
"user": { | ||
"__class__": "User", | ||
"id": 9, | ||
"name": "Sherlok" | ||
} | ||
} | ||
} | ||
} |
35 changes: 34 additions & 1 deletion
35
...om.karumi.kotlinsnapshot.core.KotlinSerializationTest_should serialize a complex map.snap
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,34 @@ | ||
{mobile=[Developer(githubStars=3, name=gabriel), Developer(githubStars=3, name=andres), Developer(githubStars=3, name=miguel)], product=[User(id=1, name=gabriel)], sales=[User(id=1, name=ramon)]} | ||
{ | ||
"__class__": "LinkedHashMap", | ||
"product": [ | ||
{ | ||
"__class__": "User", | ||
"id": 1, | ||
"name": "gabriel" | ||
} | ||
], | ||
"sales": [ | ||
{ | ||
"__class__": "User", | ||
"id": 1, | ||
"name": "ramon" | ||
} | ||
], | ||
"mobile": [ | ||
{ | ||
"__class__": "Developer", | ||
"name": "gabriel", | ||
"githubStars": 3 | ||
}, | ||
{ | ||
"__class__": "Developer", | ||
"name": "andres", | ||
"githubStars": 3 | ||
}, | ||
{ | ||
"__class__": "Developer", | ||
"name": "miguel", | ||
"githubStars": 3 | ||
} | ||
] | ||
} |
6 changes: 5 additions & 1 deletion
6
.../com.karumi.kotlinsnapshot.core.KotlinSerializationTest_should serialize a enum list.snap
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,5 @@ | ||
[INT, DOUBLE, LONG] | ||
[ | ||
"INT", | ||
"DOUBLE", | ||
"LONG" | ||
] |
10 changes: 9 additions & 1 deletion
10
...mi.kotlinsnapshot.core.KotlinSerializationTest_should serialize a kotlin Pair object.snap
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,9 @@ | ||
(1, User(id=1, name=gabriel)) | ||
{ | ||
"__class__": "Pair", | ||
"first": 1, | ||
"second": { | ||
"__class__": "User", | ||
"id": 1, | ||
"name": "gabriel" | ||
} | ||
} |
18 changes: 17 additions & 1 deletion
18
...com.karumi.kotlinsnapshot.core.KotlinSerializationTest_should serialize a kotlin Set.snap
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,17 @@ | ||
[Developer(githubStars=3, name=gabriel), Developer(githubStars=3, name=andres), Developer(githubStars=3, name=miguel)] | ||
[ | ||
{ | ||
"__class__": "Developer", | ||
"name": "gabriel", | ||
"githubStars": 3 | ||
}, | ||
{ | ||
"__class__": "Developer", | ||
"name": "andres", | ||
"githubStars": 3 | ||
}, | ||
{ | ||
"__class__": "Developer", | ||
"name": "miguel", | ||
"githubStars": 3 | ||
} | ||
] |
4 changes: 3 additions & 1 deletion
4
....karumi.kotlinsnapshot.core.KotlinSerializationTest_should serialize a kotlin object.snap
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,3 @@ | ||
KotlinObject | ||
{ | ||
"__class__": "KotlinObject" | ||
} |
22 changes: 22 additions & 0 deletions
22
...com.karumi.kotlinsnapshot.core.KotlinSerializationTest_should serialize a linked map.snap
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
{ | ||
"__class__": "LinkedHashMap", | ||
"product": [ | ||
{ | ||
"__class__": "User", | ||
"id": 1, | ||
"name": "gabriel" | ||
} | ||
], | ||
"sales": [ | ||
{ | ||
"__class__": "User", | ||
"id": 1, | ||
"name": "ramon" | ||
} | ||
], | ||
"mobile": { | ||
"__class__": "Developer", | ||
"name": "miguel", | ||
"githubStars": 3 | ||
} | ||
} |
20 changes: 19 additions & 1 deletion
20
...snapshot.core.KotlinSerializationTest_should serialize a list inside to another list.snap
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,19 @@ | ||
[[User(id=1, name=gabriel), User(id=2, name=andres), User(id=3, name=miguel)]] | ||
[ | ||
[ | ||
{ | ||
"__class__": "User", | ||
"id": 1, | ||
"name": "gabriel" | ||
}, | ||
{ | ||
"__class__": "User", | ||
"id": 2, | ||
"name": "andres" | ||
}, | ||
{ | ||
"__class__": "User", | ||
"id": 3, | ||
"name": "miguel" | ||
} | ||
] | ||
] |
5 changes: 4 additions & 1 deletion
5
...t.core.KotlinSerializationTest_should serialize a null object when is a member field.snap
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,4 @@ | ||
UserWithOptionalName(id=1, name=null) | ||
{ | ||
"__class__": "UserWithOptionalName", | ||
"id": 1 | ||
} |
22 changes: 22 additions & 0 deletions
22
...om.karumi.kotlinsnapshot.core.KotlinSerializationTest_should serialize a regular map.snap
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
{ | ||
"__class__": "LinkedHashMap", | ||
"product": [ | ||
{ | ||
"__class__": "User", | ||
"id": 1, | ||
"name": "gabriel" | ||
} | ||
], | ||
"sales": [ | ||
{ | ||
"__class__": "User", | ||
"id": 1, | ||
"name": "ramon" | ||
} | ||
], | ||
"mobile": { | ||
"__class__": "Developer", | ||
"name": "miguel", | ||
"githubStars": 3 | ||
} | ||
} |
5 changes: 4 additions & 1 deletion
5
...i.kotlinsnapshot.core.KotlinSerializationTest_should serialize a sealed class member.snap
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,4 @@ | ||
BadRequest(error=Body is required.) | ||
{ | ||
"__class__": "BadRequest", | ||
"error": "Body is required." | ||
} |
Oops, something went wrong.