Skip to content
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

Consider Switching from Gson to Moshi #96

Open
jaredsburrows opened this issue Nov 4, 2024 · 0 comments
Open

Consider Switching from Gson to Moshi #96

jaredsburrows opened this issue Nov 4, 2024 · 0 comments
Labels

Comments

@jaredsburrows
Copy link

Description:

The project currently uses Gson for JSON serialization and deserialization. Given that the project already incorporates OkHttp from Square, it may be beneficial to consider switching to Moshi (also from Square) for JSON processing.

Reasons to Consider Moshi:

  1. Consistency with OkHttp:

    • Using Moshi, which is also maintained by Square, alongside OkHttp can provide better compatibility and integration between libraries. Both libraries share design principles, resulting in potentially better synergy in terms of updates, bug fixes, and API design.
  2. Better Support for Kotlin:

    • Moshi offers native support for Kotlin through Moshi-Kotlin, allowing smoother integration with Kotlin's null-safety and data classes. This makes it easier to work with Kotlin models without the need for custom type adapters or null-checking, which can reduce boilerplate code and runtime errors.
  3. Improved JSON Adapter Mechanism:

    • Moshi has a well-designed JSON adapter mechanism, which is more flexible and less error-prone compared to Gson’s reflection-based approach. Moshi encourages using custom adapters explicitly, making serialization logic more maintainable and easier to debug.
  4. Reduced Method Count:

    • Moshi generally has a smaller footprint compared to Gson. This is advantageous in environments where method count is a concern, such as Android apps that need to stay under the DEX method limit or aim to optimize build sizes.
  5. Better Performance:

    • Benchmarks have shown that Moshi can be faster than Gson for certain use cases, especially with custom adapters. This can help improve performance, particularly in performance-critical applications.
  6. Actively Maintained with Modern Features:

    • Moshi is actively maintained with a focus on modern JSON handling features, ensuring compatibility with recent language features and performance optimizations. Gson, on the other hand, has a slower update cycle and may lack support for newer JSON standards.

Additional Considerations:

Before migrating to Moshi, it’s essential to evaluate the migration effort required and test the JSON handling thoroughly to ensure feature parity and compatibility with existing models.

@murki murki added the android label Nov 19, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants