Skip to content

Commit 1a48b01

Browse files
author
Pascal Wink
committed
add comments
1 parent d9fb1ad commit 1a48b01

File tree

1 file changed

+7
-8
lines changed

1 file changed

+7
-8
lines changed

BunqSdk/Json/AnchorObjectConverter.cs

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,9 @@ public override object ReadJson(
2424
object existingValue,
2525
JsonSerializer serializer
2626
) {
27-
// Load JSON into memory for processing
2827
JObject jsonObject = JObject.Load(reader);
2928

30-
// Create serializer settings that exclude IAnchorObjectInterface to prevent infinite recursion
29+
// Create serializer settings that exclude IAnchorObjectInterface to prevent infinite recursion.
3130
var jsonSettings = new JsonSerializerSettings {
3231
ContractResolver = new BunqContractResolver(new List<Type> { typeof(IAnchorObjectInterface) }),
3332
DateFormatString = FORMAT_DATE,
@@ -36,10 +35,10 @@ JsonSerializer serializer
3635
NullValueHandling = NullValueHandling.Ignore,
3736
};
3837

39-
// Create empty instance of the target type
38+
// Create empty instance of the target type.
4039
var instance = (IAnchorObjectInterface)Activator.CreateInstance(objectType);
4140

42-
// Strategy 1: Try mapping "object" container properties to target object properties
41+
// Try mapping "object" container properties to target object properties.
4342
if (jsonObject.TryGetValue(OBJECT_KEY, out JToken objectToken) && objectToken is JObject objectContent) {
4443
var properties = objectType.GetProperties();
4544

@@ -62,24 +61,24 @@ JsonSerializer serializer
6261
}
6362
}
6463

65-
// Return if we successfully populated at least one field
64+
// Return if we successfully populated the model.
6665
if (!((BunqModel)instance).IsAllFieldNull()) {
6766
return instance;
6867
}
6968
}
7069

71-
// Strategy 2: Try direct deserialization of the entire object
70+
// Try direct deserialization of the entire object.
7271
try {
7372
var model = JsonConvert.DeserializeObject(jsonObject.ToString(), objectType, jsonSettings);
7473

7574
if (!((BunqModel)model).IsAllFieldNull()) {
7675
return model;
7776
}
7877
} 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.
8079
}
8180

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.
8382
var allProperties = objectType.GetProperties()
8483
.Where(p => typeof(BunqModel).IsAssignableFrom(p.PropertyType))
8584
.ToList();

0 commit comments

Comments
 (0)