Skip to content

Commit

Permalink
Deserialize JSON using KotlinX Serialization instead of Gson (#270)
Browse files Browse the repository at this point in the history
* Add Kotlin serialization library

* Prepare all entities to be serializable by kotlinx serializer

* Use Kotlin serializer instead of Gson

* Ensure accounts ids are String in test JSON files as defined in API doc

* Move Json base settings to internal object

* Remove remnants of Gson and replace them with kotlinx.Json

* Detekt/checkstyle

* Remove MastodonClient#getSerializer, instead use module object Json

* Replace star imports with single imports

* Do not share kotlinx serialization dependency with library consumers

* Change recently merged data classes to kotlinx Serializable

* Remove serializer from MockClient
  • Loading branch information
PattaFeuFeu authored Oct 15, 2023
1 parent 06c53e5 commit 1d4c306
Show file tree
Hide file tree
Showing 79 changed files with 759 additions and 746 deletions.
1 change: 0 additions & 1 deletion bigbone-rx/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,4 @@ dependencies {
testRuntimeOnly libs.junit.platform.launcher
testImplementation libs.mockk
testImplementation libs.mockk.dsl
testImplementation libs.gson
}
80 changes: 40 additions & 40 deletions bigbone-rx/src/test/assets/public_timeline.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
"following_count": 0,
"header": "https://mstdn.jp/headers/original/missing.png",
"header_static": "https://mstdn.jp/headers/original/missing.png",
"id": 14476,
"id": "14476",
"locked": false,
"note": "フリーなエンジニア時々詩人。",
"statuses_count": 10,
Expand All @@ -22,7 +22,7 @@
"created_at": "2017-04-14T06:11:41.893Z",
"favourited": null,
"favourites_count": 0,
"id": 172429,
"id": "172429",
"in_reply_to_account_id": null,
"in_reply_to_id": null,
"media_attachments": [],
Expand All @@ -48,7 +48,7 @@
"following_count": 0,
"header": "https://mstdn.jp/headers/original/missing.png",
"header_static": "https://mstdn.jp/headers/original/missing.png",
"id": 42423,
"id": "42423",
"locked": false,
"note": "",
"statuses_count": 2,
Expand All @@ -60,7 +60,7 @@
"created_at": "2017-04-14T06:10:13.000Z",
"favourited": null,
"favourites_count": 0,
"id": 172427,
"id": "172427",
"in_reply_to_account_id": null,
"in_reply_to_id": null,
"media_attachments": [],
Expand All @@ -86,7 +86,7 @@
"following_count": 2,
"header": "https://mstdn.jp/system/accounts/headers/000/004/834/original/missing.png?1492054575",
"header_static": "https://mstdn.jp/system/accounts/headers/000/004/834/original/missing.png?1492054575",
"id": 4834,
"id": "4834",
"locked": false,
"note": "",
"statuses_count": 33,
Expand All @@ -98,7 +98,7 @@
"created_at": "2017-04-14T06:10:22.000Z",
"favourited": null,
"favourites_count": 0,
"id": 172426,
"id": "172426",
"in_reply_to_account_id": null,
"in_reply_to_id": null,
"media_attachments": [],
Expand All @@ -124,7 +124,7 @@
"following_count": 0,
"header": "https://mstdn.jp/headers/original/missing.png",
"header_static": "https://mstdn.jp/headers/original/missing.png",
"id": 35320,
"id": "35320",
"locked": false,
"note": "",
"statuses_count": 83,
Expand All @@ -136,7 +136,7 @@
"created_at": "2017-04-14T06:11:36.000Z",
"favourited": null,
"favourites_count": 0,
"id": 172424,
"id": "172424",
"in_reply_to_account_id": null,
"in_reply_to_id": null,
"media_attachments": [],
Expand All @@ -162,7 +162,7 @@
"following_count": 6,
"header": "https://mstdn.jp/system/accounts/headers/000/016/783/original/missing.png?1492105023",
"header_static": "https://mstdn.jp/system/accounts/headers/000/016/783/original/missing.png?1492105023",
"id": 16783,
"id": "16783",
"locked": false,
"note": "<a href=\"https://yukkurisinai.net\" rel=\"nofollow noopener\"><span class=\"invisible\">https://</span><span class=\"\">yukkurisinai.net</span><span class=\"invisible\"></span></a>",
"statuses_count": 139,
Expand All @@ -174,7 +174,7 @@
"created_at": "2017-04-14T06:10:24.000Z",
"favourited": null,
"favourites_count": 0,
"id": 172422,
"id": "172422",
"in_reply_to_account_id": null,
"in_reply_to_id": null,
"media_attachments": [],
Expand All @@ -200,7 +200,7 @@
"following_count": 10,
"header": "https://mstdn.jp/system/accounts/headers/000/005/632/original/babb0abc2698d65a.png?1492064426",
"header_static": "https://mstdn.jp/system/accounts/headers/000/005/632/original/babb0abc2698d65a.png?1492064426",
"id": 5632,
"id": "5632",
"locked": false,
"note": "",
"statuses_count": 41,
Expand All @@ -215,7 +215,7 @@
"created_at": "2017-04-14T06:11:34.868Z",
"favourited": null,
"favourites_count": 0,
"id": 172421,
"id": "172421",
"in_reply_to_account_id": null,
"in_reply_to_id": null,
"media_attachments": [],
Expand All @@ -241,7 +241,7 @@
"following_count": 38,
"header": "https://mstdn.jp/system/accounts/headers/000/009/790/original/ebb9e786c13025fb.jpg?1492082167",
"header_static": "https://mstdn.jp/system/accounts/headers/000/009/790/original/ebb9e786c13025fb.jpg?1492082167",
"id": 9790,
"id": "9790",
"locked": false,
"note": "(´・ω・`)っ <a href=\"https://mstdn.jp/@prateamsy\" rel=\"nofollow noopener\"><span class=\"invisible\">https://</span><span class=\"\">mstdn.jp/@prateamsy</span><span class=\"invisible\"></span></a>",
"statuses_count": 22,
Expand All @@ -253,7 +253,7 @@
"created_at": "2017-04-14T06:09:37.000Z",
"favourited": null,
"favourites_count": 0,
"id": 172418,
"id": "172418",
"in_reply_to_account_id": null,
"in_reply_to_id": null,
"media_attachments": [],
Expand All @@ -279,7 +279,7 @@
"following_count": 4,
"header": "https://mstdn.jp/headers/original/missing.png",
"header_static": "https://mstdn.jp/headers/original/missing.png",
"id": 19518,
"id": "19518",
"locked": false,
"note": "<a href=\"https://twitter.com/chrolis\" rel=\"nofollow noopener\"><span class=\"invisible\">https://</span><span class=\"\">twitter.com/chrolis</span><span class=\"invisible\"></span></a>",
"statuses_count": 61,
Expand All @@ -291,7 +291,7 @@
"created_at": "2017-04-14T06:11:28.000Z",
"favourited": null,
"favourites_count": 0,
"id": 172417,
"id": "172417",
"in_reply_to_account_id": null,
"in_reply_to_id": null,
"media_attachments": [],
Expand All @@ -317,7 +317,7 @@
"following_count": 6,
"header": "https://mstdn.jp/system/accounts/headers/000/016/783/original/missing.png?1492105023",
"header_static": "https://mstdn.jp/system/accounts/headers/000/016/783/original/missing.png?1492105023",
"id": 16783,
"id": "16783",
"locked": false,
"note": "<a href=\"https://yukkurisinai.net\" rel=\"nofollow noopener\"><span class=\"invisible\">https://</span><span class=\"\">yukkurisinai.net</span><span class=\"invisible\"></span></a>",
"statuses_count": 139,
Expand All @@ -329,7 +329,7 @@
"created_at": "2017-04-14T06:09:28.000Z",
"favourited": null,
"favourites_count": 0,
"id": 172416,
"id": "172416",
"in_reply_to_account_id": null,
"in_reply_to_id": null,
"media_attachments": [],
Expand All @@ -355,7 +355,7 @@
"following_count": 0,
"header": "https://mstdn.jp/headers/original/missing.png",
"header_static": "https://mstdn.jp/headers/original/missing.png",
"id": 40084,
"id": "40084",
"locked": false,
"note": "",
"statuses_count": 1,
Expand All @@ -367,7 +367,7 @@
"created_at": "2017-04-14T06:11:32.197Z",
"favourited": null,
"favourites_count": 0,
"id": 172413,
"id": "172413",
"in_reply_to_account_id": null,
"in_reply_to_id": null,
"media_attachments": [],
Expand All @@ -393,7 +393,7 @@
"following_count": 0,
"header": "https://mstdn.jp/headers/original/missing.png",
"header_static": "https://mstdn.jp/headers/original/missing.png",
"id": 44964,
"id": "44964",
"locked": false,
"note": "",
"statuses_count": 3,
Expand All @@ -405,7 +405,7 @@
"created_at": "2017-04-14T05:58:23.000Z",
"favourited": null,
"favourites_count": 0,
"id": 172411,
"id": "172411",
"in_reply_to_account_id": null,
"in_reply_to_id": null,
"media_attachments": [],
Expand All @@ -431,7 +431,7 @@
"following_count": 0,
"header": "https://mstdn.jp/headers/original/missing.png",
"header_static": "https://mstdn.jp/headers/original/missing.png",
"id": 31042,
"id": "31042",
"locked": false,
"note": "自称 情報系エンジニア。愛知県民。",
"statuses_count": 31,
Expand All @@ -443,7 +443,7 @@
"created_at": "2017-04-14T06:11:29.123Z",
"favourited": null,
"favourites_count": 0,
"id": 172408,
"id": "172408",
"in_reply_to_account_id": null,
"in_reply_to_id": null,
"media_attachments": [],
Expand All @@ -469,7 +469,7 @@
"following_count": 6,
"header": "https://mstdn.jp/system/accounts/headers/000/008/046/original/c5c0c805bfde389d.png?1492083837",
"header_static": "https://mstdn.jp/system/accounts/headers/000/008/046/original/c5c0c805bfde389d.png?1492083837",
"id": 8046,
"id": "8046",
"locked": false,
"note": "MBTI: ENFP765Pro,CAVE,CarSimu,OW.",
"statuses_count": 121,
Expand All @@ -481,7 +481,7 @@
"created_at": "2017-04-14T06:11:28.752Z",
"favourited": null,
"favourites_count": 0,
"id": 172407,
"id": "172407",
"in_reply_to_account_id": null,
"in_reply_to_id": null,
"media_attachments": [],
Expand All @@ -507,7 +507,7 @@
"following_count": 1,
"header": "https://mstdn.jp/headers/original/missing.png",
"header_static": "https://mstdn.jp/headers/original/missing.png",
"id": 41645,
"id": "41645",
"locked": false,
"note": "",
"statuses_count": 4,
Expand All @@ -519,7 +519,7 @@
"created_at": "2017-04-14T06:11:17.000Z",
"favourited": null,
"favourites_count": 0,
"id": 172405,
"id": "172405",
"in_reply_to_account_id": null,
"in_reply_to_id": null,
"media_attachments": [],
Expand All @@ -545,7 +545,7 @@
"following_count": 9,
"header": "https://mstdn.jp/system/accounts/headers/000/038/584/original/7eba8a66d3c0f5d0.jpg?1492139043",
"header_static": "https://mstdn.jp/system/accounts/headers/000/038/584/original/7eba8a66d3c0f5d0.jpg?1492139043",
"id": 38584,
"id": "38584",
"locked": false,
"note": "おしょーすいと読みます。和尚で切っちゃうと全く違うものになちゃうので注意!エロい絵を描いてます。ツイッター <a href=\"https://twitter.com/kousuke200\" rel=\"nofollow noopener\" target=\"_blank\"><span class=\"invisible\">https://</span><span class=\"\">twitter.com/kousuke200</span><span class=\"invisible\"></span></a>",
"statuses_count": 15,
Expand All @@ -557,7 +557,7 @@
"created_at": "2017-04-14T06:11:26.977Z",
"favourited": null,
"favourites_count": 0,
"id": 172404,
"id": "172404",
"in_reply_to_account_id": null,
"in_reply_to_id": null,
"media_attachments": [],
Expand All @@ -583,7 +583,7 @@
"following_count": 15,
"header": "https://mstdn.jp/headers/original/missing.png",
"header_static": "https://mstdn.jp/headers/original/missing.png",
"id": 2990,
"id": "2990",
"locked": false,
"note": "",
"statuses_count": 17,
Expand All @@ -595,7 +595,7 @@
"created_at": "2017-04-14T06:11:26.564Z",
"favourited": null,
"favourites_count": 0,
"id": 172403,
"id": "172403",
"in_reply_to_account_id": null,
"in_reply_to_id": null,
"media_attachments": [],
Expand All @@ -621,7 +621,7 @@
"following_count": 1,
"header": "https://mstdn.jp/headers/original/missing.png",
"header_static": "https://mstdn.jp/headers/original/missing.png",
"id": 42462,
"id": "42462",
"locked": false,
"note": "前髪ぱっつん至上主義な絵描きもどきデス",
"statuses_count": 1,
Expand All @@ -633,7 +633,7 @@
"created_at": "2017-04-14T06:11:26.581Z",
"favourited": null,
"favourites_count": 0,
"id": 172402,
"id": "172402",
"in_reply_to_account_id": null,
"in_reply_to_id": null,
"media_attachments": [],
Expand All @@ -659,7 +659,7 @@
"following_count": 1,
"header": "https://mstdn.jp/headers/original/missing.png",
"header_static": "https://mstdn.jp/headers/original/missing.png",
"id": 21651,
"id": "21651",
"locked": false,
"note": "",
"statuses_count": 3,
Expand All @@ -671,7 +671,7 @@
"created_at": "2017-04-14T06:11:25.776Z",
"favourited": null,
"favourites_count": 0,
"id": 172401,
"id": "172401",
"in_reply_to_account_id": null,
"in_reply_to_id": null,
"media_attachments": [],
Expand All @@ -697,7 +697,7 @@
"following_count": 159,
"header": "https://mstdn.jp/system/accounts/headers/000/017/909/original/30324680b6f9121b.jpg?1492097757",
"header_static": "https://mstdn.jp/system/accounts/headers/000/017/909/original/30324680b6f9121b.jpg?1492097757",
"id": 17909,
"id": "17909",
"locked": false,
"note": "I&apos;m a freelance web developer living in Japan.twitter.com/bellflower2015",
"statuses_count": 144,
Expand All @@ -709,7 +709,7 @@
"created_at": "2017-04-14T06:11:25.468Z",
"favourited": null,
"favourites_count": 0,
"id": 172400,
"id": "172400",
"in_reply_to_account_id": null,
"in_reply_to_id": null,
"media_attachments": [],
Expand All @@ -735,7 +735,7 @@
"following_count": 12,
"header": "https://mstdn.jp/headers/original/missing.png",
"header_static": "https://mstdn.jp/headers/original/missing.png",
"id": 11485,
"id": "11485",
"locked": false,
"note": "",
"statuses_count": 28,
Expand All @@ -747,7 +747,7 @@
"created_at": "2017-04-14T06:11:23.770Z",
"favourited": null,
"favourites_count": 0,
"id": 172398,
"id": "172398",
"in_reply_to_account_id": null,
"in_reply_to_id": null,
"media_attachments": [],
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package social.bigbone.rx.testtool

import com.google.gson.Gson
import io.mockk.every
import io.mockk.mockk
import okhttp3.MediaType.Companion.toMediaTypeOrNull
Expand All @@ -11,6 +10,7 @@ import okhttp3.ResponseBody.Companion.toResponseBody
import social.bigbone.MastodonClient

object MockClient {

fun mock(jsonName: String, maxId: String? = null, sinceId: String? = null): MastodonClient {
val client: MastodonClient = mockk()
val response: Response = Response.Builder()
Expand Down Expand Up @@ -38,9 +38,6 @@ object MockClient {
.build()
every { client.get(ofType<String>(), any()) } returns response

// mocking function that is internal in MastodonClient
every { client["getSerializer"]() } returns Gson()

return client
}
}
Loading

0 comments on commit 1d4c306

Please sign in to comment.