Guest User

Untitled

a guest
Feb 21st, 2018
55
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.39 KB | None | 0 0
  1. using System.Reflection;
  2. using Newtonsoft.Json;
  3. using Newtonsoft.Json.Serialization;
  4.  
  5. namespace Project.Infra.Serialization.Services
  6. {
  7. public class JsonSerializationService<T> : IJsonSerializationService<T>
  8. {
  9. public T Deserialize(string content)
  10. {
  11. return JsonConvert.DeserializeObject<T>(content,
  12. new JsonSerializerSettings
  13. {
  14. ContractResolver = new AllPropertiesResolver()
  15. });
  16. }
  17.  
  18. public string Serialize(T entity)
  19. {
  20. return JsonConvert.SerializeObject(entity,
  21. new JsonSerializerSettings
  22. {
  23. ContractResolver = new AllPropertiesResolver()
  24. });
  25. }
  26.  
  27. public string Serialize<T1>(T entity)
  28. {
  29. return JsonConvert.SerializeObject(entity,
  30. new JsonSerializerSettings
  31. {
  32. ContractResolver = new AllPropertiesResolver()
  33. });
  34. }
  35. }
  36.  
  37. internal class AllPropertiesResolver : DefaultContractResolver
  38. {
  39. protected override JsonProperty CreateProperty(MemberInfo member, MemberSerialization memberSerialization)
  40. {
  41. var property = base.CreateProperty(member, memberSerialization);
  42.  
  43. property.Ignored = false;
  44.  
  45. return property;
  46. }
  47. }
  48. }
Add Comment
Please, Sign In to add comment