Skip to content

[BUG-8620] Make DefaultJsonSerializer resilient to init failures#626

Open
muzahidul-opti wants to merge 2 commits into
masterfrom
muzahidul/bug-8620-serializer-fallback
Open

[BUG-8620] Make DefaultJsonSerializer resilient to init failures#626
muzahidul-opti wants to merge 2 commits into
masterfrom
muzahidul/bug-8620-serializer-fallback

Conversation

@muzahidul-opti
Copy link
Copy Markdown
Contributor

@muzahidul-opti muzahidul-opti commented May 14, 2026

Summary

  • Wraps each serializer instantiation in DefaultJsonSerializer.create() with try-catch so that if one library's initialization fails (e.g., Jackson's PropertyNamingStrategies fields obfuscated by R8), the factory falls through to the next available JSON library instead of crashing with NoClassDefFoundError
  • Catches Throwable (not just Exception) to handle NoClassDefFoundError, ExceptionInInitializerError, and similar linkage errors
  • Adds DefaultJsonSerializerTest with smoke tests for the singleton

Context

PetSmart reports that event dispatch fails with NoClassDefFoundError: DefaultJsonSerializer$LazyHolder when Jackson is on the classpath with its PropertyNamingStrategies.SNAKE_CASE field obfuscated by R8. The current create() method doesn't handle serializer constructor failures, so a Jackson init failure kills the entire serializer factory.

Companion PR: android-sdk ProGuard rules (defense-in-depth)

Test plan

  • All existing serializer tests pass (JacksonSerializerTest, GsonSerializerTest, JsonSerializerTest, JsonSimpleSerializerTest)
  • New DefaultJsonSerializerTest passes (3 tests)
  • Manual verification with test-app using obfuscated Jackson + R8

Issue

🤖 Generated with Claude Code

…ilures

Wrap each serializer instantiation in try-catch so that if one library's
initialization fails (e.g., Jackson's PropertyNamingStrategies fields
obfuscated by R8), the factory falls through to the next available
JSON library instead of crashing with NoClassDefFoundError.

Also add DefaultJsonSerializer unit tests.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant