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
- Unity CIL Linker fails on Player build when persistent listeners have "<" and ">" in their XML attribute names
- ”Lighting data asset ‘LightingData’ is incompatible with the current Unity version…” warnings are thrown when saving Indoors (URP) and Outdoors (URP) Scenes as Scene Templates
- [iOS] The screen blinks when transitioning from custom to Unity splash screen
- [macOS] ”Ignoring depth surface load action as it is memoryless” warnings are thrown when taking Game View Snapshot
- UI Builder Inspector scrolls back up when changes on an expanded but not fully displayed Inspector tab are saved
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.