Skip to content

Conversation

@joaodordio
Copy link
Member

@joaodordio joaodordio commented Jan 27, 2026

🔹 Jira Ticket(s) if any

✏️ Description

HTML-only in-app messages without a customPayload field were causing crashes due to @NonNull annotation enforcement. This affected customers using the HTML-only template option (vs. the "Everything" format).

Changes

  • Changed customPayload from @NonNull to @Nullable in:
    • Field declaration
    • Constructor parameter
    • getCustomPayload() return type
  • Added test testHtmlMessageWithoutCustomPayload to cover this scenario

⚠️ Impact

🚨 Breaking change for Kotlin consumers 🚨 — callers of getCustomPayload() must now handle nullability. Java consumers are unaffected at compile time but should add null checks.

@franco-zalamena-iterable

Hey i realized maybe we can have some other Unit tests to further verify the behaviour

Empty CustomPayload Object

What to test:

A message with "customPayload": {} (present but empty)

Expected behavior:

getCustomPayload() returns an empty JSONObject, not null


Serialization Round-Trip with Null CustomPayload

What to test:
  1. Deserialize a message without customPayload field (results in null)
  2. Serialize it back to JSON via toJSONObject()
  3. Deserialize the JSON again
  4. Verify customPayload is still null
Expected behavior:

The toJSONObject() method uses putOpt() which has specific null-handling behavior. We need to ensure null values are preserved correctly through serialization cycles, not accidentally converted to empty objects or causing the field to appear in JSON when it shouldn't.


CustomPayload Over Legacy Payload

Lines 355-357 show fallback logic:

if (customPayload == null) {
    customPayload = contentJson.optJSONObject(ITERABLE_IN_APP_LEGACY_PAYLOAD);
}

We need to verify that only a truly missing field triggers the legacy fallback, not an explicitly null or empty value


jsonOnly Mode with Null CustomPayload

What to test:

A message with "jsonOnly": true but NO customPayload field

Expected behavior:

Lines 343-345 have special handling:

if (customPayload == null && jsonOnly) {
    customPayload = new JSONObject();
}

This means:

  • jsonOnly message without customPayload → getCustomPayload() returns {}, not null
  • Regular message without customPayload → getCustomPayload() returns null

This edge case should be explicitly tested to document this intentional difference in behavior between jsonOnly and regular messages.

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.

3 participants