Skip to content

Fix attribute deserialization#21

Merged
agocke merged 2 commits intoserdedotnet:mainfrom
agocke:fix-attr-de
Jan 16, 2026
Merged

Fix attribute deserialization#21
agocke merged 2 commits intoserdedotnet:mainfrom
agocke:fix-attr-de

Conversation

@agocke
Copy link
Contributor

@agocke agocke commented Jan 16, 2026

This pull request refactors the XML deserialization logic to improve correctness and robustness, especially around handling attributes, self-closing elements, and end-element consumption. The changes also add test coverage for a common XML pattern involving lists of elements with only attributes.

Deserializer logic improvements

  • Refactored DeserializeType to use an explicit state machine for attribute and element reading, improving clarity and correctness when handling attributes and self-closing elements. The attribute lookup now supports both standard property info and XML attribute/element annotations.
  • Changed deserializer methods so that inner deserializers are responsible for fully consuming their own end elements, ensuring the XML reader's cursor is correctly positioned after each deserialization. This affects both type and collection deserialization.

Attribute and element handling

  • Improved attribute matching logic to support both XML attribute and element annotations, enabling correct mapping of XML attributes to object fields even when using custom naming.
  • Fixed enum deserialization to correctly consume start and end elements, ensuring the reader is properly advanced and attributes are fully consumed.

Test coverage

  • Added a new test for deserializing lists of elements that only have attributes (no child elements), verifying support for self-closing elements and attribute-only list patterns.

1. Provides proper support for attributes.
2. Provides support for empty elements.
3. Adds support for using Xml attributes in deserialization
@agocke agocke changed the title Fix attr de Fix attribute deserialization Jan 16, 2026
@agocke agocke merged commit 6b111b2 into serdedotnet:main Jan 16, 2026
1 check passed
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