Skip to content
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

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

Open
Haukinger opened this issue Nov 2, 2024 · 0 comments
Labels

Comments

@Haukinger
Copy link

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

@Haukinger Haukinger added the bug label Nov 2, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant