Skip to content

Does polymorphic serde work in System.Text.Json with source generation? #115218

Answered by elgonzo
aries-zhang asked this question in Q&A
Discussion options

You must be logged in to vote

I have never tried/seen "sneaking" a reflection-based resolver (DefaultJsonTypeInfoResolver is reflection-based) into the source-generated resolver (your JsonSerializerContext-derived class is the source-gen-based resolver). I wouldn't be surprised if the source-gen resolver simply ignores the TypeInfoResolver set in the options provided for its constructor and uses the JsonTypeInfos it itself produces, but i don't know.

However, i would suggest a different approach. I am not 100% sure if what i describe below is sufficient for making it work for AoT, or whether there are further pitfalls i didn't consider. But anyways, on with the show...

Instead of attempting to fall back onto a reflect…

Replies: 2 comments 1 reply

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
1 reply
@aries-zhang
Comment options

Answer selected by aries-zhang
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants