Generated-output differences

quicktype output changed between the PR base and tested PR merge revisions.
← Back to the pull request
1test cases
3files differ
0modified
3new
0deleted
728changed lines
+728 −0insertions / deletions
Base d3014aaec4f7ed11fb83168f39211b755deeeb1d · PR merge eadd66c64a16b38627f6d04a44d0950dc6526a93 · Head e2a1b1785eadbfc2668f37b05931462bc4c82255 · raw patch
Test case

test/inputs/json/misc/31189.json

3 generated files · +728 −0
Acsharp-recordsdefault / QuickType.cs+206 −0
@@ -0,0 +1,206 @@
1+// <auto-generated />
2+//
3+// To parse this JSON data, add NuGet 'Newtonsoft.Json' then do:
4+//
5+// using QuickType;
6+//
7+// var topLevel = TopLevel.FromJson(jsonString);
8+#nullable enable
9+#pragma warning disable CS8618
10+#pragma warning disable CS8601
11+#pragma warning disable CS8602
12+#pragma warning disable CS8603
13+#pragma warning disable CS8604
14+#pragma warning disable CS8625
15+#pragma warning disable CS8765
16+
17+namespace QuickType
18+{
19+ using System;
20+ using System.Collections.Generic;
21+
22+ using System.Globalization;
23+ using Newtonsoft.Json;
24+ using Newtonsoft.Json.Converters;
25+
26+ public partial record TopLevel
27+ {
28+ [JsonProperty("details", Required = Required.Always)]
29+ public Uri Details { get; set; }
30+
31+ [JsonProperty("rates", Required = Required.Always)]
32+ public Rate[] Rates { get; set; }
33+
34+ [JsonProperty("version", Required = Required.AllowNull)]
35+ public object Version { get; set; }
36+ }
37+
38+ public partial record Rate
39+ {
40+ [JsonProperty("code", Required = Required.Always)]
41+ public string Code { get; set; }
42+
43+ [JsonProperty("country_code", Required = Required.Always)]
44+ public string CountryCode { get; set; }
45+
46+ [JsonProperty("name", Required = Required.Always)]
47+ public string Name { get; set; }
48+
49+ [JsonProperty("periods", Required = Required.Always)]
50+ public Period[] Periods { get; set; }
51+ }
52+
53+ public partial record Period
54+ {
55+ [JsonProperty("effective_from", Required = Required.Always)]
56+ public EffectiveFromUnion EffectiveFrom { get; set; }
57+
58+ [JsonProperty("rates", Required = Required.Always)]
59+ public Rates Rates { get; set; }
60+ }
61+
62+ public partial record Rates
63+ {
64+ [JsonProperty("parking", Required = Required.DisallowNull, NullValueHandling = NullValueHandling.Ignore)]
65+ public double? Parking { get; set; }
66+
67+ [JsonProperty("reduced", Required = Required.DisallowNull, NullValueHandling = NullValueHandling.Ignore)]
68+ public double? Reduced { get; set; }
69+
70+ [JsonProperty("reduced1", Required = Required.DisallowNull, NullValueHandling = NullValueHandling.Ignore)]
71+ public double? Reduced1 { get; set; }
72+
73+ [JsonProperty("reduced2", Required = Required.DisallowNull, NullValueHandling = NullValueHandling.Ignore)]
74+ public double? Reduced2 { get; set; }
75+
76+ [JsonProperty("standard", Required = Required.Always)]
77+ public double Standard { get; set; }
78+
79+ [JsonProperty("super_reduced", Required = Required.DisallowNull, NullValueHandling = NullValueHandling.Ignore)]
80+ public double? SuperReduced { get; set; }
81+ }
82+
83+ public enum EffectiveFromEnum { The00000101 };
84+
85+ public partial struct EffectiveFromUnion
86+ {
87+ public DateTimeOffset? DateTime;
88+ public EffectiveFromEnum? Enum;
89+
90+ public static implicit operator EffectiveFromUnion(DateTimeOffset DateTime) => new EffectiveFromUnion { DateTime = DateTime };
91+ public static implicit operator EffectiveFromUnion(EffectiveFromEnum Enum) => new EffectiveFromUnion { Enum = Enum };
92+ }
93+
94+ public partial record TopLevel
95+ {
96+ public static TopLevel FromJson(string json) => JsonConvert.DeserializeObject<TopLevel>(json, QuickType.Converter.Settings);
97+ }
98+
99+ public static partial class Serialize
100+ {
101+ public static string ToJson(this TopLevel self) => JsonConvert.SerializeObject(self, QuickType.Converter.Settings);
102+ }
103+
104+ internal static partial class Converter
105+ {
106+ public static readonly JsonSerializerSettings Settings = new JsonSerializerSettings
107+ {
108+ MetadataPropertyHandling = MetadataPropertyHandling.Ignore,
109+ DateParseHandling = DateParseHandling.None,
110+ Converters =
111+ {
112+ EffectiveFromUnionConverter.Singleton,
113+ EffectiveFromEnumConverter.Singleton,
114+ new IsoDateTimeConverter { DateTimeStyles = DateTimeStyles.AssumeUniversal }
115+ },
116+ };
117+ }
118+
119+ internal class EffectiveFromUnionConverter : JsonConverter
120+ {
121+ public override bool CanConvert(Type t) => t == typeof(EffectiveFromUnion) || t == typeof(EffectiveFromUnion?);
122+
123+ public override object ReadJson(JsonReader reader, Type t, object existingValue, JsonSerializer serializer)
124+ {
125+ switch (reader.TokenType)
126+ {
127+ case JsonToken.String:
128+ case JsonToken.Date:
129+ var stringValue = serializer.Deserialize<string>(reader);
130+ DateTimeOffset dt;
131+ if (DateTimeOffset.TryParse(stringValue, out dt))
132+ {
133+ return new EffectiveFromUnion { DateTime = dt };
134+ }
135+ if (stringValue == "0000-01-01")
136+ {
137+ return new EffectiveFromUnion { Enum = EffectiveFromEnum.The00000101 };
138+ }
139+ break;
140+ }
141+ throw new Exception("Cannot unmarshal type EffectiveFromUnion");
142+ }
143+
144+ public override void WriteJson(JsonWriter writer, object untypedValue, JsonSerializer serializer)
145+ {
146+ var value = (EffectiveFromUnion)untypedValue;
147+ if (value.DateTime != null)
148+ {
149+ serializer.Serialize(writer, value.DateTime.Value.ToString("o", System.Globalization.CultureInfo.InvariantCulture));
150+ return;
151+ }
152+ if (value.Enum != null)
153+ {
154+ if (value.Enum == EffectiveFromEnum.The00000101)
155+ {
156+ serializer.Serialize(writer, "0000-01-01");
157+ return;
158+ }
159+ }
160+ throw new Exception("Cannot marshal type EffectiveFromUnion");
161+ }
162+
163+ public static readonly EffectiveFromUnionConverter Singleton = new EffectiveFromUnionConverter();
164+ }
165+
166+ internal class EffectiveFromEnumConverter : JsonConverter
167+ {
168+ public override bool CanConvert(Type t) => t == typeof(EffectiveFromEnum) || t == typeof(EffectiveFromEnum?);
169+
170+ public override object ReadJson(JsonReader reader, Type t, object existingValue, JsonSerializer serializer)
171+ {
172+ if (reader.TokenType == JsonToken.Null) return null;
173+ var value = serializer.Deserialize<string>(reader);
174+ if (value == "0000-01-01")
175+ {
176+ return EffectiveFromEnum.The00000101;
177+ }
178+ throw new Exception("Cannot unmarshal type EffectiveFromEnum");
179+ }
180+
181+ public override void WriteJson(JsonWriter writer, object untypedValue, JsonSerializer serializer)
182+ {
183+ if (untypedValue == null)
184+ {
185+ serializer.Serialize(writer, null);
186+ return;
187+ }
188+ var value = (EffectiveFromEnum)untypedValue;
189+ if (value == EffectiveFromEnum.The00000101)
190+ {
191+ serializer.Serialize(writer, "0000-01-01");
192+ return;
193+ }
194+ throw new Exception("Cannot marshal type EffectiveFromEnum");
195+ }
196+
197+ public static readonly EffectiveFromEnumConverter Singleton = new EffectiveFromEnumConverter();
198+ }
199+}
200+#pragma warning restore CS8618
201+#pragma warning restore CS8601
202+#pragma warning restore CS8602
203+#pragma warning restore CS8603
204+#pragma warning restore CS8604
205+#pragma warning restore CS8625
206+#pragma warning restore CS8765
Acsharp-SystemTextJsondefault / QuickType.cs+316 −0
@@ -0,0 +1,316 @@
1+// <auto-generated />
2+//
3+// To parse this JSON data, add NuGet 'System.Text.Json' then do:
4+//
5+// using QuickType;
6+//
7+// var topLevel = TopLevel.FromJson(jsonString);
8+#nullable enable
9+#pragma warning disable CS8618
10+#pragma warning disable CS8601
11+#pragma warning disable CS8602
12+#pragma warning disable CS8603
13+
14+namespace QuickType
15+{
16+ using System;
17+ using System.Collections.Generic;
18+
19+ using System.Text.Json;
20+ using System.Text.Json.Serialization;
21+ using System.Globalization;
22+
23+ public partial class TopLevel
24+ {
25+ [JsonRequired]
26+ [JsonPropertyName("details")]
27+ public Uri Details { get; set; }
28+
29+ [JsonRequired]
30+ [JsonPropertyName("rates")]
31+ public Rate[] Rates { get; set; }
32+
33+ [JsonRequired]
34+ [JsonPropertyName("version")]
35+ public object Version { get; set; }
36+ }
37+
38+ public partial class Rate
39+ {
40+ [JsonRequired]
41+ [JsonPropertyName("code")]
42+ public string Code { get; set; }
43+
44+ [JsonRequired]
45+ [JsonPropertyName("country_code")]
46+ public string CountryCode { get; set; }
47+
48+ [JsonRequired]
49+ [JsonPropertyName("name")]
50+ public string Name { get; set; }
51+
52+ [JsonRequired]
53+ [JsonPropertyName("periods")]
54+ public Period[] Periods { get; set; }
55+ }
56+
57+ public partial class Period
58+ {
59+ [JsonRequired]
60+ [JsonPropertyName("effective_from")]
61+ public EffectiveFromUnion EffectiveFrom { get; set; }
62+
63+ [JsonRequired]
64+ [JsonPropertyName("rates")]
65+ public Rates Rates { get; set; }
66+ }
67+
68+ public partial class Rates
69+ {
70+ [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]
71+ [JsonPropertyName("parking")]
72+ public double? Parking { get; set; }
73+
74+ [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]
75+ [JsonPropertyName("reduced")]
76+ public double? Reduced { get; set; }
77+
78+ [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]
79+ [JsonPropertyName("reduced1")]
80+ public double? Reduced1 { get; set; }
81+
82+ [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]
83+ [JsonPropertyName("reduced2")]
84+ public double? Reduced2 { get; set; }
85+
86+ [JsonRequired]
87+ [JsonPropertyName("standard")]
88+ public double Standard { get; set; }
89+
90+ [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]
91+ [JsonPropertyName("super_reduced")]
92+ public double? SuperReduced { get; set; }
93+ }
94+
95+ public enum EffectiveFromEnum { The00000101 };
96+
97+ public partial struct EffectiveFromUnion
98+ {
99+ public DateTimeOffset? DateTime;
100+ public EffectiveFromEnum? Enum;
101+
102+ public static implicit operator EffectiveFromUnion(DateTimeOffset DateTime) => new EffectiveFromUnion { DateTime = DateTime };
103+ public static implicit operator EffectiveFromUnion(EffectiveFromEnum Enum) => new EffectiveFromUnion { Enum = Enum };
104+ }
105+
106+ public partial class TopLevel
107+ {
108+ public static TopLevel FromJson(string json) => global::System.Text.Json.JsonSerializer.Deserialize<TopLevel>(json, QuickType.Converter.Settings);
109+ }
110+
111+ public static partial class Serialize
112+ {
113+ public static string ToJson(this TopLevel self) => JsonSerializer.Serialize(self, QuickType.Converter.Settings);
114+ }
115+
116+ internal static partial class Converter
117+ {
118+ public static readonly JsonSerializerOptions Settings = new(JsonSerializerDefaults.General)
119+ {
120+ Converters =
121+ {
122+ EffectiveFromUnionConverter.Singleton,
123+ EffectiveFromEnumConverter.Singleton,
124+ new DateOnlyConverter(),
125+ new TimeOnlyConverter(),
126+ IsoDateTimeOffsetConverter.Singleton
127+ },
128+ };
129+ }
130+
131+ internal class EffectiveFromUnionConverter : JsonConverter<EffectiveFromUnion>
132+ {
133+ public override bool CanConvert(Type t) => t == typeof(EffectiveFromUnion);
134+
135+ public override EffectiveFromUnion Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options)
136+ {
137+ switch (reader.TokenType)
138+ {
139+ case JsonTokenType.String:
140+ var stringValue = reader.GetString();
141+ DateTimeOffset dt;
142+ if (DateTimeOffset.TryParse(stringValue, out dt))
143+ {
144+ return new EffectiveFromUnion { DateTime = dt };
145+ }
146+ if (stringValue == "0000-01-01")
147+ {
148+ return new EffectiveFromUnion { Enum = EffectiveFromEnum.The00000101 };
149+ }
150+ break;
151+ }
152+ throw new JsonException("Cannot unmarshal type EffectiveFromUnion");
153+ }
154+
155+ public override void Write(Utf8JsonWriter writer, EffectiveFromUnion value, JsonSerializerOptions options)
156+ {
157+ if (value.DateTime != null)
158+ {
159+ JsonSerializer.Serialize(writer, value.DateTime.Value.ToString("o", System.Globalization.CultureInfo.InvariantCulture), options);
160+ return;
161+ }
162+ if (value.Enum != null)
163+ {
164+ if (value.Enum == EffectiveFromEnum.The00000101)
165+ {
166+ JsonSerializer.Serialize(writer, "0000-01-01", options);
167+ return;
168+ }
169+ }
170+ throw new NotSupportedException("Cannot marshal type EffectiveFromUnion");
171+ }
172+
173+ public static readonly EffectiveFromUnionConverter Singleton = new EffectiveFromUnionConverter();
174+ }
175+
176+ internal class EffectiveFromEnumConverter : JsonConverter<EffectiveFromEnum>
177+ {
178+ public override bool CanConvert(Type t) => t == typeof(EffectiveFromEnum);
179+
180+ public override EffectiveFromEnum Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options)
181+ {
182+ var value = reader.GetString();
183+ if (value == "0000-01-01")
184+ {
185+ return EffectiveFromEnum.The00000101;
186+ }
187+ throw new JsonException("Cannot unmarshal type EffectiveFromEnum");
188+ }
189+
190+ public override void Write(Utf8JsonWriter writer, EffectiveFromEnum value, JsonSerializerOptions options)
191+ {
192+ if (value == EffectiveFromEnum.The00000101)
193+ {
194+ JsonSerializer.Serialize(writer, "0000-01-01", options);
195+ return;
196+ }
197+ throw new NotSupportedException("Cannot marshal type EffectiveFromEnum");
198+ }
199+
200+ public static readonly EffectiveFromEnumConverter Singleton = new EffectiveFromEnumConverter();
201+ }
202+
203+ public class DateOnlyConverter : JsonConverter<DateOnly>
204+ {
205+ private readonly string serializationFormat;
206+ public DateOnlyConverter() : this(null) { }
207+
208+ public DateOnlyConverter(string? serializationFormat)
209+ {
210+ this.serializationFormat = serializationFormat ?? "yyyy-MM-dd";
211+ }
212+
213+ public override DateOnly Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options)
214+ {
215+ var value = reader.GetString();
216+ return DateOnly.Parse(value!);
217+ }
218+
219+ public override void Write(Utf8JsonWriter writer, DateOnly value, JsonSerializerOptions options)
220+ => writer.WriteStringValue(value.ToString(serializationFormat));
221+ }
222+
223+ public class TimeOnlyConverter : JsonConverter<TimeOnly>
224+ {
225+ private readonly string serializationFormat;
226+
227+ public TimeOnlyConverter() : this(null) { }
228+
229+ public TimeOnlyConverter(string? serializationFormat)
230+ {
231+ this.serializationFormat = serializationFormat ?? "HH:mm:ss.fff";
232+ }
233+
234+ public override TimeOnly Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options)
235+ {
236+ var value = reader.GetString();
237+ return TimeOnly.Parse(value!);
238+ }
239+
240+ public override void Write(Utf8JsonWriter writer, TimeOnly value, JsonSerializerOptions options)
241+ => writer.WriteStringValue(value.ToString(serializationFormat));
242+ }
243+
244+ internal class IsoDateTimeOffsetConverter : JsonConverter<DateTimeOffset>
245+ {
246+ public override bool CanConvert(Type t) => t == typeof(DateTimeOffset);
247+
248+ private const string DefaultDateTimeFormat = "yyyy'-'MM'-'dd'T'HH':'mm':'ss.FFFFFFFK";
249+
250+ private DateTimeStyles _dateTimeStyles = DateTimeStyles.RoundtripKind;
251+ private string? _dateTimeFormat;
252+ private CultureInfo? _culture;
253+
254+ public DateTimeStyles DateTimeStyles
255+ {
256+ get => _dateTimeStyles;
257+ set => _dateTimeStyles = value;
258+ }
259+
260+ public string? DateTimeFormat
261+ {
262+ get => _dateTimeFormat ?? string.Empty;
263+ set => _dateTimeFormat = (string.IsNullOrEmpty(value)) ? null : value;
264+ }
265+
266+ public CultureInfo Culture
267+ {
268+ get => _culture ?? CultureInfo.CurrentCulture;
269+ set => _culture = value;
270+ }
271+
272+ public override void Write(Utf8JsonWriter writer, DateTimeOffset value, JsonSerializerOptions options)
273+ {
274+ string text;
275+
276+
277+ if ((_dateTimeStyles & DateTimeStyles.AdjustToUniversal) == DateTimeStyles.AdjustToUniversal
278+ || (_dateTimeStyles & DateTimeStyles.AssumeUniversal) == DateTimeStyles.AssumeUniversal)
279+ {
280+ value = value.ToUniversalTime();
281+ }
282+
283+ text = value.ToString(_dateTimeFormat ?? DefaultDateTimeFormat, Culture);
284+
285+ writer.WriteStringValue(text);
286+ }
287+
288+ public override DateTimeOffset Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options)
289+ {
290+ string? dateText = reader.GetString();
291+
292+ if (string.IsNullOrEmpty(dateText) == false)
293+ {
294+ if (!string.IsNullOrEmpty(_dateTimeFormat))
295+ {
296+ return DateTimeOffset.ParseExact(dateText, _dateTimeFormat, Culture, _dateTimeStyles);
297+ }
298+ else
299+ {
300+ return DateTimeOffset.Parse(dateText, Culture, _dateTimeStyles);
301+ }
302+ }
303+ else
304+ {
305+ return default(DateTimeOffset);
306+ }
307+ }
308+
309+
310+ public static readonly IsoDateTimeOffsetConverter Singleton = new IsoDateTimeOffsetConverter();
311+ }
312+}
313+#pragma warning restore CS8618
314+#pragma warning restore CS8601
315+#pragma warning restore CS8602
316+#pragma warning restore CS8603
Acsharpdefault / QuickType.cs+206 −0
@@ -0,0 +1,206 @@
1+// <auto-generated />
2+//
3+// To parse this JSON data, add NuGet 'Newtonsoft.Json' then do:
4+//
5+// using QuickType;
6+//
7+// var topLevel = TopLevel.FromJson(jsonString);
8+#nullable enable
9+#pragma warning disable CS8618
10+#pragma warning disable CS8601
11+#pragma warning disable CS8602
12+#pragma warning disable CS8603
13+#pragma warning disable CS8604
14+#pragma warning disable CS8625
15+#pragma warning disable CS8765
16+
17+namespace QuickType
18+{
19+ using System;
20+ using System.Collections.Generic;
21+
22+ using System.Globalization;
23+ using Newtonsoft.Json;
24+ using Newtonsoft.Json.Converters;
25+
26+ public partial class TopLevel
27+ {
28+ [JsonProperty("details", Required = Required.Always)]
29+ public Uri Details { get; set; }
30+
31+ [JsonProperty("rates", Required = Required.Always)]
32+ public Rate[] Rates { get; set; }
33+
34+ [JsonProperty("version", Required = Required.AllowNull)]
35+ public object Version { get; set; }
36+ }
37+
38+ public partial class Rate
39+ {
40+ [JsonProperty("code", Required = Required.Always)]
41+ public string Code { get; set; }
42+
43+ [JsonProperty("country_code", Required = Required.Always)]
44+ public string CountryCode { get; set; }
45+
46+ [JsonProperty("name", Required = Required.Always)]
47+ public string Name { get; set; }
48+
49+ [JsonProperty("periods", Required = Required.Always)]
50+ public Period[] Periods { get; set; }
51+ }
52+
53+ public partial class Period
54+ {
55+ [JsonProperty("effective_from", Required = Required.Always)]
56+ public EffectiveFromUnion EffectiveFrom { get; set; }
57+
58+ [JsonProperty("rates", Required = Required.Always)]
59+ public Rates Rates { get; set; }
60+ }
61+
62+ public partial class Rates
63+ {
64+ [JsonProperty("parking", Required = Required.DisallowNull, NullValueHandling = NullValueHandling.Ignore)]
65+ public double? Parking { get; set; }
66+
67+ [JsonProperty("reduced", Required = Required.DisallowNull, NullValueHandling = NullValueHandling.Ignore)]
68+ public double? Reduced { get; set; }
69+
70+ [JsonProperty("reduced1", Required = Required.DisallowNull, NullValueHandling = NullValueHandling.Ignore)]
71+ public double? Reduced1 { get; set; }
72+
73+ [JsonProperty("reduced2", Required = Required.DisallowNull, NullValueHandling = NullValueHandling.Ignore)]
74+ public double? Reduced2 { get; set; }
75+
76+ [JsonProperty("standard", Required = Required.Always)]
77+ public double Standard { get; set; }
78+
79+ [JsonProperty("super_reduced", Required = Required.DisallowNull, NullValueHandling = NullValueHandling.Ignore)]
80+ public double? SuperReduced { get; set; }
81+ }
82+
83+ public enum EffectiveFromEnum { The00000101 };
84+
85+ public partial struct EffectiveFromUnion
86+ {
87+ public DateTimeOffset? DateTime;
88+ public EffectiveFromEnum? Enum;
89+
90+ public static implicit operator EffectiveFromUnion(DateTimeOffset DateTime) => new EffectiveFromUnion { DateTime = DateTime };
91+ public static implicit operator EffectiveFromUnion(EffectiveFromEnum Enum) => new EffectiveFromUnion { Enum = Enum };
92+ }
93+
94+ public partial class TopLevel
95+ {
96+ public static TopLevel FromJson(string json) => JsonConvert.DeserializeObject<TopLevel>(json, QuickType.Converter.Settings);
97+ }
98+
99+ public static partial class Serialize
100+ {
101+ public static string ToJson(this TopLevel self) => JsonConvert.SerializeObject(self, QuickType.Converter.Settings);
102+ }
103+
104+ internal static partial class Converter
105+ {
106+ public static readonly JsonSerializerSettings Settings = new JsonSerializerSettings
107+ {
108+ MetadataPropertyHandling = MetadataPropertyHandling.Ignore,
109+ DateParseHandling = DateParseHandling.None,
110+ Converters =
111+ {
112+ EffectiveFromUnionConverter.Singleton,
113+ EffectiveFromEnumConverter.Singleton,
114+ new IsoDateTimeConverter { DateTimeStyles = DateTimeStyles.AssumeUniversal }
115+ },
116+ };
117+ }
118+
119+ internal class EffectiveFromUnionConverter : JsonConverter
120+ {
121+ public override bool CanConvert(Type t) => t == typeof(EffectiveFromUnion) || t == typeof(EffectiveFromUnion?);
122+
123+ public override object ReadJson(JsonReader reader, Type t, object existingValue, JsonSerializer serializer)
124+ {
125+ switch (reader.TokenType)
126+ {
127+ case JsonToken.String:
128+ case JsonToken.Date:
129+ var stringValue = serializer.Deserialize<string>(reader);
130+ DateTimeOffset dt;
131+ if (DateTimeOffset.TryParse(stringValue, out dt))
132+ {
133+ return new EffectiveFromUnion { DateTime = dt };
134+ }
135+ if (stringValue == "0000-01-01")
136+ {
137+ return new EffectiveFromUnion { Enum = EffectiveFromEnum.The00000101 };
138+ }
139+ break;
140+ }
141+ throw new Exception("Cannot unmarshal type EffectiveFromUnion");
142+ }
143+
144+ public override void WriteJson(JsonWriter writer, object untypedValue, JsonSerializer serializer)
145+ {
146+ var value = (EffectiveFromUnion)untypedValue;
147+ if (value.DateTime != null)
148+ {
149+ serializer.Serialize(writer, value.DateTime.Value.ToString("o", System.Globalization.CultureInfo.InvariantCulture));
150+ return;
151+ }
152+ if (value.Enum != null)
153+ {
154+ if (value.Enum == EffectiveFromEnum.The00000101)
155+ {
156+ serializer.Serialize(writer, "0000-01-01");
157+ return;
158+ }
159+ }
160+ throw new Exception("Cannot marshal type EffectiveFromUnion");
161+ }
162+
163+ public static readonly EffectiveFromUnionConverter Singleton = new EffectiveFromUnionConverter();
164+ }
165+
166+ internal class EffectiveFromEnumConverter : JsonConverter
167+ {
168+ public override bool CanConvert(Type t) => t == typeof(EffectiveFromEnum) || t == typeof(EffectiveFromEnum?);
169+
170+ public override object ReadJson(JsonReader reader, Type t, object existingValue, JsonSerializer serializer)
171+ {
172+ if (reader.TokenType == JsonToken.Null) return null;
173+ var value = serializer.Deserialize<string>(reader);
174+ if (value == "0000-01-01")
175+ {
176+ return EffectiveFromEnum.The00000101;
177+ }
178+ throw new Exception("Cannot unmarshal type EffectiveFromEnum");
179+ }
180+
181+ public override void WriteJson(JsonWriter writer, object untypedValue, JsonSerializer serializer)
182+ {
183+ if (untypedValue == null)
184+ {
185+ serializer.Serialize(writer, null);
186+ return;
187+ }
188+ var value = (EffectiveFromEnum)untypedValue;
189+ if (value == EffectiveFromEnum.The00000101)
190+ {
191+ serializer.Serialize(writer, "0000-01-01");
192+ return;
193+ }
194+ throw new Exception("Cannot marshal type EffectiveFromEnum");
195+ }
196+
197+ public static readonly EffectiveFromEnumConverter Singleton = new EffectiveFromEnumConverter();
198+ }
199+}
200+#pragma warning restore CS8618
201+#pragma warning restore CS8601
202+#pragma warning restore CS8602
203+#pragma warning restore CS8603
204+#pragma warning restore CS8604
205+#pragma warning restore CS8625
206+#pragma warning restore CS8765
No generated files match these filters.