Skip to content

Commit 6d5ef33

Browse files
author
Amir Arayeshi
committed
Adding json settings
1 parent 839198d commit 6d5ef33

File tree

3 files changed

+23
-3
lines changed

3 files changed

+23
-3
lines changed

AnyCache.Redis/AnyCache.Redis.csproj

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,9 @@
1111
<PackageTags>Cache, dotnet, dotnetcore, Xamarin, Redis</PackageTags>
1212
<Description>AnyCache .Net and .Net Core Redis caching provider.</Description>
1313
<Copyright>2018 InfoTechbridge</Copyright>
14+
<AssemblyVersion>1.0.0.0</AssemblyVersion>
15+
<FileVersion>1.0.0.0</FileVersion>
16+
<Version>1.0.1</Version>
1417
</PropertyGroup>
1518

1619
<!-- common NuGet package refs that affect all projects -->

AnyCache.Serialization/AnyCache.Serialization.csproj

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,9 @@
1111
<PackageTags>Cache, dotnet, dotnetcore, Xamarin, Serialization</PackageTags>
1212
<Description>AnyCache .Net and .Net Core caching serialization.</Description>
1313
<Copyright>2018 InfoTechbridge</Copyright>
14+
<AssemblyVersion>1.0.0.0</AssemblyVersion>
15+
<FileVersion>1.0.0.0</FileVersion>
16+
<Version>1.0.1</Version>
1417
</PropertyGroup>
1518

1619
<!-- common NuGet package refs that affect all projects -->

AnyCache.Serialization/JsonSerializer.cs

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,28 +46,42 @@ public JsonSerializer(Encoding encoding = null, bool serializeTypeName = false)
4646

4747
public void Serialize(object value, Stream stream)
4848
{
49+
var settings = new JsonSerializerSettings()
50+
{
51+
TypeNameHandling = TypeNameHandling.Auto,
52+
NullValueHandling = NullValueHandling.Ignore,
53+
Formatting = Formatting.Indented,
54+
};
55+
settings.Converters.Add(new Newtonsoft.Json.Converters.JavaScriptDateTimeConverter());
56+
4957
using (StreamWriter sw = new StreamWriter(stream, encoding))
5058
{
5159
if (SerializeTypeName)
5260
sw.WriteLine(value.GetType().AssemblyQualifiedName);
5361

54-
sw.Write(JsonConvert.SerializeObject(value));
62+
sw.Write(JsonConvert.SerializeObject(value, settings));
5563
}
5664
}
5765

5866
public object Deserialize(Stream stream)
5967
{
68+
var settings = new JsonSerializerSettings()
69+
{
70+
TypeNameHandling = TypeNameHandling.Auto,
71+
NullValueHandling = NullValueHandling.Ignore,
72+
};
73+
6074
using (StreamReader sr = new StreamReader(stream, encoding))
6175
{
6276
if (SerializeTypeName)
6377
{
6478
string className = sr.ReadLine();
6579
Type objectType = Util.GetType(className);
6680

67-
return JsonConvert.DeserializeObject(sr.ReadToEnd(), objectType);
81+
return JsonConvert.DeserializeObject(sr.ReadToEnd(), objectType, settings);
6882
}
6983
else
70-
return JsonConvert.DeserializeObject(sr.ReadToEnd());
84+
return JsonConvert.DeserializeObject(sr.ReadToEnd(), settings);
7185
}
7286
}
7387

0 commit comments

Comments
 (0)