C
C#16mo ago
devhl

❔ Can't share JsonSerializerOptions with several SerializerContext

From this SO I see that you can't share options with multiple contexts. This is what I am observing. To work around this limitation, when I construct my context with a copy of the options. This seems like the wrong thing to do, so I am looking for input from the community. The reason I am using multiple contexts is when I tried with only one context, there was a warning about a name conflict. Since what I am talking about here is generated C#, it seemed wise to avoid the warning and just use multiple contexts. Here is the test showing the de/serialization works as I have it. https://github.com/devhl-labs/openapi-generator/blob/f237e51991d5c1c7ef5500bba8ff51ea319f0353/samples/client/petstore/csharp/OpenAPIClient-generichost-manual-tests/OpenAPIClient-generichost-manual-tests/UnitTest1.cs#L49 Here is the context I am using in the above test. https://github.com/devhl-labs/openapi-generator/blob/f237e51991d5c1c7ef5500bba8ff51ea319f0353/samples/client/petstore/csharp/OpenAPIClient-generichost-net6.0-nrt/src/Org.OpenAPITools/Model/Category.cs#L184C18-L184C18 Here is how the host is getting the options and the context. https://github.com/devhl-labs/openapi-generator/blob/f237e51991d5c1c7ef5500bba8ff51ea319f0353/samples/client/petstore/csharp/OpenAPIClient-generichost-net6.0-nrt/src/Org.OpenAPITools/Client/HostConfiguration.cs#L137 Is my approach wrong?
1 Reply
Accord
Accord16mo ago
Looks like nothing has happened here. I will mark this as stale and this post will be archived until there is new activity.
Want results from more Discord servers?
Add your server