Skip to content

Omit missing metadata fields from JSON serialization#48

Open
jbearer wants to merge 1 commit intomainfrom
jb/opt-metadata-fields
Open

Omit missing metadata fields from JSON serialization#48
jbearer wants to merge 1 commit intomainfrom
jb/opt-metadata-fields

Conversation

@jbearer
Copy link
Member

@jbearer jbearer commented Dec 9, 2025

Assuming that most nodes will omit at least some of the optional metadata fields (e.g. long description, different icon resolutions), I wanted to keep the FullNodeSetSnapshot serialization concise and readable by omitting all of those fields instead of serializing an explicit null for every omitted field.

This turned out to be more complex than I had hoped for. You can do it with a simple #[serde(default, skip_serializing_if = "Option::is_none")]. However, this feature is not supported at all in bincode, so using this attribute makes JSON work nicely and bincode fail to deserialize any object with omitted fields. This requires writing a custom serializer with different behavior based on the value of is_human_readable, which I tried to do using a macro to avoid duplicate logic for every single field.

In the end I'm on the fence about whether this optimization is worth the added complexity but here it is if we think it's worth merging.

@jbearer jbearer requested review from Ayiga and imabdulbasit December 9, 2025 18:01
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.

1 participant