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

ITelevisionApi GetAlternativeTitlesAsync does not deserialize titles collection #27

Closed
tonykaralis opened this issue Aug 2, 2020 · 5 comments · Fixed by #29
Closed
Labels
bug Something isn't working help wanted Extra attention is needed

Comments

@tonykaralis
Copy link
Owner

The data is being returned from the request but not deserialized into the AlternativeTitlesClass.

Reproduce with tvId = 1399.

Where: TelevisionApiTest -> GetAlternativeTitlesAsync_ValidId_ReturnsValidResult

@tonykaralis tonykaralis added the bug Something isn't working label Aug 2, 2020
@tonykaralis tonykaralis added the help wanted Extra attention is needed label Aug 2, 2020
@tonykaralis tonykaralis mentioned this issue Aug 2, 2020
@PoLaKoSz
Copy link
Contributor

PoLaKoSz commented Aug 2, 2020

  • GET tv/1399/alternative_titles
{"id":1399,"results":[]}
  • GET movie/550/alternative_titles
{"id":550,"titles":[]}

Both endpoint deserialized to AlternativeTitle but the collection has different name.

tonykaralis added a commit that referenced this issue Aug 3, 2020
@tonykaralis tonykaralis mentioned this issue Aug 3, 2020
tonykaralis added a commit that referenced this issue Aug 3, 2020
@PoLaKoSz
Copy link
Contributor

PoLaKoSz commented Aug 3, 2020

Maybe to prevent similar issues in the future, it would be beneficial to turn strict json deserialization on (maybe other tests will fail now, or if TMDb devs change something the test cases will fail so we could fix it ASAP).

@tonykaralis
Copy link
Owner Author

tonykaralis commented Aug 3, 2020

That might be a good idea, although how would you handle the 'strict' deserialization? We have this a weird problem here as well #31 which is not related but is similar to #5

@PoLaKoSz
Copy link
Contributor

PoLaKoSz commented Aug 3, 2020

My idea (i didn't prototyped it)

  • set the built-in deserializer strict
  • retrive the custom deserializer(s) from the IJsonDeserializer. This way person with custom deserializer should be able to implement these edge cases that we are facing now
public interface IJsonDeserializer
{
    TmdbEasyModel DeserializeTo<TmdbEasyModel>(string json);

    IChangeListDeserializer ForChangeList();
}

public interface IChangeListDeserializer
{
    Change Deserialize(string json);
}
  • we just need to implement IChangeListDeserializer (in this case) which should deserialize the json manually with Newtonsoft and we have to keep track if there any JToken or JProperty left (if i remember correctly). If yes, then FormatException or something.

The next problem will be how and where to bind the HttpClient.GetStringAsync() response and the deserialization together. I would just move the TmdbEasyClient.GetResponseAsync() content to the RequestHandler class and i would make a second ExecuteAsync method with a second parameter which would be the IChangeListDeserializer:

internal async Task<TmdbEasyModel> ExecuteAsync<TmdbEasyModel>(Request request)
{
    string uri = request.GetUri();

    string json = await _httpClient.GetStringAsync(uri).ConfigureAwait(false);

    return _client.Options.JsonDeserializer.DeserializeTo<TmdbEasyModel>(json);
}

internal async Task<TmdbEasyModel> ExecuteAsync<TmdbEasyModel>(Request request, IChangeListDeserializer deserializer)
{
    string uri = request.GetUri();

    string json = await _httpClient.GetStringAsync(uri).ConfigureAwait(false);

    return deserializer.Deserialize<TmdbEasyModel>(json);
}

@tonykaralis
Copy link
Owner Author

Shall we continue this chat in #31. I like your idea, except for the last bit (moving the httpclient up a layer, it needs to sit in the TmdbEasyClient. Also as we add more Serializers we will end up needing more and more methods. Would be good to find a way to design this so future adding of serializers dont result in code changes to the RequestHandler or TmdbEasy classes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working help wanted Extra attention is needed
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants