From 41321e3c9e296f2eff5a66fb36e791297601b6a6 Mon Sep 17 00:00:00 2001 From: Kyle Spearrin Date: Mon, 8 Apr 2019 20:49:48 -0400 Subject: [PATCH] json settings --- src/Core/Services/PreferencesStorageService.cs | 9 +++++++-- src/Core/Services/SecureStorageService.cs | 11 ++++++++--- 2 files changed, 15 insertions(+), 5 deletions(-) diff --git a/src/Core/Services/PreferencesStorageService.cs b/src/Core/Services/PreferencesStorageService.cs index ccaee3bef..005c0725c 100644 --- a/src/Core/Services/PreferencesStorageService.cs +++ b/src/Core/Services/PreferencesStorageService.cs @@ -1,5 +1,6 @@ using Bit.Core.Abstractions; using Newtonsoft.Json; +using Newtonsoft.Json.Serialization; using System; using System.Threading.Tasks; @@ -8,6 +9,10 @@ namespace Bit.Core.Services public class PreferencesStorageService : IStorageService { private string _keyFormat = "bwPreferencesStorage:{0}"; + private readonly JsonSerializerSettings _jsonSettings = new JsonSerializerSettings + { + ContractResolver = new CamelCasePropertyNamesContractResolver() + }; public Task GetAsync(string key) { @@ -51,7 +56,7 @@ namespace Bit.Core.Services else { var val = Xamarin.Essentials.Preferences.Get(formattedKey, default(string)); - return Task.FromResult(JsonConvert.DeserializeObject(val)); + return Task.FromResult(JsonConvert.DeserializeObject(val, _jsonSettings)); } } @@ -90,7 +95,7 @@ namespace Bit.Core.Services } else { - Xamarin.Essentials.Preferences.Set(formattedKey, JsonConvert.SerializeObject(obj)); + Xamarin.Essentials.Preferences.Set(formattedKey, JsonConvert.SerializeObject(obj, _jsonSettings)); } return Task.FromResult(0); } diff --git a/src/Core/Services/SecureStorageService.cs b/src/Core/Services/SecureStorageService.cs index 8a18f7b94..f4a01aabf 100644 --- a/src/Core/Services/SecureStorageService.cs +++ b/src/Core/Services/SecureStorageService.cs @@ -1,6 +1,6 @@ using Bit.Core.Abstractions; using Newtonsoft.Json; -using System; +using Newtonsoft.Json.Serialization; using System.Threading.Tasks; namespace Bit.Core.Services @@ -8,6 +8,10 @@ namespace Bit.Core.Services public class SecureStorageService : IStorageService { private string _keyFormat = "bwSecureStorage:{0}"; + private readonly JsonSerializerSettings _jsonSettings = new JsonSerializerSettings + { + ContractResolver = new CamelCasePropertyNamesContractResolver() + }; public async Task GetAsync(string key) { @@ -20,7 +24,7 @@ namespace Bit.Core.Services } else { - return JsonConvert.DeserializeObject(val); + return JsonConvert.DeserializeObject(val, _jsonSettings); } } @@ -39,7 +43,8 @@ namespace Bit.Core.Services } else { - await Xamarin.Essentials.SecureStorage.SetAsync(formattedKey, JsonConvert.SerializeObject(obj)); + await Xamarin.Essentials.SecureStorage.SetAsync(formattedKey, + JsonConvert.SerializeObject(obj, _jsonSettings)); } }