using Newtonsoft.Json;
|
using System;
|
using System.Collections.Generic;
|
using System.Linq;
|
using System.Text;
|
using System.Threading.Tasks;
|
|
namespace FlexJobApi.Core
|
{
|
public class EmptyStringToNullConverter : JsonConverter
|
{
|
public override bool CanConvert(Type objectType)
|
{
|
return objectType == typeof(string);
|
}
|
|
public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer)
|
{
|
var value = (string)reader.Value;
|
return string.IsNullOrEmpty(value) ? null : value;
|
}
|
|
public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer)
|
{
|
writer.WriteValue(value);
|
}
|
}
|
}
|