Skip to content

[Bug]: JsonProperty attribute ignored in result if property name matches other field #1905

Open
@Haukinger

Description

Describe the bug 🐞

I query a rest api and get a json result containing fields "broadcaster_login" and "id". Those are put into a record with the property "ID" that has a JsonProperty attribute with value broadcaster_login. Refit puts the id field there instead of broadcaster_login. If I name the property "Login", it works fine and I get the expected field.

It might be that refit only looks as the property name attribute if it doesn't find an exact match with the property's name.

Step to reproduce

  1. Define `record StreamersData( [property: JsonProperty( "broadcaster_login" )] string ID, [property: JsonProperty( "display_name" )] string Name );
  2. and record Streamers( [property: JsonProperty( "data" )] StreamersData[] Data );
  3. and [Get( "/helix/search/channels" )] Task<IApiResponse<Streamers?>> GetStreamers( [AliasAs( "query" )] string query, [AliasAs( "live_only" )] bool liveOnly, [AliasAs( "first" )] int count, [Authorize] string token, [Header( "Client-Id" )] string clientId );
  4. call GetStreamers
  5. result contains the streamers' ids instead of the broadcaster_logins
  6. rename string ID to string Login and see the correct result

Reproduction repository

No response

Expected behavior

If a JsonProperty attribute is present for a property, it should take precedence over the property name when matching to json fields if deserializing with the NewtonsoftJsonContentSerializer.

Screenshots 🖼️

No response

IDE

Visual Studio 2022

Operating system

Windows

Version

10

Device

No response

Refit Version

7.2.1

Additional information ℹ️

No response

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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