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

Scripting

-

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

  1. Response avatar

    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.

Add comment

Log in to post comment

All about bugs

View bugs we have successfully reproduced, and vote for the bugs you want to see fixed most urgently.