This repository has been archived by the owner on Oct 6, 2023. It is now read-only.
Fix Queue/Stack deserializing with IL2CPP #53
Labels
bug:aot
Troubles with Ahead Of Time compilation
enhancement
New feature or request
wontfix
This will not be worked on
Milestone
Description
As found in @felipegodias issue #51, the
Queue<T>
type cannot be deserialized in the IL2CPP runtime if not referencing thenew Queue<T>(IEnumerable<T>)
constructor as Json .NET apparently uses that parameterized constructor for said type.https://github.com/JamesNK/Newtonsoft.Json/blob/12.0.3/Src/Newtonsoft.Json/Serialization/JsonArrayContract.cs#L194-L201
This assumably would also apply to the
Stack<T>
type. Would have to investigate if the non-genericQueue
andStack
also would be fine. Difficult to test non-generic ones as anything that would generate the AOT code will make a test on non-generated AOT code not work properly.Tricky!
Motivation
Possibility to deserialize Queue and Stack on IL2CPP runtime.
Suggested solution
Three possible solutions:
Add ensuring of the constructor in AotHelper, but that does not help with types inheriting from
Queue<T>
as it's not possible to ensure other constructors than the default one generically.Add a custom converter for
Queue<>
andStack<>
types.Modify Json .NET to populate queues and stacks via their
.Enqueue(T item)
and.Push(T item)
methods, respectively. Will have to investigate how this can be done with the least amount of changes to the Json .NET code as possible and distinguishable so I don't accidentally remove the fix later.Nr 2 would be easiest to implement and give the best user experience, except for when users define their own converters. Perhaps hacky to force a converter in there. Which makes option nr 3 the dominating solution, and perhaps the most "best practice"-esque.
The text was updated successfully, but these errors were encountered: