feat(android): add block inserter payload model#465
Open
Conversation
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.
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
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.
Summary
Groundwork for the native block inserter feature on Android:
@SerializableKotlin data classes mirroring the JSON shape produced byBlockInserterBridgeinsrc/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.kt—BlockInserterPayload,BlockInserterSection,BlockType,BlockPattern,BlockPatternCategory,SourceRect.BlockInserterTest.kt— five parser tests.Not referenced from production code yet; the Android
@JavascriptInterfacereceiver lands in a later PR in the stack.A note on strictness
The three
List<String>fields onBlockPattern—blockTypes,categories,keywords— are non-nullable with= emptyList()defaults. kotlinx-serialization's default behavior applies the default when the JSON key is missing, but throwsSerializationExceptionwhen the key is present and explicitlynull. The current JSX emits?? nullfor these fields; that matching JS fix (?? []) lands in a follow-up PR on the stack.The
rejects null arrays on pattern fieldstest 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. tocoerceInputValues = true), that test fails and the decision happens in review.Test plan
./gradlew :Gutenberg:testDebugUnitTest detekt :Gutenberg:lintDebug— passes locallyRelated