1
0
mirror of https://github.com/bitwarden/mobile synced 2025-12-10 05:13:31 +00:00

json settings

This commit is contained in:
Kyle Spearrin
2019-04-08 20:49:48 -04:00
parent 992cf033f2
commit 41321e3c9e
2 changed files with 15 additions and 5 deletions

View File

@@ -1,5 +1,6 @@
using Bit.Core.Abstractions; using Bit.Core.Abstractions;
using Newtonsoft.Json; using Newtonsoft.Json;
using Newtonsoft.Json.Serialization;
using System; using System;
using System.Threading.Tasks; using System.Threading.Tasks;
@@ -8,6 +9,10 @@ namespace Bit.Core.Services
public class PreferencesStorageService : IStorageService public class PreferencesStorageService : IStorageService
{ {
private string _keyFormat = "bwPreferencesStorage:{0}"; private string _keyFormat = "bwPreferencesStorage:{0}";
private readonly JsonSerializerSettings _jsonSettings = new JsonSerializerSettings
{
ContractResolver = new CamelCasePropertyNamesContractResolver()
};
public Task<T> GetAsync<T>(string key) public Task<T> GetAsync<T>(string key)
{ {
@@ -51,7 +56,7 @@ namespace Bit.Core.Services
else else
{ {
var val = Xamarin.Essentials.Preferences.Get(formattedKey, default(string)); var val = Xamarin.Essentials.Preferences.Get(formattedKey, default(string));
return Task.FromResult(JsonConvert.DeserializeObject<T>(val)); return Task.FromResult(JsonConvert.DeserializeObject<T>(val, _jsonSettings));
} }
} }
@@ -90,7 +95,7 @@ namespace Bit.Core.Services
} }
else else
{ {
Xamarin.Essentials.Preferences.Set(formattedKey, JsonConvert.SerializeObject(obj)); Xamarin.Essentials.Preferences.Set(formattedKey, JsonConvert.SerializeObject(obj, _jsonSettings));
} }
return Task.FromResult(0); return Task.FromResult(0);
} }

View File

@@ -1,6 +1,6 @@
using Bit.Core.Abstractions; using Bit.Core.Abstractions;
using Newtonsoft.Json; using Newtonsoft.Json;
using System; using Newtonsoft.Json.Serialization;
using System.Threading.Tasks; using System.Threading.Tasks;
namespace Bit.Core.Services namespace Bit.Core.Services
@@ -8,6 +8,10 @@ namespace Bit.Core.Services
public class SecureStorageService : IStorageService public class SecureStorageService : IStorageService
{ {
private string _keyFormat = "bwSecureStorage:{0}"; private string _keyFormat = "bwSecureStorage:{0}";
private readonly JsonSerializerSettings _jsonSettings = new JsonSerializerSettings
{
ContractResolver = new CamelCasePropertyNamesContractResolver()
};
public async Task<T> GetAsync<T>(string key) public async Task<T> GetAsync<T>(string key)
{ {
@@ -20,7 +24,7 @@ namespace Bit.Core.Services
} }
else else
{ {
return JsonConvert.DeserializeObject<T>(val); return JsonConvert.DeserializeObject<T>(val, _jsonSettings);
} }
} }
@@ -39,7 +43,8 @@ namespace Bit.Core.Services
} }
else else
{ {
await Xamarin.Essentials.SecureStorage.SetAsync(formattedKey, JsonConvert.SerializeObject(obj)); await Xamarin.Essentials.SecureStorage.SetAsync(formattedKey,
JsonConvert.SerializeObject(obj, _jsonSettings));
} }
} }