123456789101112131415161718192021222324252627282930 |
- using System.IO;
- using Luticate2.Auth.Business.Fields;
- using Luticate2.Auth.Dbo.Fields;
- using Newtonsoft.Json;
-
- namespace Luticate2.Auth.Business.Serializers.PartialJson
- {
- public class LuPartialJsonWriter
- {
- public static string SerializeObject(object data, LuPartialFieldsDbo partialResponseDbo, JsonSerializerSettings settings)
- {
- var stringWriter = new StringWriter();
- SerializeObject(data, partialResponseDbo, settings, stringWriter);
- var result = stringWriter.ToString();
- return result;
- }
-
- public static void SerializeObject(object data, LuPartialFieldsDbo partialResponseDbo, JsonSerializerSettings settings, TextWriter writer)
- {
- using (var jsonWriter = new JsonTextWriter(writer))
- {
- jsonWriter.CloseOutput = false;
-
- var jsonSerializer = JsonSerializer.Create(settings);
-
- jsonSerializer.Serialize(jsonWriter, data, path => partialResponseDbo.Fields.IsIncluded(path));
- }
- }
- }
- }
|