// ========================================================================== // Squidex Headless CMS // ========================================================================== // Copyright (c) Squidex UG (haftungsbeschränkt) // All rights reserved. Licensed under the MIT license. // ========================================================================== using System; using System.Collections.Generic; using System.Linq; using Newtonsoft.Json; using Squidex.Infrastructure.Json.Newtonsoft; namespace Squidex.Domain.Apps.Core.Apps.Json { public sealed class AppClientsConverter : JsonClassConverter { protected override void WriteValue(JsonWriter writer, AppClients value, JsonSerializer serializer) { var json = new Dictionary(value.Count); foreach (var client in value) { json.Add(client.Key, new JsonAppClient(client.Value)); } serializer.Serialize(writer, json); } protected override AppClients ReadValue(JsonReader reader, Type objectType, JsonSerializer serializer) { var json = serializer.Deserialize>(reader); return new AppClients(json.Select(Convert).ToArray()); } private static KeyValuePair Convert(KeyValuePair kvp) { return new KeyValuePair(kvp.Key, kvp.Value.ToClient()); } } }