Repository navigation
Omit empty fields when serializing SlackFileObject - #478
Merged
Merged
Conversation
NON_NULL doesn't treat an empty Optional as absent, so an id-only slack_file
was sent as {"url": null, "id": "F..."}. Slack rejects that with
invalid_blocks, which broke image blocks and card hero images that reference
an uploaded file by ID. NON_ABSENT drops the empty field.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Comment on lines
+24
to
+25
| assertThat(node.has("url")).isFalse(); | ||
| assertThat(node.get("id").asText()).isEqualTo(FILE_ID); |
Contributor
There was a problem hiding this comment.
Can we extract these and other magic strings into constants, since they are repeated in a few places?
Contributor
Author
There was a problem hiding this comment.
Done in 7ea51e2. Field names (id, url, image_url, slack_file, hero_image), the file ID/URL, alt text and card title are now constants, and the repeated SlackFileObject builder is pulled into an idOnlySlackFile() helper.
…stants Addresses review feedback: field names, the file id and fixture text were repeated across tests, so they now live in named constants alongside an idOnlySlackFile() helper. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Viktor-Pelepiak
approved these changes
Oct 5, 2026
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.
Why
SlackFileObjectis annotated@JsonInclude(NON_NULL), butNON_NULLdoesn't treat an emptyOptionalas absent. Aslack_filethat references an uploaded file by ID is therefore serialized as:Slack rejects the whole message with
invalid_blocks. This breaks both places a file can be referenced by ID: the top-levelimageblock and an image element such as a card'shero_image(added in #473). We hit it in slack-integration when a Breeze reply carried a card whose hero image referenced an uploaded screenshot.What
Switch to
@JsonInclude(NON_ABSENT), the setting the rest of slack-base uses forOptionalfields, so only the field that's set is written:Tests
New
SlackFileObjectSerializationTestasserts on the serialized JSON:SlackFileObjects omit the other fieldimageblock and a cardhero_imagereferencing a file by ID serializeslack_filewith onlyid, and noimage_urlWith the old
NON_NULL, 4 of the 5 new tests fail. With the fix, the fullslack-basesuite passes (300 tests). I also installed this build locally and confirmed slack-integration's artifact card now serializesslack_fileas{"id": ...}.