Generated-output differences

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

test/inputs/json/priority/combined-enum.json

1 generated file · +157 −0
Acsharp-no-combine-classesdefault / QuickType.cs+157 −0
@@ -0,0 +1,157 @@
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("bar", Required = Required.Always)]
29+ public Bar[] Bar { get; set; }
30+
31+ [JsonProperty("foo", Required = Required.Always)]
32+ public Foo[] Foo { get; set; }
33+ }
34+
35+ public partial class Bar
36+ {
37+ [JsonProperty("x", Required = Required.Always)]
38+ public BarX X { get; set; }
39+ }
40+
41+ public partial class Foo
42+ {
43+ [JsonProperty("x", Required = Required.Always)]
44+ public FooX X { get; set; }
45+ }
46+
47+ public enum BarX { Three };
48+
49+ public enum FooX { One, Two };
50+
51+ public partial class TopLevel
52+ {
53+ public static TopLevel FromJson(string json) => JsonConvert.DeserializeObject<TopLevel>(json, QuickType.Converter.Settings);
54+ }
55+
56+ public static partial class Serialize
57+ {
58+ public static string ToJson(this TopLevel self) => JsonConvert.SerializeObject(self, QuickType.Converter.Settings);
59+ }
60+
61+ internal static partial class Converter
62+ {
63+ public static readonly JsonSerializerSettings Settings = new JsonSerializerSettings
64+ {
65+ MetadataPropertyHandling = MetadataPropertyHandling.Ignore,
66+ DateParseHandling = DateParseHandling.None,
67+ Converters =
68+ {
69+ BarXConverter.Singleton,
70+ FooXConverter.Singleton,
71+ new IsoDateTimeConverter { DateTimeStyles = DateTimeStyles.AssumeUniversal }
72+ },
73+ };
74+ }
75+
76+ internal class BarXConverter : JsonConverter
77+ {
78+ public override bool CanConvert(Type t) => t == typeof(BarX) || t == typeof(BarX?);
79+
80+ public override object ReadJson(JsonReader reader, Type t, object existingValue, JsonSerializer serializer)
81+ {
82+ if (reader.TokenType == JsonToken.Null) return null;
83+ var value = serializer.Deserialize<string>(reader);
84+ if (value == "three")
85+ {
86+ return BarX.Three;
87+ }
88+ throw new Exception("Cannot unmarshal type BarX");
89+ }
90+
91+ public override void WriteJson(JsonWriter writer, object untypedValue, JsonSerializer serializer)
92+ {
93+ if (untypedValue == null)
94+ {
95+ serializer.Serialize(writer, null);
96+ return;
97+ }
98+ var value = (BarX)untypedValue;
99+ if (value == BarX.Three)
100+ {
101+ serializer.Serialize(writer, "three");
102+ return;
103+ }
104+ throw new Exception("Cannot marshal type BarX");
105+ }
106+
107+ public static readonly BarXConverter Singleton = new BarXConverter();
108+ }
109+
110+ internal class FooXConverter : JsonConverter
111+ {
112+ public override bool CanConvert(Type t) => t == typeof(FooX) || t == typeof(FooX?);
113+
114+ public override object ReadJson(JsonReader reader, Type t, object existingValue, JsonSerializer serializer)
115+ {
116+ if (reader.TokenType == JsonToken.Null) return null;
117+ var value = serializer.Deserialize<string>(reader);
118+ switch (value)
119+ {
120+ case "one":
121+ return FooX.One;
122+ case "two":
123+ return FooX.Two;
124+ }
125+ throw new Exception("Cannot unmarshal type FooX");
126+ }
127+
128+ public override void WriteJson(JsonWriter writer, object untypedValue, JsonSerializer serializer)
129+ {
130+ if (untypedValue == null)
131+ {
132+ serializer.Serialize(writer, null);
133+ return;
134+ }
135+ var value = (FooX)untypedValue;
136+ switch (value)
137+ {
138+ case FooX.One:
139+ serializer.Serialize(writer, "one");
140+ return;
141+ case FooX.Two:
142+ serializer.Serialize(writer, "two");
143+ return;
144+ }
145+ throw new Exception("Cannot marshal type FooX");
146+ }
147+
148+ public static readonly FooXConverter Singleton = new FooXConverter();
149+ }
150+}
151+#pragma warning restore CS8618
152+#pragma warning restore CS8601
153+#pragma warning restore CS8602
154+#pragma warning restore CS8603
155+#pragma warning restore CS8604
156+#pragma warning restore CS8625
157+#pragma warning restore CS8765
No generated files match these filters.