fix: Property serialization with null value and interface type#52
Merged
Conversation
Contributor
Contributor
There was a problem hiding this comment.
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.
…terface and abstract type deserialization errors
…n and deserialization processes
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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:
InterfaceDeserializationTeststo 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.InterfaceOnlyMethodsSerializationTeststo ensure serialization works correctly for interface-typed members with no serializable fields/properties, including both null and concrete values.InterfacePopulationTeststo test population of interface-typed fields, verifying that population fails for interface-typed data and succeeds for concrete types.Reflection converter improvements:
BaseReflectionConverter.Deserialize, changed field deserialization to use the field's declared type as a fallback, improving type safety and correctness when deserializing fields.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.