Skip to content

fix: Property serialization with null value and interface type#52

Merged
IvanMurzak merged 7 commits into
mainfrom
fix/interface-null-serialization
Jan 9, 2026
Merged

fix: Property serialization with null value and interface type#52
IvanMurzak merged 7 commits into
mainfrom
fix/interface-null-serialization

Conversation

@IvanMurzak

@IvanMurzak IvanMurzak commented Jan 9, 2026

Copy link
Copy Markdown
Owner

This pull request adds comprehensive tests to cover serialization, deserialization, and population scenarios involving interface and abstract types, and improves logging and deserialization logic in the reflection-based converters. The changes ensure that null values for interface and abstract types are handled gracefully and that the system behaves correctly when encountering non-instantiable types. Additionally, the logging in array deserialization is now conditional on log level, and deserialization of fields now correctly uses the field's declared type as a fallback.

Test coverage for interface and abstract types:

  • Added InterfaceDeserializationTests to verify correct behavior when deserializing interface and abstract class types, ensuring exceptions are thrown for non-null data and null is returned for null data. Also includes control tests for concrete types.
  • Added InterfaceOnlyMethodsSerializationTests to ensure serialization works correctly for interface-typed members with no serializable fields/properties, including both null and concrete values.
  • Added InterfacePopulationTests to test population of interface-typed fields, verifying that population fails for interface-typed data and succeeds for concrete types.

Reflection converter improvements:

  • In BaseReflectionConverter.Deserialize, changed field deserialization to use the field's declared type as a fallback, improving type safety and correctness when deserializing fields.
  • In ArrayReflectionConverter.Deserialize, updated logging to only log information and warnings if the logger's level is enabled, preventing unnecessary log output.

These changes significantly increase test coverage for edge cases involving interfaces and abstract classes, and improve the robustness and clarity of reflection-based serialization/deserialization.

@github-actions

github-actions Bot commented Jan 9, 2026

Copy link
Copy Markdown
Contributor

Test Results

    2 files  ± 0      2 suites  ±0   3m 26s ⏱️ -11s
1 082 tests +15  1 082 ✅ +15  0 💤 ±0  0 ❌ ±0 
2 164 runs  +30  2 164 ✅ +30  0 💤 ±0  0 ❌ ±0 

Results for commit 4d832cc. ± Comparison against base commit f5ab41d.

♻️ This comment has been updated with latest results.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This pull request enhances the serialization/deserialization system to properly handle interface and abstract types, particularly when values are null. The changes improve type safety in field/property deserialization by using declared types as fallbacks, add comprehensive test coverage for edge cases involving non-instantiable types, and optimize logging by making log calls conditional on log level.

  • Adds early handling for null interface/abstract types in serialization and deserialization
  • Improves field/property deserialization to use declared types as fallback (better type resolution)
  • Adds conditional log level checks before logging to improve performance

Reviewed changes

Copilot reviewed 8 out of 8 changed files in this pull request and generated 5 comments.

Show a summary per file
File Description
ReflectorNet/src/Reflector/Reflector.cs Adds null handling for interface/abstract types in Serialize and Deserialize methods; adds conditional logging checks
ReflectorNet/src/Extension/ExtensionsJson.cs Updates logging format to include padding and improves consistency with type formatting
ReflectorNet/src/Converter/Reflection/Base/BaseReflectionConverter.Serialize.cs Adds conditional logging check before logging warnings
ReflectorNet/src/Converter/Reflection/Base/BaseReflectionConverter.Deserialize.cs Moves field/property info retrieval before deserialization to use declared types as fallback; adds conditional logging
ReflectorNet/src/Converter/Reflection/ArrayReflectionConverter.Deserialize.cs Adds conditional logging checks for information and warning levels
ReflectorNet.Tests/src/ReflectorTests/InterfacePopulationTests.cs New test file covering population scenarios with interface-typed fields
ReflectorNet.Tests/src/ReflectorTests/InterfaceOnlyMethodsSerializationTests.cs New test file for serializing classes with interface-typed members that have no serializable properties
ReflectorNet.Tests/src/ReflectorTests/InterfaceDeserializationTests.cs New test file covering deserialization of interface and abstract types with null/non-null data

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread ReflectorNet/src/Reflector/Reflector.cs Outdated
Comment thread ReflectorNet/src/Reflector/Reflector.cs Outdated
Comment thread ReflectorNet/src/Reflector/Reflector.cs Outdated
Comment thread ReflectorNet/src/Reflector/Reflector.cs Outdated
Comment thread ReflectorNet/src/Reflector/Reflector.cs Outdated
@IvanMurzak IvanMurzak merged commit 21ba58e into main Jan 9, 2026
2 checks passed
@IvanMurzak IvanMurzak deleted the fix/interface-null-serialization branch January 9, 2026 10:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants