Skip to content

Creating new JsonSerializerOptions every serialization #103824

Answered by elgonzo
DavidM29 asked this question in Q&A
Discussion options

You must be logged in to vote

I believe you should be able to achieve this by using a modifier method for JsonTypeInfo's generated by the JsonTypeInfoResolver. A resolver with such a modifier method can be derived from the used JsonTypeInfoResolver (whether it's the default reflection-based resolver or one generated by the STJ source generator) using the WithAddedModifier extension method.

JsonTypeInfo instances representing types that will be serialized as json objects (i assume the types you are interested in are) possess a list of JsonPropertyInfo instances representing serializable properties. JsonPropertyInfo has an optional ShouldSerialize predicate delegate, which allows you to assign a method/function to contr…

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@DavidM29
Comment options

Answer selected by DavidM29
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