forked from gitter-badger/IdentityServer4
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathObjectSerializer.cs
More file actions
45 lines (37 loc) · 1.31 KB
/
ObjectSerializer.cs
File metadata and controls
45 lines (37 loc) · 1.31 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
// Copyright (c) Brock Allen & Dominick Baier. All rights reserved.
// Licensed under the Apache License, Version 2.0. See LICENSE in the project root for license information.
using IdentityServer4.Infrastructure;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
namespace IdentityServer4
{
internal static class ObjectSerializer
{
private static readonly JsonSerializerSettings Settings = new JsonSerializerSettings
{
DefaultValueHandling = DefaultValueHandling.Ignore,
NullValueHandling = NullValueHandling.Ignore
};
private static readonly JsonSerializer Serializer = new JsonSerializer
{
DefaultValueHandling = DefaultValueHandling.Ignore,
NullValueHandling = NullValueHandling.Ignore
};
static ObjectSerializer()
{
Settings.Converters.Add(new NameValueCollectionConverter());
}
public static string ToString(object o)
{
return JsonConvert.SerializeObject(o, Settings);
}
public static T FromString<T>(string value)
{
return JsonConvert.DeserializeObject<T>(value, Settings);
}
public static JObject ToJObject(object o)
{
return JObject.FromObject(o, Serializer);
}
}
}