Skip to content

Fix serializers#995

Merged
wieslawsoltes merged 6 commits intomasterfrom
fix/issue-924-serializers
Jan 22, 2026
Merged

Fix serializers#995
wieslawsoltes merged 6 commits intomasterfrom
fix/issue-924-serializers

Conversation

@wieslawsoltes
Copy link
Owner

@wieslawsoltes wieslawsoltes commented Jan 21, 2026

PR Summary - Issue 924 Serialization Fixes

Findings

  • XML serialization failed with a DataContractSerializer error when derived model types were marked with DataContract but their base types were not.
  • Serializer coverage did not include full round-trip tests across all supported formats.
  • System.Text.Json and YAML attempted to serialize interface-typed properties that should be ignored (for example ICommand or IgnoreDataMember), causing deserialization failures.
  • YAML could not hydrate interface-typed collections because type tags were missing.
  • Protobuf lacked a stable model for interface-heavy graphs and had no explicit member registration for DataMember-only models, leading to missing or defaulted data.

Implementation

  • DataContract alignment
    • Removed DataContract attributes from derived model implementations that inherit non-DataContract bases.
    • Added DataContract(IsReference = true) to base ReactiveBase types so derived models remain DataContract-compatible.
    • Relaxed DockWindow DataMember requirements on geometry fields so IsReference works without required members.
  • XML serializer
    • Built known types via reflection, filtered to public, non-abstract dock types, and validated DataContract compatibility.
    • Kept the existing list conversion behavior after deserialization.
  • System.Text.Json
    • Added a polymorphic resolver that registers dock interfaces and emits $type discriminators.
    • Filtered interface properties by name when their concrete implementations are marked IgnoreDataMember or use ICommand.
    • Enabled NumberHandling for named floating point literals.
  • YAML
    • Added dynamic type resolution and tag mappings for all dock model types so interface collections can deserialize.
    • Filtered IgnoreDataMember and ICommand properties via a custom type inspector.
    • Ensured round-trip settings remain enabled.
  • Protobuf
    • Built a per-serializer RuntimeTypeModel that registers dock interfaces and classes.
    • Explicitly registered DataMember properties (including inherited ones) in deterministic order.
    • Modeled interface hierarchies with stable subtype tags to support interface-typed properties and collections.
  • Tests
    • Added a layout round-trip test that exercises Newtonsoft, System.Text.Json, YAML, XML, and Protobuf serializers.

Usage Guide

  • All serializers continue to implement IDockSerializer and can be used interchangeably. Example:
using Dock.Model.Core;
using Dock.Serializer.SystemTextJson;

IDockSerializer serializer = new DockSerializer();
using var stream = File.Create("layout.json");
serializer.Save(stream, rootDock);

stream.Position = 0;
var loaded = serializer.Load<RootDock>(stream);
  • System.Text.Json and YAML now embed concrete type information:
    • JSON uses a $type discriminator with the full type name.
    • YAML uses tags in the form !Namespace.TypeName.
  • XML, YAML, and Protobuf discover concrete types at runtime. Ensure the model assemblies you need are loaded (for example by referencing the model library or touching a type) before deserializing layouts.
  • For custom list types, continue to pass the list type into the serializer constructor, for example new DockYamlSerializer(typeof(List<>)).

Fixes #924

@wieslawsoltes wieslawsoltes merged commit f1e802d into master Jan 22, 2026
8 checks passed
@wieslawsoltes wieslawsoltes deleted the fix/issue-924-serializers branch January 22, 2026 06:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Exception when the method DockXmlSerializer.Save is called

1 participant