S.T.J source-gen reflection fallback and switching from AddContext
to TypeInfoResolver
#74359
-
I just updated System.Text.Json from When upgrading to the latest preview version, I began receiving exceptions for un-annotated root types that I apparently missed that were previously getting picked up by the reflection fallback--so a good thing. Some of our endpoints, however, produce MVC framework types (i.e. After re-reading through some of the issues/PRs in this repo, I changed my setup from this: options.JsonSerializerOptions.AddContext<MyJsonContext>() to this: options.JsonSerializerOptions.TypeInfoResolver = JsonTypeInfoResolver.Combine(MyJsonContext.Default, new DefaultJsonTypeInfoResolver()) This seems to work and fallback to the reflection-based metadata for any types that were not annotated. So my questions:
I tried digging through the code a bit and it seems like the only extra thing that Some of this will eventually be moot as the types I'm having issues with are getting an overhaul in .NET 7. We're using the preview package due to some source-gen and data annotation fixes, but our adoption of .NET 7 won't be immediate. So I wanted to be sure that my understanding is correct and that the implications (if any) are clear. In the limited testing I've done everything seems to be working as expected but just want to be sure |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
That's right.
Not really, it might make sense to request a
That's also true for the case of |
Beta Was this translation helpful? Give feedback.
That's right.
Not really, it might make sense to request a
JsonSerializerContext
exposed by the authors of the inaccessible class and then combine those with your own contexts.That's also true for the case of
TypeInfoResolver
. WhatAddContext
does differently is that it initializes a brand newJsonSerializerContext
…