mirror of https://github.com/Squidex/squidex.git
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
42 lines
1.5 KiB
42 lines
1.5 KiB
// ==========================================================================
|
|
// 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<AppClients>
|
|
{
|
|
protected override void WriteValue(JsonWriter writer, AppClients value, JsonSerializer serializer)
|
|
{
|
|
var json = new Dictionary<string, JsonAppClient>(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<Dictionary<string, JsonAppClient>>(reader);
|
|
|
|
return new AppClients(json.Select(Convert).ToArray());
|
|
}
|
|
|
|
private static KeyValuePair<string, AppClient> Convert(KeyValuePair<string, JsonAppClient> kvp)
|
|
{
|
|
return new KeyValuePair<string, AppClient>(kvp.Key, kvp.Value.ToClient());
|
|
}
|
|
}
|
|
}
|
|
|