Skip to content

feat(android): add block inserter payload model#465

Open
jkmassel wants to merge 1 commit intotrunkfrom
jkmassel/kotlin-block-inserter-model
Open

feat(android): add block inserter payload model#465
jkmassel wants to merge 1 commit intotrunkfrom
jkmassel/kotlin-block-inserter-model

Conversation

@jkmassel
Copy link
Copy Markdown
Contributor

Summary

Groundwork for the native block inserter feature on Android: @Serializable Kotlin data classes mirroring the JSON shape produced by BlockInserterBridge in src/components/native-inserter/index.jsx. Parser tests cover full payload, minimal payload, fallback category, explicit nulls on nullable strings, null arrays on pattern fields, and malformed input.

Extracted from #463 so each PR stays narrow. The original #463 mixed this model with a separate JS bridge fix, and feedback on the stack prompted a split.

Scope

  • BlockInserter.ktBlockInserterPayload, BlockInserterSection, BlockType, BlockPattern, BlockPatternCategory, SourceRect.
  • BlockInserterTest.kt — five parser tests.

Not referenced from production code yet; the Android @JavascriptInterface receiver lands in a later PR in the stack.

A note on strictness

The three List<String> fields on BlockPatternblockTypes, categories, keywords — are non-nullable with = emptyList() defaults. kotlinx-serialization's default behavior applies the default when the JSON key is missing, but throws SerializationException when the key is present and explicitly null. The current JSX emits ?? null for these fields; that matching JS fix (?? []) lands in a follow-up PR on the stack.

The rejects null arrays on pattern fields test pins this contract so the parser can't be silently relaxed later without a conscious decision. If the tradeoff ever needs to flip (e.g. to coerceInputValues = true), that test fails and the decision happens in review.

Test plan

  • ./gradlew :Gutenberg:testDebugUnitTest detekt :Gutenberg:lintDebug — passes locally

Related

Adds `@Serializable` Kotlin data classes mirroring the shape produced
by `BlockInserterBridge` in `src/components/native-inserter/index.jsx`,
with parser tests covering full/minimal payloads, fallback category,
explicit nulls on nullable string fields, null arrays on pattern
fields, and malformed input.

The model is strict: non-nullable `List<String>` fields reject JSON
`null`. The JS producer is responsible for emitting `[]` instead of
`null` for `pattern.blockTypes`, `pattern.categories`, and
`pattern.keywords` — enforced by the `rejects null arrays on pattern
fields` test and landing alongside the matching JS fix in a follow-up
PR.

Not referenced from production code yet; the Android
`@JavascriptInterface` receiving method lands in a later PR.
@github-actions github-actions Bot added the [Type] Enhancement A suggestion for improvement. label Apr 23, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

[Type] Enhancement A suggestion for improvement.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant