Skip to content

Commit 63ffaae

Browse files
author
kajan
committed
add ToJson extension method
1 parent 7f611f0 commit 63ffaae

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
using Newtonsoft.Json;
2+
using Newtonsoft.Json.Serialization;
3+
4+
namespace AspNetCoreVueMpa.Web.Utils
5+
{
6+
public static class ObjectExtensions
7+
{
8+
public static string ToJson(this object obj)
9+
{
10+
var settings = new JsonSerializerSettings
11+
{
12+
ContractResolver = new CamelCasePropertyNamesContractResolver(),
13+
NullValueHandling = NullValueHandling.Ignore,
14+
ReferenceLoopHandling = ReferenceLoopHandling.Ignore
15+
};
16+
return JsonConvert.SerializeObject(obj, settings);
17+
}
18+
}
19+
}

0 commit comments

Comments
 (0)