11using System ;
22using System . Collections . Generic ;
3+ using System . Reflection ;
34using Bunq . Sdk . Context ;
45using Bunq . Sdk . Http ;
56using Bunq . Sdk . Model . Core ;
7+ using Bunq . Sdk . Model . Generated . Endpoint ;
68using Bunq . Sdk . Model . Generated . Object ;
79using Newtonsoft . Json ;
10+ using Newtonsoft . Json . Converters ;
811using Newtonsoft . Json . Serialization ;
912
1013namespace Bunq . Sdk . Json
@@ -14,9 +17,9 @@ namespace Bunq.Sdk.Json
1417 /// </summary>
1518 public class BunqContractResolver : DefaultContractResolver
1619 {
17- private readonly Dictionary < Type , JsonConverter > converterRegistry = new Dictionary < Type , JsonConverter > ( ) ;
20+ protected readonly Dictionary < Type , JsonConverter > converterRegistry = new Dictionary < Type , JsonConverter > ( ) ;
1821
19- public BunqContractResolver ( )
22+ public BunqContractResolver ( IReadOnlyCollection < Type > typesToExclude = null )
2023 {
2124 RegisterConverter ( typeof ( ApiEnvironmentType ) , new ApiEnvironmentTypeConverter ( ) ) ;
2225 RegisterConverter ( typeof ( Geolocation ) , new GeolocationConverter ( ) ) ;
@@ -28,6 +31,20 @@ public BunqContractResolver()
2831 RegisterConverter ( typeof ( double ? ) , new NonIntegerNumberConverter ( ) ) ;
2932 RegisterConverter ( typeof ( float ? ) , new NonIntegerNumberConverter ( ) ) ;
3033 RegisterConverter ( typeof ( Pagination ) , new PaginationConverter ( ) ) ;
34+ RegisterConverter ( typeof ( IAnchorObjectInterface ) , new AnchorObjectConverter ( ) ) ;
35+
36+ if ( typesToExclude == null )
37+ {
38+ return ;
39+ }
40+
41+ foreach ( var type in typesToExclude )
42+ {
43+ if ( converterRegistry . ContainsKey ( type ) )
44+ {
45+ converterRegistry . Remove ( type ) ;
46+ }
47+ }
3148 }
3249
3350 private void RegisterConverter ( Type objectType , JsonConverter converter )
@@ -50,6 +67,13 @@ protected override JsonContract CreateContract(Type objectType)
5067
5168 private JsonConverter GetCustomConverterOrNull ( Type objectType )
5269 {
70+ if ( typeof ( IAnchorObjectInterface ) . IsAssignableFrom ( objectType ) )
71+ {
72+ return converterRegistry . ContainsKey ( typeof ( IAnchorObjectInterface ) )
73+ ? converterRegistry [ typeof ( IAnchorObjectInterface ) ]
74+ : null ;
75+ }
76+
5377 return converterRegistry . ContainsKey ( objectType ) ? converterRegistry [ objectType ] : null ;
5478 }
5579 }
0 commit comments