Search Issue Tracker
By Design
Votes
3
Found in
2019.4
2020.3
2020.3.14f1
2021.1
2021.2
2022.1
Issue ID
1361946
Regression
No
JsonUtility.ToJson() doesn't serialize supertypes when generic base type is specified
How to reproduce:
1. Open the user's attached project
2. Open scene Scenes/SampleScene
3. Press the Play button
4. Observe the Console
Expected result: the two logged lines both output two data fields: {"first":"hello","second":"world"}
Actual result: the second logged line outputs only the first field: {"data":{"first":"hello"}}
Reproducible with: 2019.4.30f1, 2020.3.18f1, 2021.1.22f1, 2021.2.0b12, 2022.1.0a9
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
- “[Worker0] Could not generate preview image“ error when opening macOS native plugin in the Inspector with Architecture to build for set to ARM 64-bit
- [iOS] Application.absoluteURL is empty on Awake/Start when opening via deep link with Splash Screen disabled
- Crash on MemoryManager::Deallocate when rapidly calling Addressables.LoadAssetAsync
- Crash on physx::shdfnd::atomicIncrement when adjusting values on a character controller component after entering Play mode in Prefab edit mode
- [Rendering Debugger] [NewInputSystem] Debug Overlays in Play mode throws InvalidOperationException when using New Input System
Resolution Note:
Unity serialization system will fetch the fields from the class of the object being passed in to gather what is being serialized. In this case the class is Data<MyData> the field type of the generic inflated type is MyData rather than InheritedData which will lead to the result you are observing which is expected and deterministic.