Closed RenanCarlosPereira closed 4 days ago
hey @abbasc52 I might found the issue.
check out the PR, that's probably why you didn't migrate fully to System.Text.Json. I found a way to sort it out if you could take a look at this implementation:
@asulwer please could you check it carefully too.
the explanation is in the PR description thanks, guys
when i attempted the change a week or so ago, i ran into something. i cannot remember what that was exactly, something to do with the object array. vague. maybe same thing or related?
yes that is exactly what i experienced. this only effects object array parameters? if a RuleParameter is used this is not applicable?
when i attempted the change a week or so ago, i ran into something. i cannot remember what that was exactly, something to do with the object array. vague. maybe same thing or related?
not sure, but it could be related, I covered the arrays in the unit test
let me know if you want this merged. looks good on my end
That doesn't affect only arrays That affects all parameters that are of type JsonElement.
We can merge it, but let's wait some time I want to get some insight from @abbasc52
Reason for Change: The primary reason for this change is the difference in how
System.Text.Json
handlesExpandoObject
compared toNewtonsoft.Json
. When usingSystem.Text.Json
, properties within anExpandoObject
are deserialized asJsonElement
rather than their respective .NET types (e.g., string, int). This behavior can lead to issues where the compiler cannot work with the dynamically deserialized properties directly.Examples:
Newtonsoft.Json Example: When you deserialize JSON to a dynamic object with Newtonsoft.Json, it converts the JSON properties to their corresponding .NET types directly:
System.Text.Json Example: In contrast, System.Text.Json does not convert properties to their .NET types but keeps them as
JsonElement
:This difference means you can't directly access or manipulate the values without additional conversion steps. As a result, handling
JsonElement
requires converting them into more manageable types, such asExpandoObject
.Changes Made:
In
CreateAbstractClassType
Method:JsonElement
toExpandoObject
:In
CreateObject
Method:JsonElement
within expando properties:Tests Added:
CreateAbstractClassType_WithJsonElement_ShouldConvertToExpandoObject
JsonElement
input is correctly converted and that the dynamic type has the expected properties.CreateObject_WithJsonElement_ShouldConvertToExpandoObject
CreateObject
correctly handlesJsonElement
and converts it to anExpandoObject
.CreateObject_WithJsonElementNested_ShouldConvertToExpandoObject
CreateObject_WithJsonElementArray_ShouldConvertToExpandoObject
This pull request resolves issues caused by the serialization behavior of
System.Text.Json
, allowing the dynamic type creation and object creation methods to work seamlessly with JSON data serialized bySystem.Text.Json
.References: