Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System.Reflection;
- using Newtonsoft.Json;
- using Newtonsoft.Json.Serialization;
- namespace Project.Infra.Serialization.Services
- {
- public class JsonSerializationService<T> : IJsonSerializationService<T>
- {
- public T Deserialize(string content)
- {
- return JsonConvert.DeserializeObject<T>(content,
- new JsonSerializerSettings
- {
- ContractResolver = new AllPropertiesResolver()
- });
- }
- public string Serialize(T entity)
- {
- return JsonConvert.SerializeObject(entity,
- new JsonSerializerSettings
- {
- ContractResolver = new AllPropertiesResolver()
- });
- }
- public string Serialize<T1>(T entity)
- {
- return JsonConvert.SerializeObject(entity,
- new JsonSerializerSettings
- {
- ContractResolver = new AllPropertiesResolver()
- });
- }
- }
- internal class AllPropertiesResolver : DefaultContractResolver
- {
- protected override JsonProperty CreateProperty(MemberInfo member, MemberSerialization memberSerialization)
- {
- var property = base.CreateProperty(member, memberSerialization);
- property.Ignored = false;
- return property;
- }
- }
- }
Add Comment
Please, Sign In to add comment