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
- URP Realtime reflection probes do not update when RenderProbe() is being called once per second
- Addressable terrain shader variants are stripped from the Player
- [iOS] Debug.Log() appears as <private> in Console app
- UI stays in the background when it is disabled in simulator
- A wrong log file is attached when project is launched with a "-logFile" command line argument
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.