Skip to content
Discussion options

You must be logged in to vote

System.Text.Json solution:

var options = new JsonSerializerOptions
{
    Converters = {
        new CollectionObjectConverterFactory(
            defaultItemsName: "$Items",
            typeItemsNameMap: new Dictionary<Type, string>
            {
                { typeof(TrackList), "$Tracks" },
                { typeof(Track), "$Clips" }
            }
        )
    },
    WriteIndented = true
};
#region Factory

/// <summary>
/// A JsonConverterFactory that creates converters for collection types (classes implementing IEnumerable with a generic element type).
/// The converter serializes the collection as a JSON object containing all public properties plus a special property (configurabl…

Replies: 4 comments

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Answer selected by CodingOctocat
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
1 participant