Skip to content

Commit ccd53d7

Browse files
committed
update info response model
1 parent 5b79f4b commit ccd53d7

File tree

2 files changed

+62
-8
lines changed

2 files changed

+62
-8
lines changed

DotNut/ApiModels/GetInfoResponse.cs

+42-8
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,52 @@
11
using System.Text.Json;
22
using System.Text.Json.Serialization;
3+
using DotNut.JsonConverters;
34

45
namespace DotNut.ApiModels;
56

67
public class GetInfoResponse
78
{
8-
[JsonPropertyName("name")] public string Name { get; set; }
9-
[JsonPropertyName("pubkey")] public string Pubkey { get; set; }
10-
[JsonPropertyName("version")] public string Version { get; set; }
11-
[JsonPropertyName("description")] public string Description { get; set; }
12-
[JsonPropertyName("description_long")] public string DescriptionLong { get; set; }
13-
[JsonPropertyName("contact")] public List<ContactInfo> Contact { get; set; }
14-
[JsonPropertyName("motd")] public string Motd { get; set; }
15-
[JsonPropertyName("nuts")] public Dictionary<string, JsonDocument> Nuts { get; set; }
9+
[JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingDefault)]
10+
[JsonPropertyName("name")]
11+
public string? Name { get; set; }
12+
13+
[JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingDefault)]
14+
[JsonPropertyName("pubkey")]
15+
public string? Pubkey { get; set; }
16+
17+
[JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingDefault)]
18+
[JsonPropertyName("version")]
19+
public string? Version { get; set; }
20+
21+
[JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingDefault)]
22+
[JsonPropertyName("description")]
23+
public string? Description { get; set; }
24+
25+
[JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingDefault)]
26+
[JsonPropertyName("description_long")]
27+
public string? DescriptionLong { get; set; }
28+
29+
[JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingDefault)]
30+
[JsonPropertyName("contact")]
31+
public List<ContactInfo>? Contact { get; set; }
32+
33+
[JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingDefault)]
34+
[JsonPropertyName("motd")]
35+
public string? Motd { get; set; }
36+
37+
38+
[JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingDefault)]
39+
[JsonPropertyName("icon_url")]
40+
public string? IconUrl { get; set; }
41+
42+
[JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingDefault)]
43+
[JsonConverter(typeof(UnixDateTimeOffsetConverter))]
44+
[JsonPropertyName("time")]
45+
public DateTimeOffset? Time { get; set; }
46+
47+
[JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingDefault)]
48+
[JsonPropertyName("nuts")]
49+
public Dictionary<string, JsonDocument>? Nuts { get; set; }
1650
}
1751

1852
public class ContactInfo
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
using System.Text.Json;
2+
using System.Text.Json.Serialization;
3+
4+
namespace DotNut.JsonConverters;
5+
6+
public class UnixDateTimeOffsetConverter : JsonConverter<DateTimeOffset>
7+
{
8+
public override DateTimeOffset Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options)
9+
{
10+
var val = reader.TokenType == JsonTokenType.Number? reader.GetInt64() : long.Parse(reader.GetString()!);
11+
12+
13+
return DateTimeOffset.FromUnixTimeSeconds(val);
14+
}
15+
16+
public override void Write(Utf8JsonWriter writer, DateTimeOffset value, JsonSerializerOptions options)
17+
{
18+
writer.WriteNumberValue(value.ToUnixTimeSeconds());
19+
}
20+
}

0 commit comments

Comments
 (0)