Generated-output differences

quicktype output changed between the PR base and tested PR merge revisions.
← Back to the pull request
6test cases
6files differ
5modified
1new
0deleted
298changed lines
+278 −20insertions / deletions
Base 988a3d6ab2ee15a18da376b15a53b475abdc8fcb · PR merge 53cc2811a82fc434f93d1cddf110fb59c38cb92c · Head c265298d63c054ab191aca5ebdf9a2912772aeea · raw patch
Test case

test/inputs/regressions/unicode-codepoint-length.schema

1 generated file · +258 −0
Aschema-csharp-SystemTextJsondefault / QuickType.cs+258 −0
@@ -0,0 +1,258 @@
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("exact")]
27+ [JsonConverter(typeof(PurpleMinMaxLengthCheckConverter))]
28+ public string Exact { get; set; }
29+
30+ [JsonRequired]
31+ [JsonPropertyName("maximum")]
32+ [JsonConverter(typeof(FluffyMinMaxLengthCheckConverter))]
33+ public string Maximum { get; set; }
34+
35+ [JsonRequired]
36+ [JsonPropertyName("minimum")]
37+ [JsonConverter(typeof(TentacledMinMaxLengthCheckConverter))]
38+ public string Minimum { get; set; }
39+ }
40+
41+ public partial class TopLevel
42+ {
43+ public static TopLevel FromJson(string json) => global::System.Text.Json.JsonSerializer.Deserialize<TopLevel>(json, QuickType.Converter.Settings);
44+ }
45+
46+ public static partial class Serialize
47+ {
48+ public static string ToJson(this TopLevel self) => JsonSerializer.Serialize(self, QuickType.Converter.Settings);
49+ }
50+
51+ internal static partial class Converter
52+ {
53+ public static readonly JsonSerializerOptions Settings = new(JsonSerializerDefaults.General)
54+ {
55+ Converters =
56+ {
57+ new DateOnlyConverter(),
58+ new TimeOnlyConverter(),
59+ IsoDateTimeOffsetConverter.Singleton
60+ },
61+ };
62+ }
63+
64+ internal class PurpleMinMaxLengthCheckConverter : JsonConverter<string>
65+ {
66+ public override bool CanConvert(Type t) => t == typeof(string);
67+
68+ public override string Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options)
69+ {
70+ var value = reader.GetString();
71+ if (System.Linq.Enumerable.Count(value!, c => !char.IsLowSurrogate(c)) >= 2 && System.Linq.Enumerable.Count(value!, c => !char.IsLowSurrogate(c)) <= 2)
72+ {
73+ return value;
74+ }
75+ throw new JsonException("Cannot unmarshal type string");
76+ }
77+
78+ public override void Write(Utf8JsonWriter writer, string value, JsonSerializerOptions options)
79+ {
80+ if (System.Linq.Enumerable.Count(value!, c => !char.IsLowSurrogate(c)) >= 2 && System.Linq.Enumerable.Count(value!, c => !char.IsLowSurrogate(c)) <= 2)
81+ {
82+ JsonSerializer.Serialize(writer, value, options);
83+ return;
84+ }
85+ throw new NotSupportedException("Cannot marshal type string");
86+ }
87+
88+ public static readonly PurpleMinMaxLengthCheckConverter Singleton = new PurpleMinMaxLengthCheckConverter();
89+ }
90+
91+ internal class FluffyMinMaxLengthCheckConverter : JsonConverter<string>
92+ {
93+ public override bool CanConvert(Type t) => t == typeof(string);
94+
95+ public override string Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options)
96+ {
97+ var value = reader.GetString();
98+ if (System.Linq.Enumerable.Count(value!, c => !char.IsLowSurrogate(c)) <= 1)
99+ {
100+ return value;
101+ }
102+ throw new JsonException("Cannot unmarshal type string");
103+ }
104+
105+ public override void Write(Utf8JsonWriter writer, string value, JsonSerializerOptions options)
106+ {
107+ if (System.Linq.Enumerable.Count(value!, c => !char.IsLowSurrogate(c)) <= 1)
108+ {
109+ JsonSerializer.Serialize(writer, value, options);
110+ return;
111+ }
112+ throw new NotSupportedException("Cannot marshal type string");
113+ }
114+
115+ public static readonly FluffyMinMaxLengthCheckConverter Singleton = new FluffyMinMaxLengthCheckConverter();
116+ }
117+
118+ internal class TentacledMinMaxLengthCheckConverter : JsonConverter<string>
119+ {
120+ public override bool CanConvert(Type t) => t == typeof(string);
121+
122+ public override string Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options)
123+ {
124+ var value = reader.GetString();
125+ if (System.Linq.Enumerable.Count(value!, c => !char.IsLowSurrogate(c)) >= 2)
126+ {
127+ return value;
128+ }
129+ throw new JsonException("Cannot unmarshal type string");
130+ }
131+
132+ public override void Write(Utf8JsonWriter writer, string value, JsonSerializerOptions options)
133+ {
134+ if (System.Linq.Enumerable.Count(value!, c => !char.IsLowSurrogate(c)) >= 2)
135+ {
136+ JsonSerializer.Serialize(writer, value, options);
137+ return;
138+ }
139+ throw new NotSupportedException("Cannot marshal type string");
140+ }
141+
142+ public static readonly TentacledMinMaxLengthCheckConverter Singleton = new TentacledMinMaxLengthCheckConverter();
143+ }
144+
145+ public class DateOnlyConverter : JsonConverter<DateOnly>
146+ {
147+ private readonly string serializationFormat;
148+ public DateOnlyConverter() : this(null) { }
149+
150+ public DateOnlyConverter(string? serializationFormat)
151+ {
152+ this.serializationFormat = serializationFormat ?? "yyyy-MM-dd";
153+ }
154+
155+ public override DateOnly Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options)
156+ {
157+ var value = reader.GetString();
158+ return DateOnly.Parse(value!);
159+ }
160+
161+ public override void Write(Utf8JsonWriter writer, DateOnly value, JsonSerializerOptions options)
162+ => writer.WriteStringValue(value.ToString(serializationFormat));
163+ }
164+
165+ public class TimeOnlyConverter : JsonConverter<TimeOnly>
166+ {
167+ private readonly string serializationFormat;
168+
169+ public TimeOnlyConverter() : this(null) { }
170+
171+ public TimeOnlyConverter(string? serializationFormat)
172+ {
173+ this.serializationFormat = serializationFormat ?? "HH:mm:ss.fff";
174+ }
175+
176+ public override TimeOnly Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options)
177+ {
178+ var value = reader.GetString();
179+ return TimeOnly.Parse(value!);
180+ }
181+
182+ public override void Write(Utf8JsonWriter writer, TimeOnly value, JsonSerializerOptions options)
183+ => writer.WriteStringValue(value.ToString(serializationFormat));
184+ }
185+
186+ internal class IsoDateTimeOffsetConverter : JsonConverter<DateTimeOffset>
187+ {
188+ public override bool CanConvert(Type t) => t == typeof(DateTimeOffset);
189+
190+ private const string DefaultDateTimeFormat = "yyyy'-'MM'-'dd'T'HH':'mm':'ss.FFFFFFFK";
191+
192+ private DateTimeStyles _dateTimeStyles = DateTimeStyles.RoundtripKind;
193+ private string? _dateTimeFormat;
194+ private CultureInfo? _culture;
195+
196+ public DateTimeStyles DateTimeStyles
197+ {
198+ get => _dateTimeStyles;
199+ set => _dateTimeStyles = value;
200+ }
201+
202+ public string? DateTimeFormat
203+ {
204+ get => _dateTimeFormat ?? string.Empty;
205+ set => _dateTimeFormat = (string.IsNullOrEmpty(value)) ? null : value;
206+ }
207+
208+ public CultureInfo Culture
209+ {
210+ get => _culture ?? CultureInfo.CurrentCulture;
211+ set => _culture = value;
212+ }
213+
214+ public override void Write(Utf8JsonWriter writer, DateTimeOffset value, JsonSerializerOptions options)
215+ {
216+ string text;
217+
218+
219+ if ((_dateTimeStyles & DateTimeStyles.AdjustToUniversal) == DateTimeStyles.AdjustToUniversal
220+ || (_dateTimeStyles & DateTimeStyles.AssumeUniversal) == DateTimeStyles.AssumeUniversal)
221+ {
222+ value = value.ToUniversalTime();
223+ }
224+
225+ text = value.ToString(_dateTimeFormat ?? DefaultDateTimeFormat, Culture);
226+
227+ writer.WriteStringValue(text);
228+ }
229+
230+ public override DateTimeOffset Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options)
231+ {
232+ string? dateText = reader.GetString();
233+
234+ if (string.IsNullOrEmpty(dateText) == false)
235+ {
236+ if (!string.IsNullOrEmpty(_dateTimeFormat))
237+ {
238+ return DateTimeOffset.ParseExact(dateText, _dateTimeFormat, Culture, _dateTimeStyles);
239+ }
240+ else
241+ {
242+ return DateTimeOffset.Parse(dateText, Culture, _dateTimeStyles);
243+ }
244+ }
245+ else
246+ {
247+ return default(DateTimeOffset);
248+ }
249+ }
250+
251+
252+ public static readonly IsoDateTimeOffsetConverter Singleton = new IsoDateTimeOffsetConverter();
253+ }
254+}
255+#pragma warning restore CS8618
256+#pragma warning restore CS8601
257+#pragma warning restore CS8602
258+#pragma warning restore CS8603
Test case

test/inputs/schema/minmaxlength.schema

1 generated file · +12 −12
Mschema-csharp-SystemTextJsondefault / QuickType.cs+12 −12
@@ -107,7 +107,7 @@ namespace QuickType
107107 return new InUnion { Double = doubleValue1 };
108108 case JsonTokenType.String:
109109 var stringValue = reader.GetString();
110- if (stringValue.Length >= 3 && stringValue.Length <= 5)
110+ if (System.Linq.Enumerable.Count(stringValue!, c => !char.IsLowSurrogate(c)) >= 3 && System.Linq.Enumerable.Count(stringValue!, c => !char.IsLowSurrogate(c)) <= 5)
111111 {
112112 return new InUnion { String = stringValue };
113113 }
@@ -125,7 +125,7 @@ namespace QuickType
125125 }
126126 if (value.String != null)
127127 {
128- if (value.String.Length >= 3 && value.String.Length <= 5)
128+ if (System.Linq.Enumerable.Count(value.String!, c => !char.IsLowSurrogate(c)) >= 3 && System.Linq.Enumerable.Count(value.String!, c => !char.IsLowSurrogate(c)) <= 5)
129129 {
130130 JsonSerializer.Serialize(writer, value.String, options);
131131 return;
@@ -144,7 +144,7 @@ namespace QuickType
144144 public override string Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options)
145145 {
146146 var value = reader.GetString();
147- if (value.Length >= 3 && value.Length <= 5)
147+ if (System.Linq.Enumerable.Count(value!, c => !char.IsLowSurrogate(c)) >= 3 && System.Linq.Enumerable.Count(value!, c => !char.IsLowSurrogate(c)) <= 5)
148148 {
149149 return value;
150150 }
@@ -153,7 +153,7 @@ namespace QuickType
153153
154154 public override void Write(Utf8JsonWriter writer, string value, JsonSerializerOptions options)
155155 {
156- if (value.Length >= 3 && value.Length <= 5)
156+ if (System.Linq.Enumerable.Count(value!, c => !char.IsLowSurrogate(c)) >= 3 && System.Linq.Enumerable.Count(value!, c => !char.IsLowSurrogate(c)) <= 5)
157157 {
158158 JsonSerializer.Serialize(writer, value, options);
159159 return;
@@ -171,7 +171,7 @@ namespace QuickType
171171 public override string Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options)
172172 {
173173 var value = reader.GetString();
174- if (value.Length >= 4 && value.Length <= 5)
174+ if (System.Linq.Enumerable.Count(value!, c => !char.IsLowSurrogate(c)) >= 4 && System.Linq.Enumerable.Count(value!, c => !char.IsLowSurrogate(c)) <= 5)
175175 {
176176 return value;
177177 }
@@ -180,7 +180,7 @@ namespace QuickType
180180
181181 public override void Write(Utf8JsonWriter writer, string value, JsonSerializerOptions options)
182182 {
183- if (value.Length >= 4 && value.Length <= 5)
183+ if (System.Linq.Enumerable.Count(value!, c => !char.IsLowSurrogate(c)) >= 4 && System.Linq.Enumerable.Count(value!, c => !char.IsLowSurrogate(c)) <= 5)
184184 {
185185 JsonSerializer.Serialize(writer, value, options);
186186 return;
@@ -198,7 +198,7 @@ namespace QuickType
198198 public override string Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options)
199199 {
200200 var value = reader.GetString();
201- if (value.Length <= 5)
201+ if (System.Linq.Enumerable.Count(value!, c => !char.IsLowSurrogate(c)) <= 5)
202202 {
203203 return value;
204204 }
@@ -207,7 +207,7 @@ namespace QuickType
207207
208208 public override void Write(Utf8JsonWriter writer, string value, JsonSerializerOptions options)
209209 {
210- if (value.Length <= 5)
210+ if (System.Linq.Enumerable.Count(value!, c => !char.IsLowSurrogate(c)) <= 5)
211211 {
212212 JsonSerializer.Serialize(writer, value, options);
213213 return;
@@ -225,7 +225,7 @@ namespace QuickType
225225 public override string Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options)
226226 {
227227 var value = reader.GetString();
228- if (value.Length >= 3)
228+ if (System.Linq.Enumerable.Count(value!, c => !char.IsLowSurrogate(c)) >= 3)
229229 {
230230 return value;
231231 }
@@ -234,7 +234,7 @@ namespace QuickType
234234
235235 public override void Write(Utf8JsonWriter writer, string value, JsonSerializerOptions options)
236236 {
237- if (value.Length >= 3)
237+ if (System.Linq.Enumerable.Count(value!, c => !char.IsLowSurrogate(c)) >= 3)
238238 {
239239 JsonSerializer.Serialize(writer, value, options);
240240 return;
@@ -252,7 +252,7 @@ namespace QuickType
252252 public override string Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options)
253253 {
254254 var value = reader.GetString();
255- if (value.Length >= 3 && value.Length <= 6)
255+ if (System.Linq.Enumerable.Count(value!, c => !char.IsLowSurrogate(c)) >= 3 && System.Linq.Enumerable.Count(value!, c => !char.IsLowSurrogate(c)) <= 6)
256256 {
257257 return value;
258258 }
@@ -261,7 +261,7 @@ namespace QuickType
261261
262262 public override void Write(Utf8JsonWriter writer, string value, JsonSerializerOptions options)
263263 {
264- if (value.Length >= 3 && value.Length <= 6)
264+ if (System.Linq.Enumerable.Count(value!, c => !char.IsLowSurrogate(c)) >= 3 && System.Linq.Enumerable.Count(value!, c => !char.IsLowSurrogate(c)) <= 6)
265265 {
266266 JsonSerializer.Serialize(writer, value, options);
267267 return;
Test case

test/inputs/schema/optional-const-ref.schema

1 generated file · +2 −2
Mschema-csharp-SystemTextJsondefault / QuickType.cs+2 −2
@@ -124,7 +124,7 @@ namespace QuickType
124124 public override string Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options)
125125 {
126126 var value = reader.GetString();
127- if (value.Length >= 2 && value.Length <= 16)
127+ if (System.Linq.Enumerable.Count(value!, c => !char.IsLowSurrogate(c)) >= 2 && System.Linq.Enumerable.Count(value!, c => !char.IsLowSurrogate(c)) <= 16)
128128 {
129129 return value;
130130 }
@@ -133,7 +133,7 @@ namespace QuickType
133133
134134 public override void Write(Utf8JsonWriter writer, string value, JsonSerializerOptions options)
135135 {
136- if (value.Length >= 2 && value.Length <= 16)
136+ if (System.Linq.Enumerable.Count(value!, c => !char.IsLowSurrogate(c)) >= 2 && System.Linq.Enumerable.Count(value!, c => !char.IsLowSurrogate(c)) <= 16)
137137 {
138138 JsonSerializer.Serialize(writer, value, options);
139139 return;
Test case

test/inputs/schema/optional-constraints.schema

1 generated file · +2 −2
Mschema-csharp-SystemTextJsondefault / QuickType.cs+2 −2
@@ -131,7 +131,7 @@ namespace QuickType
131131 public override string Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options)
132132 {
133133 var value = reader.GetString();
134- if (value.Length >= 3 && value.Length <= 10)
134+ if (System.Linq.Enumerable.Count(value!, c => !char.IsLowSurrogate(c)) >= 3 && System.Linq.Enumerable.Count(value!, c => !char.IsLowSurrogate(c)) <= 10)
135135 {
136136 return value;
137137 }
@@ -140,7 +140,7 @@ namespace QuickType
140140
141141 public override void Write(Utf8JsonWriter writer, string value, JsonSerializerOptions options)
142142 {
143- if (value.Length >= 3 && value.Length <= 10)
143+ if (System.Linq.Enumerable.Count(value!, c => !char.IsLowSurrogate(c)) >= 3 && System.Linq.Enumerable.Count(value!, c => !char.IsLowSurrogate(c)) <= 10)
144144 {
145145 JsonSerializer.Serialize(writer, value, options);
146146 return;
Test case

test/inputs/schema/renaming-bug.schema

1 generated file · +2 −2
Mschema-csharp-SystemTextJsondefault / QuickType.cs+2 −2
@@ -228,7 +228,7 @@ namespace QuickType
228228 public override string Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options)
229229 {
230230 var value = reader.GetString();
231- if (value.Length >= 1)
231+ if (System.Linq.Enumerable.Count(value!, c => !char.IsLowSurrogate(c)) >= 1)
232232 {
233233 return value;
234234 }
@@ -237,7 +237,7 @@ namespace QuickType
237237
238238 public override void Write(Utf8JsonWriter writer, string value, JsonSerializerOptions options)
239239 {
240- if (value.Length >= 1)
240+ if (System.Linq.Enumerable.Count(value!, c => !char.IsLowSurrogate(c)) >= 1)
241241 {
242242 JsonSerializer.Serialize(writer, value, options);
243243 return;
Test case

test/inputs/schema/schema-constraints.schema

1 generated file · +2 −2
Mschema-csharp-SystemTextJsondefault / QuickType.cs+2 −2
@@ -63,7 +63,7 @@ namespace QuickType
6363 public override string Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options)
6464 {
6565 var value = reader.GetString();
66- if (value.Length >= 5 && value.Length <= 5)
66+ if (System.Linq.Enumerable.Count(value!, c => !char.IsLowSurrogate(c)) >= 5 && System.Linq.Enumerable.Count(value!, c => !char.IsLowSurrogate(c)) <= 5)
6767 {
6868 return value;
6969 }
@@ -72,7 +72,7 @@ namespace QuickType
7272
7373 public override void Write(Utf8JsonWriter writer, string value, JsonSerializerOptions options)
7474 {
75- if (value.Length >= 5 && value.Length <= 5)
75+ if (System.Linq.Enumerable.Count(value!, c => !char.IsLowSurrogate(c)) >= 5 && System.Linq.Enumerable.Count(value!, c => !char.IsLowSurrogate(c)) <= 5)
7676 {
7777 JsonSerializer.Serialize(writer, value, options);
7878 return;
No generated files match these filters.