[BUG]: Deserializing `https://api.github.com/repos/{owner}/{repository}` to `Octokit.Webhooks.Models.Repository` will throw
OoLunar opened this issue ยท 3 comments
What happened?
When attempting to deserialize a successful rest request response from https://api.github.com/repos/{owner}/{repository}
to Octokit.Webhooks.Models.Repository
, STJ will throw the following exception:
System.Text.Json.JsonException: The JSON value could not be converted to System.String. Path: $.organization | LineNumber: 0 | BytePositionInLine: 5592.
---> System.InvalidOperationException: Cannot get the value of a token type 'StartObject' as a string.
at System.Text.Json.ThrowHelper.ThrowInvalidOperationException_ExpectedString(JsonTokenType tokenType)
at System.Text.Json.Utf8JsonReader.GetString()
at System.Text.Json.Serialization.Metadata.JsonPropertyInfo`1.ReadJsonAndSetMember(Object obj, ReadStack& state, Utf8JsonReader& reader)
at System.Text.Json.Serialization.Converters.ObjectDefaultConverter`1.OnTryRead(Utf8JsonReader& reader, Type typeToConvert, JsonSerializerOptions options, ReadStack& state, T& value)
at System.Text.Json.Serialization.JsonConverter`1.TryRead(Utf8JsonReader& reader, Type typeToConvert, JsonSerializerOptions options, ReadStack& state, T& value, Boolean& isPopulatedValue)
at System.Text.Json.Serialization.JsonConverter`1.ReadCore(Utf8JsonReader& reader, JsonSerializerOptions options, ReadStack& state)
--- End of inner exception stack trace ---
at System.Text.Json.ThrowHelper.ReThrowWithPath(ReadStack& state, Utf8JsonReader& reader, Exception ex)
at System.Text.Json.Serialization.JsonConverter`1.ReadCore(Utf8JsonReader& reader, JsonSerializerOptions options, ReadStack& state)
at System.Text.Json.Serialization.Metadata.JsonTypeInfo`1.ContinueDeserialize(ReadBufferState& bufferState, JsonReaderState& jsonReaderState, ReadStack& readStack)
at System.Text.Json.Serialization.Metadata.JsonTypeInfo`1.DeserializeAsync(Stream utf8Json, CancellationToken cancellationToken)
at System.Net.Http.Json.HttpContentJsonExtensions.ReadFromJsonAsyncCore[T](HttpContent content, JsonSerializerOptions options, CancellationToken cancellationToken)
I suspect this is because Octokit.Webhooks.Models.Repository
should be of type Octokit.Webhooks.Models.Organization
instead of a string
. When reproducing, ensure the repository you're calling the route on belongs to an organization, not a user.
Versions
- Dotnet SDK:
8.0.302
Octokit.Webhooks
NuGet package:2.2.2
Relevant log output
No response
Code of Conduct
- I agree to follow this project's Code of Conduct
๐ Hi! Thank you for this contribution! Just to let you know, our GitHub SDK team does a round of issue and PR reviews twice a week, every Monday and Friday! We have a process in place for prioritizing and responding to your input. Because you are a part of this community please feel free to comment, add to, or pick up any issues/PRs that are labeled with Status: Up for grabs
. You & others like you are the reason all of this works! So thank you & happy coding! ๐
When attempting to deserialize a successful rest request response from
https://api.github.com/repos/{owner}/{repository}
toOctokit.Webhooks.Models.Repository
This library isn't designed to deserialize REST API Responses. I think you might be looking for https://github.com/octokit/octokit.net
@OoLunar I'm closing this for now, as I don't believe this library is the correct one for what you're doing. Please leave a comment if I've misunderstood and I can re-open the issue.