google / google/play-appbundle-unity

[1.10.0] - Error during deserialization of asset pack settings due to JsonUtility serializing null strings as empty

Open
#3 1 comment 0 reactions 0 assignees View on GitHub
Dominant language
C#
Stars
10
Forks
5
PR merge metrics
No merged PRs in 30d

Description

When deserializing asset pack settings, an error occurs because Unity's built-in `JsonUtility` serializes `null` strings as empty strings (`""`). This leads to unexpected behavior during deserialization, as the code expects `null` values but receives empty strings instead. The issue originates from the following example code snippet:
` var deviceGroupToAssetPackDirectoryPath =`
` pack.paths.Any(path => path.deviceGroup != null)`
` ? pack.paths`
` .ToDictionary(item => item.deviceGroup, item => item.path)`
` : new Dictionary();`

Callstack:
`ArgumentException: An item with the same key has already been added. Key:
System.Collections.Generic.Dictionary`2[TKey,TValue].TryInsert (TKey key, TValue value, System.Collections.Generic.InsertionBehavior behavior) (at :0)
System.Collections.Generic.Dictionary`2[TKey,TValue].Add (TKey key, TValue value) (at :0)
System.Linq.Enumerable.ToDictionary[TSource,TKey,TElement] (System.Collections.Generic.List`1[T] source, System.Func`2[T,TResult] keySelector, System.Func`2[T,TResult] elementSelector, System.Collections.Generic.IEqualityComparer`1[T] comparer) (at <38255ab1a4964f369f4d08660dc32380>:0)
System.Linq.Enumerable.ToDictionary[TSource,TKey,TElement] (System.Collections.Generic.IEnumerable`1[T] source, System.Func`2[T,TResult] keySelector, System.Func`2[T,TResult] elementSelector, System.Collections.Generic.IEqualityComparer`1[T] comparer) (at <38255ab1a4964f369f4d08660dc32380>:0)
System.Linq.Enumerable.ToDictionary[TSource,TKey,TElement] (System.Collections.Generic.IEnumerable`1[T] source, System.Func`2[T,TResult] keySelector, System.Func`2[T,TResult] elementSelector) (at <38255ab1a4964f369f4d08660dc32380>:0)
Google.Android.AppBundle.Editor.Internal.Config.SerializationHelper.Deserialize (Google.Android.AppBundle.Editor.Internal.Config.SerializableAssetPackConfig config) (at ./Library/PackageCache/com.google.android.appbundle@1.10.0/Editor/Scripts/Internal/Config/SerializationHelper.cs:342)
Google.Android.AppBundle.Editor.AssetPacks.AssetPackConfigSerializer.LoadConfig () (at ./Library/PackageCache/com.google.android.appbundle@1.10.0/Editor/Scripts/AssetPackConfigSerializer.cs:52)`

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.