Jackson object mapping is slow on the initial run as all the classes need to be loaded and their annotations reflectively checked.
Moshi use code generation to create "adapters" to do the same work at build time, which speeds things up considerably. Some custom adapters are also written (in fact: generated first by Moshi and then changed a bit by me) to accommodate the schema used by the backend.
Initially, I wanted to convert everything from Jackson to Moshi, but this was problematic, as there are corner cases and the class hierarchy does not suit Moshi very well. So I went for a more TDD approach and focused on the calls underlying Recent and Continue tabs only. The rest can be done piece by piece, and even if not, then this change makes the Android Auto load fast enough.
How have you tested this?
On my phone with the desktop head unit, moreover unit and instrumented test are added using json responses from my server, to make sure the data is the same when deserialized with Jackson and with Moshi.
🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.
## 📋 Pull Request Information
**Original PR:** https://github.com/advplyr/audiobookshelf-app/pull/1591
**Author:** [@golinski](https://github.com/golinski)
**Created:** 5/31/2025
**Status:** 🔄 Open
**Base:** `master` ← **Head:** `moshi`
---
### 📝 Commits (4)
- [`3d17bd8`](https://github.com/advplyr/audiobookshelf-app/commit/3d17bd8ae364cded975f812f632fd98cb811b46a) Add libraries and tests to compare Moshi against Jackson
- [`c041f84`](https://github.com/advplyr/audiobookshelf-app/commit/c041f84c895f7d693791511d2bccd4456e25e225) Create the Moshi adapters
- [`77dcf98`](https://github.com/advplyr/audiobookshelf-app/commit/77dcf9887dba54317b931a9efedb028f1da46cea) Use the Moshi deserializers in the most problematic places of the app
- [`ec4bf1e`](https://github.com/advplyr/audiobookshelf-app/commit/ec4bf1ec91cd9dc05eb40e0d436157e323edf264) Make sure serialization with Moshi works as well
### 📊 Changes
**29 files changed** (+10525 additions, -74 deletions)
<details>
<summary>View changed files</summary>
📝 `android/app/build.gradle` (+17 -0)
➖ `android/app/src/androidTest/java/com/getcapacitor/myapp/ExampleInstrumentedTest.java` (+0 -26)
➕ `android/app/src/androidTest/kotlin/com/audiobookshelf/app/SerializationInstrumentedTest.kt` (+92 -0)
➕ `android/app/src/androidTest/resources/items-in-progress.json` (+882 -0)
➕ `android/app/src/androidTest/resources/personalized.json` (+2540 -0)
➕ `android/app/src/androidTest/resources/personalized2.json` (+1348 -0)
📝 `android/app/src/main/java/com/audiobookshelf/app/data/AudioTrack.kt` (+2 -0)
📝 `android/app/src/main/java/com/audiobookshelf/app/data/CollapsedSeries.kt` (+2 -0)
📝 `android/app/src/main/java/com/audiobookshelf/app/data/DataClasses.kt` (+30 -1)
📝 `android/app/src/main/java/com/audiobookshelf/app/data/EBookFile.kt` (+2 -0)
📝 `android/app/src/main/java/com/audiobookshelf/app/data/ItemInProgress.kt` (+5 -12)
📝 `android/app/src/main/java/com/audiobookshelf/app/data/LibraryAuthorItem.kt` (+2 -0)
📝 `android/app/src/main/java/com/audiobookshelf/app/data/LibraryItem.kt` (+2 -0)
📝 `android/app/src/main/java/com/audiobookshelf/app/data/LibrarySeriesItem.kt` (+2 -0)
📝 `android/app/src/main/java/com/audiobookshelf/app/data/MediaProgress.kt` (+2 -0)
➕ `android/app/src/main/java/com/audiobookshelf/app/data/MoshiProvider.kt` (+20 -0)
➕ `android/app/src/main/java/com/audiobookshelf/app/data/adapters/BookJsonAdapter.kt` (+139 -0)
➕ `android/app/src/main/java/com/audiobookshelf/app/data/adapters/CustomAdapterFactory.kt` (+22 -0)
➕ `android/app/src/main/java/com/audiobookshelf/app/data/adapters/CustomPolymorhicJsonAdapterFactory.kt` (+193 -0)
➕ `android/app/src/main/java/com/audiobookshelf/app/data/adapters/LibraryItemJsonAdapter.kt` (+245 -0)
_...and 9 more files_
</details>
### 📄 Description
## Brief summary
This PR uses Moshi serialization library to speed up items loading on Android Auto initialization.
## Which issue is fixed?
Fixes #1570
## Pull Request Type
Android only
## In-depth Description
Jackson object mapping is slow on the initial run as all the classes need to be loaded and their annotations reflectively checked.
Moshi use code generation to create "adapters" to do the same work at build time, which speeds things up considerably. Some custom adapters are also written (in fact: generated first by Moshi and then changed a bit by me) to accommodate the schema used by the backend.
Initially, I wanted to convert everything from Jackson to Moshi, but this was problematic, as there are corner cases and the class hierarchy does not suit Moshi very well. So I went for a more TDD approach and focused on the calls underlying Recent and Continue tabs only. The rest can be done piece by piece, and even if not, then this change makes the Android Auto load fast enough.
## How have you tested this?
On my phone with the desktop head unit, moreover unit and instrumented test are added using json responses from my server, to make sure the data is the same when deserialized with Jackson and with Moshi.
---
<sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
Blocking a user prevents them from interacting with repositories, such as opening or commenting on pull requests or issues. Learn more about blocking a user.
📋 Pull Request Information
Original PR: https://github.com/advplyr/audiobookshelf-app/pull/1591
Author: @golinski
Created: 5/31/2025
Status: 🔄 Open
Base:
master← Head:moshi📝 Commits (4)
3d17bd8Add libraries and tests to compare Moshi against Jacksonc041f84Create the Moshi adapters77dcf98Use the Moshi deserializers in the most problematic places of the appec4bf1eMake sure serialization with Moshi works as well📊 Changes
29 files changed (+10525 additions, -74 deletions)
View changed files
📝
android/app/build.gradle(+17 -0)➖
android/app/src/androidTest/java/com/getcapacitor/myapp/ExampleInstrumentedTest.java(+0 -26)➕
android/app/src/androidTest/kotlin/com/audiobookshelf/app/SerializationInstrumentedTest.kt(+92 -0)➕
android/app/src/androidTest/resources/items-in-progress.json(+882 -0)➕
android/app/src/androidTest/resources/personalized.json(+2540 -0)➕
android/app/src/androidTest/resources/personalized2.json(+1348 -0)📝
android/app/src/main/java/com/audiobookshelf/app/data/AudioTrack.kt(+2 -0)📝
android/app/src/main/java/com/audiobookshelf/app/data/CollapsedSeries.kt(+2 -0)📝
android/app/src/main/java/com/audiobookshelf/app/data/DataClasses.kt(+30 -1)📝
android/app/src/main/java/com/audiobookshelf/app/data/EBookFile.kt(+2 -0)📝
android/app/src/main/java/com/audiobookshelf/app/data/ItemInProgress.kt(+5 -12)📝
android/app/src/main/java/com/audiobookshelf/app/data/LibraryAuthorItem.kt(+2 -0)📝
android/app/src/main/java/com/audiobookshelf/app/data/LibraryItem.kt(+2 -0)📝
android/app/src/main/java/com/audiobookshelf/app/data/LibrarySeriesItem.kt(+2 -0)📝
android/app/src/main/java/com/audiobookshelf/app/data/MediaProgress.kt(+2 -0)➕
android/app/src/main/java/com/audiobookshelf/app/data/MoshiProvider.kt(+20 -0)➕
android/app/src/main/java/com/audiobookshelf/app/data/adapters/BookJsonAdapter.kt(+139 -0)➕
android/app/src/main/java/com/audiobookshelf/app/data/adapters/CustomAdapterFactory.kt(+22 -0)➕
android/app/src/main/java/com/audiobookshelf/app/data/adapters/CustomPolymorhicJsonAdapterFactory.kt(+193 -0)➕
android/app/src/main/java/com/audiobookshelf/app/data/adapters/LibraryItemJsonAdapter.kt(+245 -0)...and 9 more files
📄 Description
Brief summary
This PR uses Moshi serialization library to speed up items loading on Android Auto initialization.
Which issue is fixed?
Fixes #1570
Pull Request Type
Android only
In-depth Description
Jackson object mapping is slow on the initial run as all the classes need to be loaded and their annotations reflectively checked.
Moshi use code generation to create "adapters" to do the same work at build time, which speeds things up considerably. Some custom adapters are also written (in fact: generated first by Moshi and then changed a bit by me) to accommodate the schema used by the backend.
Initially, I wanted to convert everything from Jackson to Moshi, but this was problematic, as there are corner cases and the class hierarchy does not suit Moshi very well. So I went for a more TDD approach and focused on the calls underlying Recent and Continue tabs only. The rest can be done piece by piece, and even if not, then this change makes the Android Auto load fast enough.
How have you tested this?
On my phone with the desktop head unit, moreover unit and instrumented test are added using json responses from my server, to make sure the data is the same when deserialized with Jackson and with Moshi.
🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.