-
Notifications
You must be signed in to change notification settings - Fork 115
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1095 from alexander-olesiyuk-apaleo/1093-serializ…
…ation-configuration Explicitly configure ContractResolver for SaleToPOIMessage serialization
- Loading branch information
Showing
4 changed files
with
169 additions
and
15 deletions.
There are no files selected for viewing
This file contains 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
34 changes: 24 additions & 10 deletions
34
Adyen/ApiSerialization/Converter/JsonConvertSerializerWrapper.cs
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,29 +1,43 @@ | ||
using Adyen.Model.TerminalApi; | ||
using System.Collections.Generic; | ||
using Adyen.Model.TerminalApi; | ||
using Adyen.Security; | ||
using Newtonsoft.Json; | ||
using Newtonsoft.Json.Converters; | ||
using Newtonsoft.Json.Serialization; | ||
|
||
namespace Adyen.ApiSerialization.Converter | ||
{ | ||
internal class JsonConvertSerializerWrapper | ||
{ | ||
private const string DateTimeFormat = "yyyy-MM-ddTHH\\:mm\\:ss"; | ||
|
||
private static readonly JsonSerializerSettings SaleToPoiMessageSerializerSettings = CreateSerializerSettings(new SaleToPoiMessageConverter()); | ||
private static readonly JsonSerializerSettings SaleToPoiMessageSecuredSerializerSettings = CreateSerializerSettings(new SaleToPoiMessageSecuredConverter()); | ||
|
||
internal static string Serialize(SaleToPOIMessage saleToPoiMessage) | ||
{ | ||
var serialize= JsonConvert.SerializeObject(saleToPoiMessage, | ||
new SaleToPoiMessageConverter(), | ||
new StringEnumConverter(), | ||
new IsoDateTimeConverter { DateTimeFormat = DateTimeFormat }); | ||
return serialize; | ||
return JsonConvert.SerializeObject(saleToPoiMessage, SaleToPoiMessageSerializerSettings); | ||
} | ||
|
||
internal static string Serialize(SaleToPoiMessageSecured saleToPoiMessageSecured) | ||
{ | ||
return JsonConvert.SerializeObject(saleToPoiMessageSecured, | ||
new SaleToPoiMessageSecuredConverter(), | ||
new StringEnumConverter(), | ||
new IsoDateTimeConverter { DateTimeFormat = DateTimeFormat }); | ||
return JsonConvert.SerializeObject(saleToPoiMessageSecured, SaleToPoiMessageSecuredSerializerSettings); | ||
} | ||
|
||
private static JsonSerializerSettings CreateSerializerSettings(JsonConverter messageConverter) | ||
{ | ||
return new JsonSerializerSettings | ||
{ | ||
Converters = new List<JsonConverter> | ||
{ | ||
messageConverter, | ||
new StringEnumConverter(), | ||
new IsoDateTimeConverter { DateTimeFormat = DateTimeFormat } | ||
}, | ||
NullValueHandling = NullValueHandling.Ignore, | ||
MissingMemberHandling = MissingMemberHandling.Ignore, | ||
ContractResolver = new DefaultContractResolver() | ||
}; | ||
} | ||
} | ||
} |
This file contains 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
This file contains 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