Search Issue Tracker
By Design
Votes
0
Found in
2021.3.40f1
2022.3.38f1
6000.0.11f1
Issue ID
UUM-76168
Regression
No
The JSON output of an empty array differs when instead of the "new CustomClass[0]" the method "new List<CustomClass>.toArray()" is used
How to reproduce:
1. Open the “SerializationTest“ project
2. Open the “SampleScene“
3. Enter the play mode
4. Observe the Console window
Expected result: The message logged in the Console window is
”Json:
{
"branchA": [],
"branchB": []
}
"
Actual result: The message logged in the Console window is
“Json:
{
"branchA":{
"$id": 0,
"$elements": []
},
"branchB":{
"$ref": 0
}
}"
Reproducible with: 2021.3.40f1, 2022.3.38f1, 6000.0.11f1
Reproducible on: macOS 14.5 (Intel), Windows 10 Pro (22H2)
Not reproducible on: No other environments tested
Workaround: Exchange the “{{{}branchA = new List<BranchClass>().ToArray(){}}}“ method to the {{“branchA = new BranchClass[0]"}}
Note: When converting just a “{{{}branchList = new List<BranchClass>(){}}}“ list to JSON, the output is as expected “ {{"branchList": []}} "
Add comment
All about bugs
View bugs we have successfully reproduced, and vote for the bugs you want to see fixed most urgently.
Latest issues
- Spot Light with 'Box' Shape stops working when it collides with Mesh
- Accepting Asset Store EULA endless loop in Package Manager window
- “InvalidOperationException: Sequence contains no matching element“ error when reenabling a custom Debug Draw Mode
- Prefab that contains a layout group is marked as changed by the Editor when opened
- Emission animation does not appear when the "Emission Map" parameter is set to black in a Lit material
Resolution Note:
The observed bahebviour is a feature of the package you are using to allow tracking multiple instances of the same object.
If this is not desired you can either use `JsonUtility` or refer to the package documentation where there is a setting to control this behaviour `JsonSerializationParameters.DisableSerializedReferences`.
https://docs.unity3d.com/Packages/com.unity.serialization@3.1/api/Unity.Serialization.Json.JsonSerializationParameters.html#Unity_Serialization_Json_JsonSerializationParameters_DisableSerializedReferences
This can be provided to the `ToJson` method as:
var json = JsonSerialization.ToJson(rootClass, new JsonSerializationParameters { DisableSerializedReferences = true } );