Open
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
- Define `record StreamersData( [property: JsonProperty( "broadcaster_login" )] string ID, [property: JsonProperty( "display_name" )] string Name );
- and
record Streamers( [property: JsonProperty( "data" )] StreamersData[] Data );
- 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 );
- call
GetStreamers
- result contains the streamers' ids instead of the broadcaster_logins
- rename
string ID
tostring 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