Skip to content

Conversation

tzolov
Copy link
Contributor

@tzolov tzolov commented Sep 14, 2025

Add JsonInclude annotations to notification records to ensure proper JSON serialization by excluding absent (null/Optional.empty()) fields from the serialized output.

Motivation and Context

The ResourcesUpdatedNotification and LoggingMessageNotification records were missing the @JsonInclude(JsonInclude.Include.NON_ABSENT) annotation, which could lead to unnecessary null/absent fields being included in the JSON output. This change ensures consistent serialization behavior across all notification types and prevents potential issues with clients that may not handle absent fields correctly.

How Has This Been Tested?

  • Verified that notification records serialize correctly without including absent fields
  • Tested with both populated and null optional fields to ensure proper exclusion
  • Existing test suite continues to pass

Breaking Changes

No breaking changes. This change only affects the JSON serialization output by excluding absent fields, which should not impact existing functionality. Clients will receive cleaner JSON without unnecessary null fields.

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)
  • Documentation update

Checklist

  • I have read the MCP Documentation
  • My code follows the repository's style guidelines
  • New and existing tests pass locally
  • I have added appropriate error handling
  • I have added or updated documentation as needed

Additional context

This change aligns the notification records with the existing pattern used throughout the codebase where @JsonInclude(JsonInclude.Include.NON_ABSENT) is applied to ensure clean JSON serialization. The annotation specifically handles both null values and Optional.empty() cases, preventing them from appearing in the serialized JSON output.

…rialization

Add @JsonInclude(JsonInclude.Include.NON_ABSENT) to ResourcesUpdatedNotification
  and to LoggingMessageNotification

This ensures that absent (null/Optional.empty()) fields are excluded from JSON
serialization, preventing potential serialization issues with these MCP notification types.

Signed-off-by: Christian Tzolov <[email protected]>
@tzolov tzolov added this to the 0.13.0 milestone Sep 14, 2025
@tzolov tzolov merged commit 7e3ea73 into modelcontextprotocol:main Sep 14, 2025
1 check passed
tzolov added a commit that referenced this pull request Sep 14, 2025
…rialization (#552)

Add @JsonInclude(JsonInclude.Include.NON_ABSENT) to ResourcesUpdatedNotification
  and to LoggingMessageNotification

This ensures that absent (null/Optional.empty()) fields are excluded from JSON
serialization, preventing potential serialization issues with these MCP notification types.

Signed-off-by: Christian Tzolov <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant