Skip to content

Commit 98e178f

Browse files
authored
Fixed deserialization fail on arrays with null values (#84)
* fix: Fixed deserialization fail on arrays with all null values * PubNub SDK v6.0.9 release.
1 parent 14b7c64 commit 98e178f

File tree

5 files changed

+27
-20
lines changed

5 files changed

+27
-20
lines changed

.pubnub.yml

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
11
---
2-
version: v6.0.8
2+
version: v6.0.9
33
changelog:
4+
- date: 2023-03-30
5+
version: v6.0.9
6+
changes:
7+
- type: bug
8+
text: "Fixed deserialization fail on arrays with all null values."
49
- date: 2023-03-24
510
version: v6.0.8
611
changes:
@@ -670,7 +675,7 @@ sdks:
670675
distribution-type: package
671676
distribution-repository: git release
672677
package-name: PubNub.unitypackage
673-
location: https://github.com/pubnub/unity/releases/download/v6.0.8/PubNub.unitypackage
678+
location: https://github.com/pubnub/unity/releases/download/v6.0.9/PubNub.unitypackage
674679
requires:
675680
-
676681
name: "UnityEditor"
@@ -837,7 +842,7 @@ sdks:
837842
distribution-type: package
838843
distribution-repository: git release
839844
package-name: PubNub.unitypackage
840-
location: https://github.com/pubnub/unity/releases/download/v6.0.8/PubNub.unitypackage
845+
location: https://github.com/pubnub/unity/releases/download/v6.0.9/PubNub.unitypackage
841846
requires:
842847
-
843848
name: "UnityEditor"

PubNubUnity/Assets/PubNub/PubNubUnity/PubNubUnityBase.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ namespace PubNubAPI
77
public class PubNubUnityBase
88
{
99
protected Counter publishMessageCounter;
10-
private const string build = "6.0.8";
10+
private const string build = "6.0.9";
1111
private string pnsdkVersion = string.Format ("PubNub-CSharp-Unity/{0}", build);
1212

1313
public string Version {

PubNubUnity/Assets/PubNub/Serialization/JSONSerializer.cs

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -381,7 +381,8 @@ private object deserializeToDictionary(string jo, bool isArray=false)
381381

382382
var values = JsonConvert.DeserializeObject<Dictionary<string, object>>(jo, defaultSettings);
383383
#if (ENABLE_PUBNUB_LOGGING)
384-
pnUnityBase.PNLog.WriteToLog (string.Format("JsonConvert.SerializeObject(values) {0}", JsonConvert.SerializeObject(values, defaultSettings)), PNLoggingMethod.LevelInfo);
384+
pnUnityBase.PNLog.WriteToLog (
385+
$"JsonConvert.SerializeObject(values) {JsonConvert.SerializeObject(values, defaultSettings)}", PNLoggingMethod.LevelInfo);
385386
#endif
386387

387388
var values2 = new Dictionary<string, object>();
@@ -390,21 +391,21 @@ private object deserializeToDictionary(string jo, bool isArray=false)
390391
if (d.Value is JObject)
391392
{
392393
#if (ENABLE_PUBNUB_LOGGING)
393-
pnUnityBase.PNLog.WriteToLog (string.Format("1: d.Key {0}, d.Value {1}", d.Key, d.Value), PNLoggingMethod.LevelInfo);
394+
pnUnityBase.PNLog.WriteToLog ($"1: d.Key {d.Key}, d.Value {d.Value}", PNLoggingMethod.LevelInfo);
394395
#endif
395396
values2.Add(d.Key, deserializeToDictionary(d.Value.ToString()));
396397
}
397398
else if (d.Value is JArray)
398399
{
399400
#if (ENABLE_PUBNUB_LOGGING)
400-
pnUnityBase.PNLog.WriteToLog (string.Format("2: d.Key {0}, d.Value {1}", d.Key, d.Value), PNLoggingMethod.LevelInfo);
401+
pnUnityBase.PNLog.WriteToLog ($"2: d.Key {d.Key}, d.Value {d.Value}", PNLoggingMethod.LevelInfo);
401402
#endif
402403
values2.Add(d.Key, deserializeToDictionary(d.Value.ToString(), true));
403404
}
404405
else
405406
{
406407
#if (ENABLE_PUBNUB_LOGGING)
407-
pnUnityBase.PNLog.WriteToLog (string.Format("3: d.Key {0}, d.Value {1}", d.Key, d.Value), PNLoggingMethod.LevelInfo);
408+
pnUnityBase.PNLog.WriteToLog ($"3: d.Key {d.Key}, d.Value {d.Value}", PNLoggingMethod.LevelInfo);
408409
#endif
409410
values2.Add(d.Key, d.Value);
410411
}
@@ -416,20 +417,21 @@ private object deserializeToDictionary(string jo, bool isArray=false)
416417

417418
var values = JsonConvert.DeserializeObject<List<object>>(jo, defaultSettings);
418419
#if (ENABLE_PUBNUB_LOGGING)
419-
pnUnityBase.PNLog.WriteToLog (string.Format("2: JsonConvert.SerializeObject(values) {0}", JsonConvert.SerializeObject(values, defaultSettings)), PNLoggingMethod.LevelInfo);
420+
pnUnityBase.PNLog.WriteToLog (
421+
$"2: JsonConvert.SerializeObject(values) {JsonConvert.SerializeObject(values, defaultSettings)}", PNLoggingMethod.LevelInfo);
420422
#endif
421423

422424
Type whatType = typeof(object);
423425
Type currType = whatType;
424426
int count = 0;
425427
foreach (var d in values)
426428
{
427-
if ((d is JObject) || (d is JArray)){
429+
if (d is JObject || d is JArray || d is null){
428430
break;
429431
}
430-
if(count == 0){
432+
if (count == 0){
431433
currType = d.GetType();
432-
} else if(!currType.Equals(d.GetType())){
434+
} else if (currType != d.GetType()){
433435
break;
434436
}
435437
count++;
@@ -439,7 +441,7 @@ private object deserializeToDictionary(string jo, bool isArray=false)
439441
currType = d.GetType();
440442
}
441443
#if (ENABLE_PUBNUB_LOGGING)
442-
pnUnityBase.PNLog.WriteToLog (string.Format("whatType {0}", whatType), PNLoggingMethod.LevelInfo);
444+
pnUnityBase.PNLog.WriteToLog ($"whatType {whatType}", PNLoggingMethod.LevelInfo);
443445
#endif
444446

445447
Type listType = typeof(List<>).MakeGenericType(new [] { whatType } );
@@ -448,32 +450,32 @@ private object deserializeToDictionary(string jo, bool isArray=false)
448450
foreach (var d in values)
449451
{
450452
#if (ENABLE_PUBNUB_LOGGING)
451-
pnUnityBase.PNLog.WriteToLog (string.Format("d.GetType() {0}", d.GetType()), PNLoggingMethod.LevelInfo);
453+
pnUnityBase.PNLog.WriteToLog ($"d.GetType() {d?.GetType()}", PNLoggingMethod.LevelInfo);
452454
#endif
453455
if (d is JObject)
454456
{
455457
#if (ENABLE_PUBNUB_LOGGING)
456-
pnUnityBase.PNLog.WriteToLog (string.Format("1: d {0}", d), PNLoggingMethod.LevelInfo);
458+
pnUnityBase.PNLog.WriteToLog ($"1: d {d}", PNLoggingMethod.LevelInfo);
457459
#endif
458460
values2.Add(deserializeToDictionary(d.ToString()));
459461
}
460462
else if (d is JArray)
461463
{
462464
#if (ENABLE_PUBNUB_LOGGING)
463-
pnUnityBase.PNLog.WriteToLog (string.Format("2: d {0}", d), PNLoggingMethod.LevelInfo);
465+
pnUnityBase.PNLog.WriteToLog ($"2: d {d}", PNLoggingMethod.LevelInfo);
464466
#endif
465467
values2.Add(deserializeToDictionary(d.ToString(), true));
466468
}
467469
else
468470
{
469471
#if (ENABLE_PUBNUB_LOGGING)
470-
pnUnityBase.PNLog.WriteToLog (string.Format("3: d {0}", d), PNLoggingMethod.LevelInfo);
472+
pnUnityBase.PNLog.WriteToLog ($"3: d {d}", PNLoggingMethod.LevelInfo);
471473
#endif
472474
values2.Add(d);
473475
}
474476
}
475477
#if (ENABLE_PUBNUB_LOGGING)
476-
pnUnityBase.PNLog.WriteToLog (string.Format("values2.GetType() {0}", values2.GetType()), PNLoggingMethod.LevelInfo);
478+
pnUnityBase.PNLog.WriteToLog ($"values2.GetType() {values2.GetType()}", PNLoggingMethod.LevelInfo);
477479
#endif
478480
return ListExtensions.ConvertToDynamicArray(values2, whatType, pnUnityBase);
479481
}

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ You will need the publish and subscribe keys to authenticate your app. Get your
1212

1313
## Configure PubNub
1414

15-
1. Download the PubNub Unity package from [this repository](https://github.com/pubnub/unity/releases/download/v6.0.8/PubNub.unitypackage).
15+
1. Download the PubNub Unity package from [this repository](https://github.com/pubnub/unity/releases/download/v6.0.9/PubNub.unitypackage).
1616

1717
2. Import the package to your Unity project by going to Assets > Import Package > Custom Package.
1818

VERSION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
6.0.8
1+
6.0.9

0 commit comments

Comments
 (0)