Skip to content

Commit 28f6bc7

Browse files
committed
Switch out external newtonsoft to Unity.Plastic
1 parent e135439 commit 28f6bc7

25 files changed

+105
-158
lines changed

Runtime/Client/GetRequests.cs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,4 @@
1-
using System.Collections;
2-
using System.Collections.Generic;
3-
using UnityEngine;
4-
using Newtonsoft.Json;
1+
using System.Collections.Generic;
52

63
namespace LootLocker.Requests
74
{

Runtime/Client/LootLockerBaseServerAPI.cs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,14 @@
22
using System.Collections.Generic;
33
using UnityEngine;
44
using UnityEngine.Networking;
5-
using Newtonsoft.Json;
5+
//using Newtonsoft.Json;
6+
using Unity.Plastic.Newtonsoft.Json;
67
using System;
78
using System.Text;
89
using System.Net;
910
using LootLocker.Requests;
10-
using Newtonsoft.Json.Linq;
11+
//using Newtonsoft.Json.Linq;
12+
using Unity.Plastic.Newtonsoft.Json.Linq;
1113

1214
namespace LootLocker.LootLockerEnums
1315
{
@@ -289,7 +291,7 @@ UnityWebRequest CreateWebRequest(string url, LootLockerServerRequest request)
289291
}
290292
else
291293
{
292-
string json = (request.payload != null && request.payload.Count > 0) ? JsonConvert.SerializeObject(request.payload) : request.jsonPayload;
294+
string json = (request.payload != null && request.payload.Count > 0) ? LootLockerJson.SerializeObject(request.payload) : request.jsonPayload;
293295
#if UNITY_EDITOR
294296
LootLockerLogger.GetForLogLevel(LootLockerLogger.LogLevel.Verbose)("REQUEST BODY = " + ObfuscateJsonStringForLogging(json));
295297
#endif
@@ -431,7 +433,7 @@ private static string ObfuscateJsonStringForLogging(string json)
431433
}
432434
}
433435

434-
return JsonConvert.SerializeObject(jsonObject);
436+
return LootLockerJson.SerializeObject(jsonObject);
435437
}
436438

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

Runtime/Client/LootLockerServerRequest.cs

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
11
using System.Collections.Generic;
22
using UnityEngine;
33
using System;
4-
using Newtonsoft.Json;
4+
using Unity.Plastic.Newtonsoft.Json;
55
using LootLocker.LootLockerEnums;
6-
using LootLocker.Requests;
7-
using Newtonsoft.Json.Serialization;
6+
using Unity.Plastic.Newtonsoft.Json.Serialization;
87
#if UNITY_EDITOR
98
using UnityEditor;
109
#endif
@@ -31,6 +30,19 @@ public static class LootLockerJsonSettings
3130
};
3231
}
3332

33+
public static class LootLockerJson
34+
{
35+
public static string SerializeObject(object obj, JsonSerializerSettings settings = null)
36+
{
37+
return JsonConvert.SerializeObject(obj, settings ?? LootLockerJsonSettings.Default);
38+
}
39+
40+
public static T DeserializeObject<T>(string json, JsonSerializerSettings settings = null)
41+
{
42+
return JsonConvert.DeserializeObject<T>(json, settings ?? LootLockerJsonSettings.Default);
43+
}
44+
}
45+
3446
[System.Serializable]
3547
public enum LootLockerHTTPMethod
3648
{
@@ -102,7 +114,7 @@ public static T Deserialize<T>(LootLockerResponse serverResponse, JsonSerializer
102114
return new T() { success = false, Error = serverResponse.Error, statusCode = serverResponse.statusCode };
103115
}
104116

105-
var response = JsonConvert.DeserializeObject<T>(serverResponse.text, settings ?? LootLockerJsonSettings.Default) ?? new T();
117+
var response = LootLockerJson.DeserializeObject<T>(serverResponse.text, settings ?? LootLockerJsonSettings.Default) ?? new T();
106118

107119
response.text = serverResponse.text;
108120
response.success = serverResponse.success;

Runtime/Game/LootLockerSDKManager.cs

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
using UnityEngine;
55
using System.Security.Cryptography;
66
using System.Text;
7-
using Newtonsoft.Json;
87
using LootLocker.LootLockerEnums;
98
using static LootLocker.LootLockerConfig;
109
using System.Linq;
@@ -1776,7 +1775,7 @@ public static void AddPointsToPlayerProgression(string progressionKey, ulong amo
17761775

17771776
var endpoint = string.Format(LootLockerEndPoints.addPointsToPlayerProgression.endPoint, progressionKey);
17781777

1779-
var body = JsonConvert.SerializeObject(new { amount });
1778+
var body = LootLockerJson.SerializeObject(new { amount });
17801779

17811780
LootLockerServerRequest.CallAPI(endpoint, LootLockerHTTPMethod.POST, body, onComplete: (serverResponse) => { LootLockerResponse.Deserialize(onComplete, serverResponse); });
17821781
}
@@ -1797,7 +1796,7 @@ public static void SubtractPointsFromPlayerProgression(string progressionKey, ul
17971796

17981797
var endpoint = string.Format(LootLockerEndPoints.subtractPointsFromPlayerProgression.endPoint, progressionKey);
17991798

1800-
var body = JsonConvert.SerializeObject(new { amount });
1799+
var body = LootLockerJson.SerializeObject(new { amount });
18011800

18021801
LootLockerServerRequest.CallAPI(endpoint, LootLockerHTTPMethod.POST, body, onComplete: (serverResponse) => { LootLockerResponse.Deserialize(onComplete, serverResponse); });
18031802
}
@@ -2223,7 +2222,7 @@ public static void AddPointsToCharacterProgression(int characterId, string progr
22232222

22242223
var endpoint = string.Format(LootLockerEndPoints.addPointsToCharacterProgression.endPoint, characterId, progressionKey);
22252224

2226-
var body = JsonConvert.SerializeObject(new { amount });
2225+
var body = LootLockerJson.SerializeObject(new { amount });
22272226

22282227
LootLockerServerRequest.CallAPI(endpoint, LootLockerHTTPMethod.POST, body, onComplete: (serverResponse) => { LootLockerResponse.Deserialize(onComplete, serverResponse); });
22292228
}
@@ -2245,7 +2244,7 @@ public static void SubtractPointsFromCharacterProgression(int characterId, strin
22452244

22462245
var endpoint = string.Format(LootLockerEndPoints.subtractPointsFromCharacterProgression.endPoint, characterId, progressionKey);
22472246

2248-
var body = JsonConvert.SerializeObject(new { amount });
2247+
var body = LootLockerJson.SerializeObject(new { amount });
22492248

22502249
LootLockerServerRequest.CallAPI(endpoint, LootLockerHTTPMethod.POST, body, onComplete: (serverResponse) => { LootLockerResponse.Deserialize(onComplete, serverResponse); });
22512250
}
@@ -3246,7 +3245,7 @@ public static void FinishingAMission(int missionId, string startingMissionSignat
32463245
return;
32473246
}
32483247

3249-
string source = JsonConvert.SerializeObject(finishingPayload) + startingMissionSignature + playerId;
3248+
string source = LootLockerJson.SerializeObject(finishingPayload) + startingMissionSignature + playerId;
32503249
string hash;
32513250
using (SHA1 sha1Hash = SHA1.Create())
32523251
{
@@ -3280,7 +3279,7 @@ public static void FinishMission(int missionId, string startingMissionSignature,
32803279
onComplete?.Invoke(LootLockerResponseFactory.SDKNotInitializedError<LootLockerFinishMissionResponse>());
32813280
return;
32823281
}
3283-
string source = JsonConvert.SerializeObject(finishingPayload) + startingMissionSignature + playerId;
3282+
string source = LootLockerJson.SerializeObject(finishingPayload) + startingMissionSignature + playerId;
32843283
string hash;
32853284
using (SHA1 sha1Hash = SHA1.Create())
32863285
{

Runtime/Game/Requests/AssetInstanceRequest.cs

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,5 @@
1-
using System.Collections;
2-
using System.Collections.Generic;
3-
using UnityEngine;
4-
using LootLocker;
5-
using LootLocker.Requests;
6-
using Newtonsoft.Json;
1+
using LootLocker.Requests;
72
using System;
8-
using System.Linq;
93

104
namespace LootLocker.Requests
115
{
@@ -101,7 +95,7 @@ public static void GetAKeyValuePairById(LootLockerGetRequest data, Action<LootLo
10195
return;
10296
}
10397

104-
string json = JsonConvert.SerializeObject(data);
98+
string json = LootLockerJson.SerializeObject(data);
10599

106100
EndPointClass endPoint = LootLockerEndPoints.getAKeyValuePairById;
107101

@@ -118,7 +112,7 @@ public static void CreateKeyValuePair(LootLockerGetRequest lootLockerGetRequest,
118112
return;
119113
}
120114

121-
string json = JsonConvert.SerializeObject(data);
115+
string json = LootLockerJson.SerializeObject(data);
122116

123117
EndPointClass endPoint = LootLockerEndPoints.createKeyValuePair;
124118

@@ -135,7 +129,7 @@ public static void UpdateOneOrMoreKeyValuePair(LootLockerGetRequest lootLockerGe
135129
return;
136130
}
137131

138-
string json = JsonConvert.SerializeObject(data);
132+
string json = LootLockerJson.SerializeObject(data);
139133

140134
EndPointClass endPoint = LootLockerEndPoints.updateOneOrMoreKeyValuePair;
141135

@@ -152,7 +146,7 @@ public static void UpdateKeyValuePairById(LootLockerGetRequest lootLockerGetRequ
152146
return;
153147
}
154148

155-
string json = JsonConvert.SerializeObject(data);
149+
string json = LootLockerJson.SerializeObject(data);
156150

157151
EndPointClass endPoint = LootLockerEndPoints.updateKeyValuePairById;
158152

Runtime/Game/Requests/AssetRequest.cs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
using Newtonsoft.Json;
1+
//using Newtonsoft.Json;
2+
using Unity.Plastic.Newtonsoft.Json;
23
using System;
34
using System.Collections;
45
using System.Collections.Generic;
@@ -335,11 +336,11 @@ public static void GetAssetById(LootLockerGetRequest data, Action<LootLockerSing
335336
LootLockerAssetResponse realResponse = LootLockerResponse.Deserialize<LootLockerAssetResponse>(serverResponse);
336337
LootLockerSingleAssetResponse newResponse = new LootLockerSingleAssetResponse();
337338

338-
string serializedAsset = JsonConvert.SerializeObject(realResponse.assets[0], Formatting.Indented);
339+
string serializedAsset = LootLockerJson.SerializeObject(realResponse.assets[0], LootLockerJsonSettings.Indented);
339340

340-
newResponse.asset = JsonConvert.DeserializeObject<LootLockerCommonAsset>(serializedAsset);
341+
newResponse.asset = LootLockerJson.DeserializeObject<LootLockerCommonAsset>(serializedAsset);
341342

342-
string singleAssetResponse = JsonConvert.SerializeObject(newResponse, Formatting.Indented);
343+
string singleAssetResponse = LootLockerJson.SerializeObject(newResponse, LootLockerJsonSettings.Indented);
343344
newResponse.text = singleAssetResponse;
344345
newResponse.SetResponseInfo(serverResponse);
345346

Runtime/Game/Requests/CharacterRequest.cs

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,5 @@
1-
using LootLocker;
2-
using System;
3-
using System.Collections;
4-
using System.Collections.Generic;
5-
using UnityEngine;
1+
using System;
62
using LootLocker.Requests;
7-
using Newtonsoft.Json;
83
using System.Linq;
94

105

@@ -143,7 +138,7 @@ public static void CreateCharacter(LootLockerCreateCharacterRequest data, Action
143138
return;
144139
}
145140

146-
string json = JsonConvert.SerializeObject(data);
141+
string json = LootLockerJson.SerializeObject(data);
147142

148143
string getVariable = endPoint.endPoint;
149144

@@ -185,7 +180,7 @@ public static void UpdateCharacter(LootLockerGetRequest lootLockerGetRequest, Lo
185180
return;
186181
}
187182

188-
string json = JsonConvert.SerializeObject(data);
183+
string json = LootLockerJson.SerializeObject(data);
189184

190185
EndPointClass endPoint = LootLockerEndPoints.updateCharacter;
191186

@@ -202,7 +197,7 @@ public static void EquipIdAssetToDefaultCharacter(LootLockerEquipByIDRequest dat
202197
return;
203198
}
204199

205-
string json = JsonConvert.SerializeObject(data);
200+
string json = LootLockerJson.SerializeObject(data);
206201

207202
EndPointClass endPoint = LootLockerEndPoints.equipIDAssetToDefaultCharacter;
208203

@@ -219,7 +214,7 @@ public static void EquipGlobalAssetToDefaultCharacter(LootLockerEquipByAssetRequ
219214
return;
220215
}
221216

222-
string json = JsonConvert.SerializeObject(data);
217+
string json = LootLockerJson.SerializeObject(data);
223218

224219
EndPointClass endPoint = LootLockerEndPoints.equipGlobalAssetToDefaultCharacter;
225220

@@ -236,7 +231,7 @@ public static void EquipIdAssetToCharacter(LootLockerGetRequest lootLockerGetReq
236231
return;
237232
}
238233

239-
string json = JsonConvert.SerializeObject(data);
234+
string json = LootLockerJson.SerializeObject(data);
240235

241236
EndPointClass endPoint = LootLockerEndPoints.equipIDAssetToCharacter;
242237

@@ -253,7 +248,7 @@ public static void EquipGlobalAssetToCharacter(LootLockerGetRequest lootLockerGe
253248
return;
254249
}
255250

256-
string json = JsonConvert.SerializeObject(data);
251+
string json = LootLockerJson.SerializeObject(data);
257252

258253
EndPointClass endPoint = LootLockerEndPoints.equipGlobalAssetToCharacter;
259254

Runtime/Game/Requests/CollectableRequest.cs

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,4 @@
1-
using System.Collections;
2-
using System.Collections.Generic;
3-
using UnityEngine;
4-
using LootLocker;
5-
using LootLocker.Requests;
6-
using Newtonsoft.Json;
1+
using LootLocker.Requests;
72
using System;
83
using System.Linq;
94
using UnityEngine.UI;
@@ -106,7 +101,7 @@ public static void GetCollectables(Action<LootLockerGetCollectablesResponse> onC
106101
{
107102
LootLockerGetCollectablesResponse response = new LootLockerGetCollectablesResponse();
108103
if (string.IsNullOrEmpty(serverResponse.Error))
109-
response = JsonConvert.DeserializeObject<LootLockerGetCollectablesResponse>(serverResponse.text);
104+
response = LootLockerJson.DeserializeObject<LootLockerGetCollectablesResponse>(serverResponse.text);
110105

111106
response.text = serverResponse.text;
112107
response.success = serverResponse.success;
@@ -125,7 +120,7 @@ public static void GettingCollectables(Action<LootLockerGettingCollectablesRespo
125120
{
126121
LootLockerGettingCollectablesResponse response = new LootLockerGettingCollectablesResponse();
127122
if (string.IsNullOrEmpty(serverResponse.Error))
128-
response = JsonConvert.DeserializeObject<LootLockerGettingCollectablesResponse>(serverResponse.text);
123+
response = LootLockerJson.DeserializeObject<LootLockerGettingCollectablesResponse>(serverResponse.text);
129124

130125
response.text = serverResponse.text;
131126
response.success = serverResponse.success;
@@ -143,7 +138,7 @@ public static void CollectItem(LootLockerCollectingAnItemRequest data, Action<Lo
143138
return;
144139
}
145140

146-
string json = JsonConvert.SerializeObject(data);
141+
string json = LootLockerJson.SerializeObject(data);
147142

148143
EndPointClass endPoint = LootLockerEndPoints.collectingAnItem;
149144

@@ -152,7 +147,7 @@ public static void CollectItem(LootLockerCollectingAnItemRequest data, Action<Lo
152147
LootLockerCollectItemResponse response = new LootLockerCollectItemResponse();
153148
if (string.IsNullOrEmpty(serverResponse.Error))
154149
{
155-
response = JsonConvert.DeserializeObject<LootLockerCollectItemResponse>(serverResponse.text);
150+
response = LootLockerJson.DeserializeObject<LootLockerCollectItemResponse>(serverResponse.text);
156151
string[] collectableStrings = data.slug.Split('.');
157152

158153
string collectable = collectableStrings[0];
@@ -181,7 +176,7 @@ public static void CollectingAnItem(LootLockerCollectingAnItemRequest data, Acti
181176
return;
182177
}
183178

184-
string json = JsonConvert.SerializeObject(data);
179+
string json = LootLockerJson.SerializeObject(data);
185180

186181
EndPointClass endPoint = LootLockerEndPoints.collectingAnItem;
187182

@@ -190,7 +185,7 @@ public static void CollectingAnItem(LootLockerCollectingAnItemRequest data, Acti
190185
LootLockerCollectingAnItemResponse response = new LootLockerCollectingAnItemResponse();
191186
if (string.IsNullOrEmpty(serverResponse.Error))
192187
{
193-
response = JsonConvert.DeserializeObject<LootLockerCollectingAnItemResponse>(serverResponse.text);
188+
response = LootLockerJson.DeserializeObject<LootLockerCollectingAnItemResponse>(serverResponse.text);
194189
string[] collectableStrings = data.slug.Split('.');
195190

196191
string collectable = collectableStrings[0];

Runtime/Game/Requests/CrashesRequest.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
using Newtonsoft.Json;
1+
//using Newtonsoft.Json;
2+
using Unity.Plastic.Newtonsoft.Json;
23
using System;
34
using System.Collections;
45
using System.Collections.Generic;
@@ -47,7 +48,7 @@ public static void SubmittingACrashLog(LootLockerSubmittingACrashLogRequest data
4748
if (string.IsNullOrEmpty(serverResponse.Error))
4849
{
4950
LootLockerLogger.GetForLogLevel(LootLockerLogger.LogLevel.Verbose)(serverResponse.text);
50-
response = JsonConvert.DeserializeObject<LootLockerResponse>(serverResponse.text);
51+
response = LootLockerJson.DeserializeObject<LootLockerResponse>(serverResponse.text);
5152
onComplete?.Invoke(response);
5253
}
5354
else

Runtime/Game/Requests/DropTableRequest.cs

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,5 @@
11
using LootLocker.Requests;
2-
using Newtonsoft.Json;
32
using System;
4-
using System.Collections;
5-
using System.Collections.Generic;
6-
using UnityEngine;
73

84
namespace LootLocker.Requests
95
{
@@ -68,7 +64,7 @@ public static void PickDropsFromDropTable(PickDropsFromDropTableRequest data, in
6864
return;
6965
}
7066

71-
string json = JsonConvert.SerializeObject(data);
67+
string json = LootLockerJson.SerializeObject(data);
7268

7369
string endPoint = string.Format(requestEndPoint.endPoint, tableInstanceId);
7470

0 commit comments

Comments
 (0)