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

Add possibility to serialize objects as JSON with indentation #401

Closed
henrikfroehling opened this issue Jan 25, 2023 · 0 comments · Fixed by #431
Closed

Add possibility to serialize objects as JSON with indentation #401

henrikfroehling opened this issue Jan 25, 2023 · 0 comments · Fixed by #431

Comments

@henrikfroehling
Copy link
Owner

henrikfroehling commented Jan 25, 2023

The output of

ITraktShow show = ...; // Show: The Last of Us
string json = await TraktSerializationService.SerializeAsync(show);
Console.WriteLine(json);

looks like this:

{"title":"The Last of Us","year":2023,"ids":{"trakt":158947,"slug":"the-last-of-us","tvdb":392256,"imdb":"tt3581920","tmdb":100088}}

TraktSerializationService.SerializeAsync() should get an optional boolean parameter indentation, which indents the JSON output like this:

{
    "title":"The Last of Us",
    "year":2023,
    "ids":
    {
        "trakt":158947,
        "slug":"the-last-of-us",
        "tvdb":392256,
        "imdb":"tt3581920",
        "tmdb":100088
    }
}

API Change:

namespace TraktNet.Services
{
+    public static Task<string> SerializeAsync(ITraktAuthorization authorization, bool indentation, CancellationToken cancellationToken = default);

+    public static Task<string> SerializeAsync<TObjectType>(TObjectType obj, bool indentation, CancellationToken cancellationToken = default);

+    public static Task<string> SerializeCollectionAsync<TObjectType>(IEnumerable<TObjectType> objects, bool indentation, CancellationToken cancellationToken = default);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment