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
- Articulation Body with 'Revolute' Joint Type has erratic behavior when Upper Limit is set to above 360
- WebGL Player fails to render Scene when Terrain with Detail Mesh is added and WebGPU Graphics API is used
- Inconsistent errors are logged when different types are passed into the Query "Q<>" method in UIToolkit and the ancestor VisualElement is null
- Crash on GetMaterialPropertyByIndex when opening a specific Scene
- Discrepancies in the styling are present when using a TSS file instead of a USS file in custom EditorWindow
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.