C
C#5w ago
Mr. Dink

STJ Polymorphic Serialization in Source Gen mode

I trying to remain AOT compatible for my library. I have a class that users can inherit from, so I'm unable to add the derived type attributes to the base type directly. I'm able to have the user register their custom types all in one place using a static method, and internally use a Modifier to add them to the list of derived types for that JsonTypeInfo. This works for reflection-based DefaultJsonTypeInfoResolver, but no matter what I do, the delegate passed into WithAddedModifier() is never called if I use the source gen context and it just errors. Is there a way to add these in source gen mode? Here's a gist: https://gist.github.com/markdibarry/354e2b9ed387e9b2f94088d2ad00c496
Gist
Polymorphic serialization with Source Gen
Polymorphic serialization with Source Gen. GitHub Gist: instantly share code, notes, and snippets.
1 Reply
Mr. Dink
Mr. DinkOP4w ago
Unfortunately, it seems it's just not supported at the moment. https://github.com/dotnet/runtime/discussions/115303
GitHub
System.Text.Json AOT Polymorphic serialization · dotnet runtime ·...
Description I'm making an AOT compatible library. This library contains a base type that users inherit from for their own custom classes. This type needs serialized, but considering the base ty...

Did you find this page helpful?