@@ -24,10 +24,9 @@ public override object ReadJson(
24
24
object existingValue ,
25
25
JsonSerializer serializer
26
26
) {
27
- // Load JSON into memory for processing
28
27
JObject jsonObject = JObject . Load ( reader ) ;
29
28
30
- // Create serializer settings that exclude IAnchorObjectInterface to prevent infinite recursion
29
+ // Create serializer settings that exclude IAnchorObjectInterface to prevent infinite recursion.
31
30
var jsonSettings = new JsonSerializerSettings {
32
31
ContractResolver = new BunqContractResolver ( new List < Type > { typeof ( IAnchorObjectInterface ) } ) ,
33
32
DateFormatString = FORMAT_DATE ,
@@ -36,10 +35,10 @@ JsonSerializer serializer
36
35
NullValueHandling = NullValueHandling . Ignore ,
37
36
} ;
38
37
39
- // Create empty instance of the target type
38
+ // Create empty instance of the target type.
40
39
var instance = ( IAnchorObjectInterface ) Activator . CreateInstance ( objectType ) ;
41
40
42
- // Strategy 1: Try mapping "object" container properties to target object properties
41
+ // Try mapping "object" container properties to target object properties.
43
42
if ( jsonObject . TryGetValue ( OBJECT_KEY , out JToken objectToken ) && objectToken is JObject objectContent ) {
44
43
var properties = objectType . GetProperties ( ) ;
45
44
@@ -62,24 +61,24 @@ JsonSerializer serializer
62
61
}
63
62
}
64
63
65
- // Return if we successfully populated at least one field
64
+ // Return if we successfully populated the model.
66
65
if ( ! ( ( BunqModel ) instance ) . IsAllFieldNull ( ) ) {
67
66
return instance ;
68
67
}
69
68
}
70
69
71
- // Strategy 2: Try direct deserialization of the entire object
70
+ // Try direct deserialization of the entire object.
72
71
try {
73
72
var model = JsonConvert . DeserializeObject ( jsonObject . ToString ( ) , objectType , jsonSettings ) ;
74
73
75
74
if ( ! ( ( BunqModel ) model ) . IsAllFieldNull ( ) ) {
76
75
return model ;
77
76
}
78
77
} catch ( System . Exception ) {
79
- // If direct deserialization fails, continue to the field-by-field approach
78
+ // If direct deserialization fails, continue to the field-by-field approach.
80
79
}
81
80
82
- // Strategy 3: Try to deserialize the JSON into each complex property of the target object
81
+ // Attempt to populate model properties by deserializing the entire JSON into each BunqModel property.
83
82
var allProperties = objectType . GetProperties ( )
84
83
. Where ( p => typeof ( BunqModel ) . IsAssignableFrom ( p . PropertyType ) )
85
84
. ToList ( ) ;
0 commit comments