question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Discriminator value and expected deserialization value do not match

See original GitHub issue

Describe the bug I may be doing this wrong, it looks like deserialization is using the component schema name instead of the discriminator name when generating the client (validated with C# and TypeScript) for string discriminators.

If I have a discriminator like this:

"discriminator": {
          "propertyName": "type",
          "mapping": {
            "AccountCreatedV1": "#/components/schemas/AccountCreatedV1EventResponse",
            "AccountDeletedV1": "#/components/schemas/AccountDeletedV1EventResponse",
            "AccountUpdatedV1": "#/components/schemas/AccountUpdatedV1EventResponse"
          }
        }

The serialization code for C# looks like this

internal static EventResponseV1 DeserializeEventResponseV1(JsonElement element)
        {
            if (element.TryGetProperty("type", out JsonElement discriminator))
            {
                switch (discriminator.GetString())
                {
                    case "AccountCreatedV1EventResponse": return AccountCreatedV1EventResponse.DeserializeAccountCreatedV1EventResponse(element);
                    case "AccountDeletedV1EventResponse": return AccountDeletedV1EventResponse.DeserializeAccountDeletedV1EventResponse(element);
                    case "AccountUpdatedV1EventResponse": return AccountUpdatedV1EventResponse.DeserializeAccountUpdatedV1EventResponse(element);
                }
            }

Expected behavior I would expect the switch statement to use the discriminator name specified in the swagger.json

Additional context @autorest/core: 3.1.3 @autorest/csharp: v3.0.0-beta.20210428.4

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:7 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
nascostocommented, Apr 30, 2021

Confirmed. That worked. Thanks again!

1reaction
timotheeguerincommented, Apr 30, 2021

that change involved changing core and modelerfour. Modelerfour version is usually fixed by whatever generator pick, so my guess is it just locked to an older version before this was supported. You can set the version manually and/or file an issue on the autorest.typescript repo for them to update.

--use:@autorest/modelerfour@~4.18.1
Read more comments on GitHub >

github_iconTop Results From Across the Web

c# - MongoDB Unknown discriminator value => deserialize to ...
I'd like to deserialize MyProperty to a simple generic BsonDocument or to a string.
Read more >
The error is: The discriminator field name "type" for base-class ...
Hi, i have a problem with @Discriminator for abstract class. For example, this structure of classes don't work correctly when I try to...
Read more >
Migrate from Newtonsoft.Json to System.Text.Json - .NET
Learn how to migrate from Newtonsoft.Json to System.Text.Json. Includes sample code.
Read more >
Inheritance in Jackson | Baeldung
This tutorial will demonstrate how to handle inclusion of subtype metadata and ignoring properties inherited from superclasses with Jackson.
Read more >
24 JBO-24000 to JBO-80008 - Oracle Help Center
Cause: The database value does not match the cached value for this entity object. This could happen when another user or operation has...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found