refactor: simplify null handling in serialization methods across converters#62
Merged
Merged
Conversation
Contributor
Contributor
There was a problem hiding this comment.
Pull request overview
This pull request refactors serialization logic in reflection-based converters by introducing dedicated helper methods for field and property serialization, standardizing logging indentation, and simplifying null value handling.
Changes:
- Introduced
SerializeFieldandSerializePropertyhelper methods to encapsulate field/property serialization logic - Replaced
SerializedMember.FromJson(..., json: null, ...)with the cleanerSerializedMember.Null()method - Moved depth increment logic from inside serialization methods to the call site in
GenericReflectionConverter
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| PrimitiveReflectionConverter.cs | Updated null handling to use SerializedMember.Null() for cleaner null serialization |
| GenericReflectionConverter.cs | Updated null handling and moved depth increment to call site when invoking SerializeFields and SerializeProperties |
| BaseReflectionConverter.Serialize.cs | Added helper methods SerializeField and SerializeProperty, updated logging to use correct depth, and refactored field/property serialization to use the new helpers |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
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 refactors and improves the serialization logic in the reflection-based converters. The main changes include introducing dedicated methods for field and property serialization, standardizing logging indentation, and updating how null values are handled. These updates enhance code clarity, maintainability, and consistency in serialization depth handling.
Refactoring serialization logic:
SerializeFieldandSerializePropertyhelper methods toBaseReflectionConverter.Serialize.csfor handling field and property serialization, replacing inline calls toreflector.Serializein the main serialization loop.Logging improvements:
depthinstead ofdepth + 1toStringUtils.GetPaddingin trace and warning log statements for both fields and properties. [1] [2] [3] [4]Null value handling:
SerializedMember.Nullinstead ofSerializedMember.FromJson(..., json: null, ...)in bothGenericReflectionConverterandPrimitiveReflectionConverter. [1] [2]Depth handling in generic converter:
GenericReflectionConverterto increment depth by 1, ensuring proper nesting in serialization.