-
-
Notifications
You must be signed in to change notification settings - Fork 528
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
JsonInheritanceConverter thread safety #206
Comments
This is bad, I could not find another way to implement the converter... |
We need a fix for that. There are unit tests to check its functionality, so it should be simple to experiment... |
Why is this running in parallel? |
Is the serializer reused? |
It runs in parallel as it speeds up unit and integration tests. But this could happen in other parallel scenarios as well. |
So if you call JsonConvert.SerializeObject then you see these problems? I thought that SerializeObject creates a new serializer to prevent these problems... But it seems that it reuses the serializer internally... My problem: I could not find a way to implement the converter without setting the Converter to null... |
I think this is the problem: http://stackoverflow.com/questions/33557737/does-json-net-cache-types-serialization-information But creating a new resolver each time is not an option because it would degrade the performance dramatically... |
Ill try something with thread local... But i have to find a solution to reproduce your problem in a unit test first... |
I see. Yes, I also was not able to find a solution that works. I tried to implement a workaround by defining a property on the base class with the name of the discriminator:
This works for Serialize/Deserialize the data, but when i try to build the swagger.json I get an exception as the field is defined multiple times. Thanks for your help. |
The "defined multiple times" problem can easily be fixed... |
I think I have found a solution... |
Also updated in NSwag: RicoSuter/NSwag@a47fca7 |
Check out NJsonSchema v4.18. Is this working for you? |
Hey, thank you. I extended the Tests here: With the new approach all child elements are deserialized to the base class. The JsonInheritanceConverter seems to gets called recursively and is disabled on the child elements. |
Ok, next workaround :-), now it should work as expected: |
v4.19 |
That helped. |
Hi
Thanks for providing such a nice Swagger/JsonSchema implementation including discriminator support.
I tried to implemented this in a Project. Unfortunately the JsonInheritanceConverter seems not to be thread safe. In Unit Tests I get random exceptions as the discriminator field is not present in the written Json.
Setting the contract.Converter = null; in WriteJson() seems to cause that issue.
Has anyone solved this?
Thanks
Urs
The text was updated successfully, but these errors were encountered: