You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 

37 lines
1.1 KiB

using System;
using System.Text.Json;
using System.Text.Json.Serialization;
namespace Znyc.Cloudcar.Admin.Commons.Helpers
{
/// <summary>
/// </summary>
public class BooleanJsonConverter : JsonConverter<bool>
{
/// <summary>
/// </summary>
/// <param name="reader"></param>
/// <param name="typeToConvert"></param>
/// <param name="options"></param>
/// <returns></returns>
public override bool Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options)
{
if (reader.TokenType == JsonTokenType.True || reader.TokenType == JsonTokenType.False)
{
return reader.GetBoolean();
}
return bool.Parse(reader.GetString());
}
/// <summary>
/// </summary>
/// <param name="writer"></param>
/// <param name="value"></param>
/// <param name="options"></param>
public override void Write(Utf8JsonWriter writer, bool value, JsonSerializerOptions options)
{
writer.WriteBooleanValue(value);
}
}
}