Skip to content

[Bug]: Missing type discriminator when using JsonDerivedType #1959

@Rick-van-Dam

Description

@Rick-van-Dam

Describe the bug 🐞

I ran into this error:

The JSON payload for polymorphic interface or abstract type 'CleanAspCore.Api.Endpoints.Weapons.CreateWeaponRequest' must specify a type discriminator. Path: $ | LineNumber: 0 | BytePositionInLine: 10

It seems refit is not taking into account JsonDerivedType. I assume because its not using the base type that contains those attributes.

Step to reproduce

  1. Use json serialization with derived classes: https://learn.microsoft.com/en-us/dotnet/standard/serialization/system-text-json/polymorphism
  2. Send a request
  3. Notice the type discriminator property is missing which causes problems when deserializing

Reproduction repository

https://github.com/reactiveui/refit

Expected behavior

The type disriminator is included in the json payload

Screenshots 🖼️

No response

IDE

Rider

Operating system

Windows

Version

11

Device

PC

Refit Version

8.0.0

Additional information ℹ️

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions