-
Notifications
You must be signed in to change notification settings - Fork 547
Gson and Parcelize to kotlinx.serialization #453
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
yet300
wants to merge
15
commits into
permissionlesstech:main
Choose a base branch
from
yet300:feature/migrate-kotlinx.serialization
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Gson and Parcelize to kotlinx.serialization #453
yet300
wants to merge
15
commits into
permissionlesstech:main
from
yet300:feature/migrate-kotlinx.serialization
Conversation
This file contains hidden or 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
Replaced `Parcelable` with `kotlinx.serialization.Serializable` across data models to improve serialization performance and maintainability. - Replaced the `kotlin-parcelize` plugin with `kotlin-serialization`. - Added `kotlinx-serialization-json` dependency. - Updated `IdentityAnnouncement`, `BitchatMessage`, `BitchatPacket`, `NoisePayload`, `PrivateMessagePacket`, and `ReadReceipt` to use `@Serializable`. - Introduced a new `Serializers.kt` file with custom serializers for `Date`, `ByteArray`, `UByte`, and `ULong` to ensure compatibility.
Introduces `JsonUtil`, a Kotlin object that serves as a wrapper around the `kotlinx.serialization` library. This utility provides methods for serializing objects to JSON and deserializing JSON strings to objects, including safe versions that return null on error. It is configured to be lenient and ignore unknown keys.
Replaced Gson with `kotlinx.serialization` for JSON handling across the application. This improves performance and ensures better integration with Kotlin. - Updated `NostrEvent`, `NostrFilter`, `BitchatMessage`, `IdentityAnnouncement`, `BitchatPacket`, and `SeenMessageStore` data classes to use `@Serializable`. - Replaced `@SerializedName` with `@SerialName`. - Created custom `ByteArraySerializer`, `UByteSerializer`, and `ULongSerializer` for handling specific types in `BitchatPacket` and `IdentityAnnouncement`. - Introduced a `JsonUtil` helper to centralize serialization logic. - Removed the Gson dependency and related imports. - Refactored `NostrFilter` to move helper functions and the `Builder` class into a companion object.
This commit replaces the Gson library with kotlinx.serialization for all JSON processing related to Nostr messages (requests, responses, and protocol operations). Key changes include: - Removing custom `JsonSerializer` implementations. - Updating `NostrRequest.toJson` to use `buildJsonArray` from kotlinx.serialization. - Modifying `NostrResponse.fromJsonArray` and other parsing logic to use kotlinx.serialization's `JsonElement` API instead of Gson's. - Removing the Gson instance from `NostrRelayManager` and `NostrProtocol`.
Replaced Gson with kotlinx.serialization for `NoisePayload` and `NoiseChannelEncryption`. This change introduces a custom `ByteArraySerializer` to handle the serialization of the `data` field in `NoisePayload` and updates the channel key packet processing to use the new JSON utility.
Replaced all instances of the Gson library with the `kotlinx.serialization` library for JSON handling. - Introduced a new `JsonUtil` helper class for serialization and deserialization. - Updated `GeohashBookmarksStore`, `LocationChannelManager`, `FavoritesPersistenceService`, and `DataManager` to use `JsonUtil`. - Added the `@Serializable` annotation to `FavoriteRelationshipData`. - Ensured safer JSON parsing by handling potential nulls and exceptions during deserialization.
The Gson JSON library is no longer in use and has been removed from the project's dependencies.
Thank you, great addition. I will review this. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Description
This PR migrates the entire Bitchat Android codebase from using Android's Parcelize and Google's Gson to Kotlin's native kotlinx.serialization library. This modernization brings significant benefits in terms of performance, type safety, and future-proofing.
🚀 Why This Migration?
Current Pain Points
Benefits of kotlinx.serialization
🔧 Technical Changes
Dependencies Updated
Custom Serializers Created
DateSerializer
: Handlesjava.util.Date
using milliseconds since epochByteArraySerializer
: HandlesByteArray
using Base64 encodingUByteSerializer
&ULongSerializer
: Handle unsigned integer typesJsonUtil
: Centralized JSON operations replacing Gson usageFiles Migrated
Model Classes (Parcelize → @serializable)
BitchatMessage
+DeliveryStatus
enumIdentityAnnouncement
NoisePayload
,PrivateMessagePacket
,ReadReceipt
BitchatPacket
with binary protocol supportNostr Protocol Classes (Gson → kotlinx.serialization)
NostrEvent
with@SerialName
field mappingNostrRequest
with custom JSON array serializationNostrFilter
with tag filter supportNostrResponse
with updated parsing logicService Classes
SeenMessageStore
: Message deduplication storageGeohashBookmarksStore
: Location channel bookmarksLocationChannelManager
: Channel data persistenceFavoritesPersistenceService
: Complex nested data structuresDataManager
: Application preferencesNoiseChannelEncryption
: Encrypted channel packets📱 Impact Assessment
Positive Impacts
Risk Mitigation
🔍 Code Quality Improvements
Map<String, Any>
usage with proper data classesChecklist
@Parcelize
classes to@Serializable