Skip to content

Commit 58cba44

Browse files
committed
Invert directives and use ZeroDepJson by default
1 parent 2e4eec0 commit 58cba44

File tree

4 files changed

+65
-64
lines changed

4 files changed

+65
-64
lines changed

Runtime/Client/GetRequests.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
using System.Collections.Generic;
2-
#if LOOTLOCKER_USE_ZERODEPJSON
2+
#if !LOOTLOCKER_USE_NEWTONSOFTJSON
33
using LLlibs.ZeroDepJson;
44
#endif
55

@@ -8,7 +8,7 @@ namespace LootLocker.Requests
88
public class LootLockerGetRequest
99
{
1010

11-
#if LOOTLOCKER_USE_ZERODEPJSON
11+
#if !LOOTLOCKER_USE_NEWTONSOFTJSON
1212
[Json(IgnoreWhenSerializing = true, IgnoreWhenDeserializing = true)]
1313
public List<string> getRequests = new List<string>();
1414
#else

Runtime/Client/LootLockerBaseServerAPI.cs

Lines changed: 31 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,11 @@
55
using System;
66
using System.Text;
77
using System.Net;
8-
#if LOOTLOCKER_USE_ZERODEPJSON
9-
using LLlibs.ZeroDepJson;
10-
#elif LOOTLOCKER_USE_NEWTONSOFTJSON
8+
#if LOOTLOCKER_USE_NEWTONSOFTJSON
119
using Newtonsoft.Json;
1210
using Newtonsoft.Json.Linq;
11+
#else
12+
using LLlibs.ZeroDepJson;
1313
#endif
1414
using LootLocker.Requests;
1515

@@ -369,36 +369,35 @@ public ObfuscationDetails(string key, char replacementChar = '*', int visibleCha
369369
};
370370

371371
private static string ObfuscateJsonStringForLogging(string json)
372-
{
373-
#if LOOTLOCKER_USE_ZERODEPJSON
374-
if (string.IsNullOrEmpty(json) || json.Equals("{}"))
372+
{
373+
#if LOOTLOCKER_USE_NEWTONSOFTJSON
374+
if (string.IsNullOrEmpty(json))
375375
{
376376
return json;
377377
}
378-
379-
Dictionary<string, object> jsonObject = null;
378+
379+
JObject jsonObject;
380380
try
381381
{
382-
jsonObject = Json.Deserialize(json) as Dictionary<string, object>;
382+
jsonObject = JObject.Parse(json);
383383
}
384-
catch (JsonException)
384+
catch (JsonReaderException)
385385
{
386386
return json;
387387
}
388-
389-
if (jsonObject != null && jsonObject.Count > 0)
388+
;
389+
if (jsonObject.HasValues)
390390
{
391391
foreach (ObfuscationDetails obfuscationInfo in FieldsToObfuscate)
392392
{
393393
string valueToObfuscate;
394394
try
395395
{
396-
if (!jsonObject.ContainsKey(obfuscationInfo.key))
397-
{
396+
JToken jsonValue;
397+
jsonObject.TryGetValue(obfuscationInfo.key, StringComparison.Ordinal, out jsonValue);
398+
if (jsonValue == null || (jsonValue.Type != JTokenType.String && jsonValue.Type != JTokenType.Integer))
398399
continue;
399-
}
400-
401-
valueToObfuscate = Json.Serialize(jsonObject[obfuscationInfo.key]);
400+
valueToObfuscate = jsonValue.ToString();
402401
}
403402
catch (KeyNotFoundException)
404403
{
@@ -437,34 +436,36 @@ private static string ObfuscateJsonStringForLogging(string json)
437436
}
438437

439438
return LootLockerJson.SerializeObject(jsonObject);
440-
#else
441-
if (string.IsNullOrEmpty(json))
439+
440+
#else //LOOTLOCKER_USE_NEWTONSOFTJSON
441+
if (string.IsNullOrEmpty(json) || json.Equals("{}"))
442442
{
443443
return json;
444444
}
445-
446-
JObject jsonObject;
445+
446+
Dictionary<string, object> jsonObject = null;
447447
try
448448
{
449-
jsonObject = JObject.Parse(json);
449+
jsonObject = Json.Deserialize(json) as Dictionary<string, object>;
450450
}
451-
catch (JsonReaderException)
451+
catch (JsonException)
452452
{
453453
return json;
454454
}
455-
;
456-
if (jsonObject.HasValues)
455+
456+
if (jsonObject != null && jsonObject.Count > 0)
457457
{
458458
foreach (ObfuscationDetails obfuscationInfo in FieldsToObfuscate)
459459
{
460460
string valueToObfuscate;
461461
try
462462
{
463-
JToken jsonValue;
464-
jsonObject.TryGetValue(obfuscationInfo.key, StringComparison.Ordinal, out jsonValue);
465-
if (jsonValue == null || (jsonValue.Type != JTokenType.String && jsonValue.Type != JTokenType.Integer))
463+
if (!jsonObject.ContainsKey(obfuscationInfo.key))
464+
{
466465
continue;
467-
valueToObfuscate = jsonValue.ToString();
466+
}
467+
468+
valueToObfuscate = Json.Serialize(jsonObject[obfuscationInfo.key]);
468469
}
469470
catch (KeyNotFoundException)
470471
{
@@ -503,7 +504,7 @@ private static string ObfuscateJsonStringForLogging(string json)
503504
}
504505

505506
return LootLockerJson.SerializeObject(jsonObject);
506-
#endif
507+
#endif //LOOTLOCKER_USE_NEWTONSOFTJSON
507508
}
508509

509510
string BuildURL(string endpoint, Dictionary<string, string> queryParams = null)

Runtime/Client/LootLockerServerRequest.cs

Lines changed: 25 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,11 @@
22
using UnityEngine;
33
using System;
44
using LootLocker.LootLockerEnums;
5-
#if LOOTLOCKER_USE_ZERODEPJSON
6-
using LLlibs.ZeroDepJson;
7-
#elif LOOTLOCKER_USE_NEWTONSOFTJSON
5+
#if LOOTLOCKER_USE_NEWTONSOFTJSON
86
using Newtonsoft.Json;
97
using Newtonsoft.Json.Serialization;
8+
#else
9+
using LLlibs.ZeroDepJson;
1010
#endif
1111
#if UNITY_EDITOR
1212
using UnityEditor;
@@ -18,61 +18,61 @@ namespace LootLocker
1818

1919
public static class LootLockerJsonSettings
2020
{
21-
#if LOOTLOCKER_USE_ZERODEPJSON
22-
public static readonly JsonOptions Default = new JsonOptions(JsonSerializationOptions.Default & ~JsonSerializationOptions.SkipGetOnly);
23-
#else //LOOTLOCKER_USE_ZERODEPJSON
21+
#if LOOTLOCKER_USE_NEWTONSOFTJSON
2422
public static readonly JsonSerializerSettings Default = new JsonSerializerSettings
2523
{
2624
ContractResolver = new DefaultContractResolver { NamingStrategy = new SnakeCaseNamingStrategy() },
2725
Formatting = Formatting.None
2826
};
27+
#else
28+
public static readonly JsonOptions Default = new JsonOptions(JsonSerializationOptions.Default & ~JsonSerializationOptions.SkipGetOnly);
2929
#endif
3030
}
3131

3232
public static class LootLockerJson
33-
{
34-
#if LOOTLOCKER_USE_ZERODEPJSON
33+
{
34+
#if LOOTLOCKER_USE_NEWTONSOFTJSON
3535
public static string SerializeObject(object obj)
3636
{
3737
return SerializeObject(obj, LootLockerJsonSettings.Default);
3838
}
3939

40-
public static string SerializeObject(object obj, JsonOptions options)
40+
public static string SerializeObject(object obj, JsonSerializerSettings settings)
4141
{
42-
return Json.Serialize(obj, options ?? LootLockerJsonSettings.Default);
42+
return JsonConvert.SerializeObject(obj, settings ?? LootLockerJsonSettings.Default);
4343
}
4444

4545
public static T DeserializeObject<T>(string json)
4646
{
4747
return DeserializeObject<T>(json, LootLockerJsonSettings.Default);
4848
}
4949

50-
public static T DeserializeObject<T>(string json, JsonOptions options)
50+
51+
public static T DeserializeObject<T>(string json, JsonSerializerSettings settings)
5152
{
52-
return Json.Deserialize<T>(json, options ?? LootLockerJsonSettings.Default);
53+
return JsonConvert.DeserializeObject<T>(json, settings ?? LootLockerJsonSettings.Default);
5354
}
54-
#else //LOOTLOCKER_USE_ZERODEPJSON
55+
#else //LOOTLOCKER_USE_NEWTONSOFTJSON
5556
public static string SerializeObject(object obj)
5657
{
5758
return SerializeObject(obj, LootLockerJsonSettings.Default);
5859
}
5960

60-
public static string SerializeObject(object obj, JsonSerializerSettings settings)
61+
public static string SerializeObject(object obj, JsonOptions options)
6162
{
62-
return JsonConvert.SerializeObject(obj, settings ?? LootLockerJsonSettings.Default);
63+
return Json.Serialize(obj, options ?? LootLockerJsonSettings.Default);
6364
}
6465

6566
public static T DeserializeObject<T>(string json)
6667
{
6768
return DeserializeObject<T>(json, LootLockerJsonSettings.Default);
6869
}
6970

70-
71-
public static T DeserializeObject<T>(string json, JsonSerializerSettings settings)
71+
public static T DeserializeObject<T>(string json, JsonOptions options)
7272
{
73-
return JsonConvert.DeserializeObject<T>(json, settings ?? LootLockerJsonSettings.Default);
73+
return Json.Deserialize<T>(json, options ?? LootLockerJsonSettings.Default);
7474
}
75-
#endif
75+
#endif //LOOTLOCKER_USE_NEWTONSOFTJSON
7676
}
7777

7878
[Serializable]
@@ -128,10 +128,10 @@ public class LootLockerResponse
128128
public string EventId { get; set; }
129129

130130
public static void Deserialize<T>(Action<T> onComplete, LootLockerResponse serverResponse,
131-
#if LOOTLOCKER_USE_ZERODEPJSON
131+
#if LOOTLOCKER_USE_NEWTONSOFTJSON
132+
JsonSerializerSettings options = null
133+
#else //LOOTLOCKER_USE_NEWTONSOFTJSON
132134
JsonOptions options = null
133-
#else //LOOTLOCKER_USE_ZERODEPJSON
134-
JsonSerializerSettings options = null
135135
#endif
136136
)
137137
where T : LootLockerResponse, new()
@@ -140,10 +140,10 @@ public static void Deserialize<T>(Action<T> onComplete, LootLockerResponse serve
140140
}
141141

142142
public static T Deserialize<T>(LootLockerResponse serverResponse,
143-
#if LOOTLOCKER_USE_ZERODEPJSON
144-
JsonOptions options = null
145-
#else //LOOTLOCKER_USE_ZERODEPJSON
143+
#if LOOTLOCKER_USE_NEWTONSOFTJSON
146144
JsonSerializerSettings options = null
145+
#else //LOOTLOCKER_USE_NEWTONSOFTJSON
146+
JsonOptions options = null
147147
#endif
148148
)
149149
where T : LootLockerResponse, new()

Runtime/Game/Requests/PlayerRequest.cs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
using System;
2-
using LootLocker.Requests;
3-
#if LOOTLOCKER_USE_ZERODEPJSON
4-
using LLlibs.ZeroDepJson;
5-
#elif LOOTLOCKER_USE_NEWTONSOFTJSON
2+
using LootLocker.Requests;
3+
#if LOOTLOCKER_USE_NEWTONSOFTJSON
64
using Newtonsoft.Json;
5+
#else
6+
using LLlibs.ZeroDepJson;
77
#endif
88

99
namespace LootLocker.Requests
@@ -208,10 +208,10 @@ public class LootLockerPlayerFile : LootLockerResponse
208208
public int size { get; set; }
209209
public string purpose { get; set; }
210210

211-
#if LOOTLOCKER_USE_ZERODEPJSON
212-
[Json(Name = "public")]
213-
#else
211+
#if LOOTLOCKER_USE_NEWTONSOFTJSON
214212
[JsonProperty("public")]
213+
#else
214+
[Json(Name = "public")]
215215
#endif
216216
public bool is_public { get; set; }
217217
public string url { get; set; }

0 commit comments

Comments
 (0)