1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
| using System.Text.Json;
| using System.Text.Json.Serialization;
|
| namespace Yw.WebApi
| {
| /// <summary>
| ///
| /// </summary>
| public class LongJsonConverter : JsonConverter<long>
| {
| /// <summary>
| ///
| /// </summary>
| public override long Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options)
| {
| if (reader.TokenType == JsonTokenType.Number)
| {
| return reader.GetInt64();
| }
| return long.Parse(reader.GetString());
| }
|
| /// <summary>
| ///
| /// </summary>
| public override void Write(Utf8JsonWriter writer, long value, JsonSerializerOptions options)
| {
| writer.WriteStringValue(value.ToString());
| }
| }
| }
|
|