[C#][netcore] Add nullable support to oneOf models (#7750)

* add nullable support to C# oneOf models

* fix null reference exception
This commit is contained in:
William Cheng 2020-10-20 14:50:03 +08:00 committed by GitHub
parent 12acf2eb72
commit 072b309100
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
23 changed files with 151 additions and 257 deletions

View File

@ -14,7 +14,7 @@ namespace {{packageName}}.{{modelPackage}}
/// <summary> /// <summary>
/// Custom JSON serializer /// Custom JSON serializer
/// </summary> /// </summary>
protected readonly JsonSerializerSettings _serializerSettings = new JsonSerializerSettings static public readonly JsonSerializerSettings SerializerSettings = new JsonSerializerSettings
{ {
// OpenAPI generated types generally hide default constructors. // OpenAPI generated types generally hide default constructors.
ConstructorHandling = ConstructorHandling.AllowNonPublicDefaultConstructor, ConstructorHandling = ConstructorHandling.AllowNonPublicDefaultConstructor,

View File

@ -4,6 +4,7 @@
[DataContract(Name = "{{{name}}}")] [DataContract(Name = "{{{name}}}")]
{{>visibility}} partial class {{classname}} : AbstractOpenAPISchema, {{#parent}}{{{parent}}}, {{/parent}}IEquatable<{{classname}}>{{#validatable}}, IValidatableObject{{/validatable}} {{>visibility}} partial class {{classname}} : AbstractOpenAPISchema, {{#parent}}{{{parent}}}, {{/parent}}IEquatable<{{classname}}>{{#validatable}}, IValidatableObject{{/validatable}}
{ {
{{#isNullable}}
/// <summary> /// <summary>
/// Initializes a new instance of the <see cref="{{classname}}" /> class. /// Initializes a new instance of the <see cref="{{classname}}" /> class.
/// </summary> /// </summary>
@ -13,6 +14,7 @@
this.SchemaType= "oneOf"; this.SchemaType= "oneOf";
} }
{{/isNullable}}
{{#oneOf}} {{#oneOf}}
/// <summary> /// <summary>
/// Initializes a new instance of the <see cref="{{classname}}" /> class /// Initializes a new instance of the <see cref="{{classname}}" /> class
@ -85,7 +87,7 @@
/// <returns>JSON string presentation of the object</returns> /// <returns>JSON string presentation of the object</returns>
public override string ToJson() public override string ToJson()
{ {
return JsonConvert.SerializeObject(this.ActualInstance, _serializerSettings); return JsonConvert.SerializeObject(this.ActualInstance, {{classname}}.SerializerSettings);
} }
/// <summary> /// <summary>
@ -95,7 +97,7 @@
/// <returns>An instance of {{classname}}</returns> /// <returns>An instance of {{classname}}</returns>
public static {{classname}} FromJson(string jsonString) public static {{classname}} FromJson(string jsonString)
{ {
{{classname}} new{{classname}} = new {{classname}}(); {{classname}} new{{classname}} = null;
{{#useOneOfDiscriminatorLookup}} {{#useOneOfDiscriminatorLookup}}
{{#discriminator}} {{#discriminator}}
@ -104,11 +106,11 @@
{ {
{{#mappedModels}} {{#mappedModels}}
case "{{{mappingName}}}": case "{{{mappingName}}}":
new{{classname}}.ActualInstance = JsonConvert.DeserializeObject<{{{modelName}}}>(jsonString, new{{classname}}._serializerSettings); new{{classname}} = new {{classname}}(JsonConvert.DeserializeObject<{{{modelName}}}>(jsonString, {{classname}}.SerializerSettings));
return new{{classname}}; return new{{classname}};
{{/mappedModels}} {{/mappedModels}}
default: default:
System.Diagnostics.Debug.WriteLine(String.Format("Failed to lookup discriminator value `%s` for {{classname}}. Possible values:{{#mappedModels}} {{{mappingName}}}{{/mappedModels}}", discriminatorValue)); System.Diagnostics.Debug.WriteLine(String.Format("Failed to lookup discriminator value `{0}` for {{classname}}. Possible values:{{#mappedModels}} {{{mappingName}}}{{/mappedModels}}", discriminatorValue));
break; break;
} }
@ -120,14 +122,14 @@
try try
{ {
new{{classname}}.ActualInstance = JsonConvert.DeserializeObject<{{{.}}}>(jsonString, new{{classname}}._serializerSettings); new{{classname}} = new {{classname}}(JsonConvert.DeserializeObject<{{{.}}}>(jsonString, {{classname}}.SerializerSettings));
matchedTypes.Add("{{{.}}}"); matchedTypes.Add("{{{.}}}");
match++; match++;
} }
catch (Exception exception) catch (Exception exception)
{ {
// deserialization failed, try the next one // deserialization failed, try the next one
System.Diagnostics.Debug.WriteLine(String.Format("Failed to deserialize `%s` into {{{.}}}: %s", jsonString, exception.ToString())); System.Diagnostics.Debug.WriteLine(String.Format("Failed to deserialize `{0}` into {{{.}}}: {1}", jsonString, exception.ToString()));
} }
{{/oneOf}} {{/oneOf}}

View File

@ -68,7 +68,7 @@ namespace Org.OpenAPITools.Test
t.Name = "Something"; t.Name = "Something";
Fruit f1 = new Fruit(a); Fruit f1 = new Fruit(a);
Fruit f2 = new Fruit(a); Fruit f2 = new Fruit(b);
f1.ActualInstance = b; f1.ActualInstance = b;
f2.ActualInstance = a; f2.ActualInstance = a;

View File

@ -22,7 +22,7 @@ namespace Org.OpenAPITools.Model
/// <summary> /// <summary>
/// Custom JSON serializer /// Custom JSON serializer
/// </summary> /// </summary>
protected readonly JsonSerializerSettings _serializerSettings = new JsonSerializerSettings static public readonly JsonSerializerSettings SerializerSettings = new JsonSerializerSettings
{ {
// OpenAPI generated types generally hide default constructors. // OpenAPI generated types generally hide default constructors.
ConstructorHandling = ConstructorHandling.AllowNonPublicDefaultConstructor, ConstructorHandling = ConstructorHandling.AllowNonPublicDefaultConstructor,

View File

@ -32,15 +32,6 @@ namespace Org.OpenAPITools.Model
[DataContract(Name = "fruit")] [DataContract(Name = "fruit")]
public partial class Fruit : AbstractOpenAPISchema, IEquatable<Fruit>, IValidatableObject public partial class Fruit : AbstractOpenAPISchema, IEquatable<Fruit>, IValidatableObject
{ {
/// <summary>
/// Initializes a new instance of the <see cref="Fruit" /> class.
/// </summary>
public Fruit()
{
this.IsNullable = true;
this.SchemaType= "oneOf";
}
/// <summary> /// <summary>
/// Initializes a new instance of the <see cref="Fruit" /> class /// Initializes a new instance of the <see cref="Fruit" /> class
/// with the <see cref="Apple" /> class /// with the <see cref="Apple" /> class
@ -133,7 +124,7 @@ namespace Org.OpenAPITools.Model
/// <returns>JSON string presentation of the object</returns> /// <returns>JSON string presentation of the object</returns>
public override string ToJson() public override string ToJson()
{ {
return JsonConvert.SerializeObject(this.ActualInstance, _serializerSettings); return JsonConvert.SerializeObject(this.ActualInstance, Fruit.SerializerSettings);
} }
/// <summary> /// <summary>
@ -143,32 +134,32 @@ namespace Org.OpenAPITools.Model
/// <returns>An instance of Fruit</returns> /// <returns>An instance of Fruit</returns>
public static Fruit FromJson(string jsonString) public static Fruit FromJson(string jsonString)
{ {
Fruit newFruit = new Fruit(); Fruit newFruit = null;
int match = 0; int match = 0;
List<string> matchedTypes = new List<string>(); List<string> matchedTypes = new List<string>();
try try
{ {
newFruit.ActualInstance = JsonConvert.DeserializeObject<Apple>(jsonString, newFruit._serializerSettings); newFruit = new Fruit(JsonConvert.DeserializeObject<Apple>(jsonString, Fruit.SerializerSettings));
matchedTypes.Add("Apple"); matchedTypes.Add("Apple");
match++; match++;
} }
catch (Exception exception) catch (Exception exception)
{ {
// deserialization failed, try the next one // deserialization failed, try the next one
System.Diagnostics.Debug.WriteLine(String.Format("Failed to deserialize `%s` into Apple: %s", jsonString, exception.ToString())); System.Diagnostics.Debug.WriteLine(String.Format("Failed to deserialize `{0}` into Apple: {1}", jsonString, exception.ToString()));
} }
try try
{ {
newFruit.ActualInstance = JsonConvert.DeserializeObject<Banana>(jsonString, newFruit._serializerSettings); newFruit = new Fruit(JsonConvert.DeserializeObject<Banana>(jsonString, Fruit.SerializerSettings));
matchedTypes.Add("Banana"); matchedTypes.Add("Banana");
match++; match++;
} }
catch (Exception exception) catch (Exception exception)
{ {
// deserialization failed, try the next one // deserialization failed, try the next one
System.Diagnostics.Debug.WriteLine(String.Format("Failed to deserialize `%s` into Banana: %s", jsonString, exception.ToString())); System.Diagnostics.Debug.WriteLine(String.Format("Failed to deserialize `{0}` into Banana: {1}", jsonString, exception.ToString()));
} }
if (match == 0) if (match == 0)

View File

@ -133,7 +133,7 @@ namespace Org.OpenAPITools.Model
/// <returns>JSON string presentation of the object</returns> /// <returns>JSON string presentation of the object</returns>
public override string ToJson() public override string ToJson()
{ {
return JsonConvert.SerializeObject(this.ActualInstance, _serializerSettings); return JsonConvert.SerializeObject(this.ActualInstance, FruitReq.SerializerSettings);
} }
/// <summary> /// <summary>
@ -143,32 +143,32 @@ namespace Org.OpenAPITools.Model
/// <returns>An instance of FruitReq</returns> /// <returns>An instance of FruitReq</returns>
public static FruitReq FromJson(string jsonString) public static FruitReq FromJson(string jsonString)
{ {
FruitReq newFruitReq = new FruitReq(); FruitReq newFruitReq = null;
int match = 0; int match = 0;
List<string> matchedTypes = new List<string>(); List<string> matchedTypes = new List<string>();
try try
{ {
newFruitReq.ActualInstance = JsonConvert.DeserializeObject<AppleReq>(jsonString, newFruitReq._serializerSettings); newFruitReq = new FruitReq(JsonConvert.DeserializeObject<AppleReq>(jsonString, FruitReq.SerializerSettings));
matchedTypes.Add("AppleReq"); matchedTypes.Add("AppleReq");
match++; match++;
} }
catch (Exception exception) catch (Exception exception)
{ {
// deserialization failed, try the next one // deserialization failed, try the next one
System.Diagnostics.Debug.WriteLine(String.Format("Failed to deserialize `%s` into AppleReq: %s", jsonString, exception.ToString())); System.Diagnostics.Debug.WriteLine(String.Format("Failed to deserialize `{0}` into AppleReq: {1}", jsonString, exception.ToString()));
} }
try try
{ {
newFruitReq.ActualInstance = JsonConvert.DeserializeObject<BananaReq>(jsonString, newFruitReq._serializerSettings); newFruitReq = new FruitReq(JsonConvert.DeserializeObject<BananaReq>(jsonString, FruitReq.SerializerSettings));
matchedTypes.Add("BananaReq"); matchedTypes.Add("BananaReq");
match++; match++;
} }
catch (Exception exception) catch (Exception exception)
{ {
// deserialization failed, try the next one // deserialization failed, try the next one
System.Diagnostics.Debug.WriteLine(String.Format("Failed to deserialize `%s` into BananaReq: %s", jsonString, exception.ToString())); System.Diagnostics.Debug.WriteLine(String.Format("Failed to deserialize `{0}` into BananaReq: {1}", jsonString, exception.ToString()));
} }
if (match == 0) if (match == 0)

View File

@ -33,15 +33,6 @@ namespace Org.OpenAPITools.Model
[DataContract(Name = "mammal")] [DataContract(Name = "mammal")]
public partial class Mammal : AbstractOpenAPISchema, IEquatable<Mammal>, IValidatableObject public partial class Mammal : AbstractOpenAPISchema, IEquatable<Mammal>, IValidatableObject
{ {
/// <summary>
/// Initializes a new instance of the <see cref="Mammal" /> class.
/// </summary>
public Mammal()
{
this.IsNullable = true;
this.SchemaType= "oneOf";
}
/// <summary> /// <summary>
/// Initializes a new instance of the <see cref="Mammal" /> class /// Initializes a new instance of the <see cref="Mammal" /> class
/// with the <see cref="Pig" /> class /// with the <see cref="Pig" /> class
@ -160,7 +151,7 @@ namespace Org.OpenAPITools.Model
/// <returns>JSON string presentation of the object</returns> /// <returns>JSON string presentation of the object</returns>
public override string ToJson() public override string ToJson()
{ {
return JsonConvert.SerializeObject(this.ActualInstance, _serializerSettings); return JsonConvert.SerializeObject(this.ActualInstance, Mammal.SerializerSettings);
} }
/// <summary> /// <summary>
@ -170,22 +161,22 @@ namespace Org.OpenAPITools.Model
/// <returns>An instance of Mammal</returns> /// <returns>An instance of Mammal</returns>
public static Mammal FromJson(string jsonString) public static Mammal FromJson(string jsonString)
{ {
Mammal newMammal = new Mammal(); Mammal newMammal = null;
string discriminatorValue = JObject.Parse(jsonString)["className"].ToString(); string discriminatorValue = JObject.Parse(jsonString)["className"].ToString();
switch (discriminatorValue) switch (discriminatorValue)
{ {
case "Pig": case "Pig":
newMammal.ActualInstance = JsonConvert.DeserializeObject<Pig>(jsonString, newMammal._serializerSettings); newMammal = new Mammal(JsonConvert.DeserializeObject<Pig>(jsonString, Mammal.SerializerSettings));
return newMammal; return newMammal;
case "whale": case "whale":
newMammal.ActualInstance = JsonConvert.DeserializeObject<Whale>(jsonString, newMammal._serializerSettings); newMammal = new Mammal(JsonConvert.DeserializeObject<Whale>(jsonString, Mammal.SerializerSettings));
return newMammal; return newMammal;
case "zebra": case "zebra":
newMammal.ActualInstance = JsonConvert.DeserializeObject<Zebra>(jsonString, newMammal._serializerSettings); newMammal = new Mammal(JsonConvert.DeserializeObject<Zebra>(jsonString, Mammal.SerializerSettings));
return newMammal; return newMammal;
default: default:
System.Diagnostics.Debug.WriteLine(String.Format("Failed to lookup discriminator value `%s` for Mammal. Possible values: Pig whale zebra", discriminatorValue)); System.Diagnostics.Debug.WriteLine(String.Format("Failed to lookup discriminator value `{0}` for Mammal. Possible values: Pig whale zebra", discriminatorValue));
break; break;
} }
@ -194,38 +185,38 @@ namespace Org.OpenAPITools.Model
try try
{ {
newMammal.ActualInstance = JsonConvert.DeserializeObject<Pig>(jsonString, newMammal._serializerSettings); newMammal = new Mammal(JsonConvert.DeserializeObject<Pig>(jsonString, Mammal.SerializerSettings));
matchedTypes.Add("Pig"); matchedTypes.Add("Pig");
match++; match++;
} }
catch (Exception exception) catch (Exception exception)
{ {
// deserialization failed, try the next one // deserialization failed, try the next one
System.Diagnostics.Debug.WriteLine(String.Format("Failed to deserialize `%s` into Pig: %s", jsonString, exception.ToString())); System.Diagnostics.Debug.WriteLine(String.Format("Failed to deserialize `{0}` into Pig: {1}", jsonString, exception.ToString()));
} }
try try
{ {
newMammal.ActualInstance = JsonConvert.DeserializeObject<Whale>(jsonString, newMammal._serializerSettings); newMammal = new Mammal(JsonConvert.DeserializeObject<Whale>(jsonString, Mammal.SerializerSettings));
matchedTypes.Add("Whale"); matchedTypes.Add("Whale");
match++; match++;
} }
catch (Exception exception) catch (Exception exception)
{ {
// deserialization failed, try the next one // deserialization failed, try the next one
System.Diagnostics.Debug.WriteLine(String.Format("Failed to deserialize `%s` into Whale: %s", jsonString, exception.ToString())); System.Diagnostics.Debug.WriteLine(String.Format("Failed to deserialize `{0}` into Whale: {1}", jsonString, exception.ToString()));
} }
try try
{ {
newMammal.ActualInstance = JsonConvert.DeserializeObject<Zebra>(jsonString, newMammal._serializerSettings); newMammal = new Mammal(JsonConvert.DeserializeObject<Zebra>(jsonString, Mammal.SerializerSettings));
matchedTypes.Add("Zebra"); matchedTypes.Add("Zebra");
match++; match++;
} }
catch (Exception exception) catch (Exception exception)
{ {
// deserialization failed, try the next one // deserialization failed, try the next one
System.Diagnostics.Debug.WriteLine(String.Format("Failed to deserialize `%s` into Zebra: %s", jsonString, exception.ToString())); System.Diagnostics.Debug.WriteLine(String.Format("Failed to deserialize `{0}` into Zebra: {1}", jsonString, exception.ToString()));
} }
if (match == 0) if (match == 0)

View File

@ -134,7 +134,7 @@ namespace Org.OpenAPITools.Model
/// <returns>JSON string presentation of the object</returns> /// <returns>JSON string presentation of the object</returns>
public override string ToJson() public override string ToJson()
{ {
return JsonConvert.SerializeObject(this.ActualInstance, _serializerSettings); return JsonConvert.SerializeObject(this.ActualInstance, NullableShape.SerializerSettings);
} }
/// <summary> /// <summary>
@ -144,19 +144,19 @@ namespace Org.OpenAPITools.Model
/// <returns>An instance of NullableShape</returns> /// <returns>An instance of NullableShape</returns>
public static NullableShape FromJson(string jsonString) public static NullableShape FromJson(string jsonString)
{ {
NullableShape newNullableShape = new NullableShape(); NullableShape newNullableShape = null;
string discriminatorValue = JObject.Parse(jsonString)["shapeType"].ToString(); string discriminatorValue = JObject.Parse(jsonString)["shapeType"].ToString();
switch (discriminatorValue) switch (discriminatorValue)
{ {
case "Quadrilateral": case "Quadrilateral":
newNullableShape.ActualInstance = JsonConvert.DeserializeObject<Quadrilateral>(jsonString, newNullableShape._serializerSettings); newNullableShape = new NullableShape(JsonConvert.DeserializeObject<Quadrilateral>(jsonString, NullableShape.SerializerSettings));
return newNullableShape; return newNullableShape;
case "Triangle": case "Triangle":
newNullableShape.ActualInstance = JsonConvert.DeserializeObject<Triangle>(jsonString, newNullableShape._serializerSettings); newNullableShape = new NullableShape(JsonConvert.DeserializeObject<Triangle>(jsonString, NullableShape.SerializerSettings));
return newNullableShape; return newNullableShape;
default: default:
System.Diagnostics.Debug.WriteLine(String.Format("Failed to lookup discriminator value `%s` for NullableShape. Possible values: Quadrilateral Triangle", discriminatorValue)); System.Diagnostics.Debug.WriteLine(String.Format("Failed to lookup discriminator value `{0}` for NullableShape. Possible values: Quadrilateral Triangle", discriminatorValue));
break; break;
} }
@ -165,26 +165,26 @@ namespace Org.OpenAPITools.Model
try try
{ {
newNullableShape.ActualInstance = JsonConvert.DeserializeObject<Quadrilateral>(jsonString, newNullableShape._serializerSettings); newNullableShape = new NullableShape(JsonConvert.DeserializeObject<Quadrilateral>(jsonString, NullableShape.SerializerSettings));
matchedTypes.Add("Quadrilateral"); matchedTypes.Add("Quadrilateral");
match++; match++;
} }
catch (Exception exception) catch (Exception exception)
{ {
// deserialization failed, try the next one // deserialization failed, try the next one
System.Diagnostics.Debug.WriteLine(String.Format("Failed to deserialize `%s` into Quadrilateral: %s", jsonString, exception.ToString())); System.Diagnostics.Debug.WriteLine(String.Format("Failed to deserialize `{0}` into Quadrilateral: {1}", jsonString, exception.ToString()));
} }
try try
{ {
newNullableShape.ActualInstance = JsonConvert.DeserializeObject<Triangle>(jsonString, newNullableShape._serializerSettings); newNullableShape = new NullableShape(JsonConvert.DeserializeObject<Triangle>(jsonString, NullableShape.SerializerSettings));
matchedTypes.Add("Triangle"); matchedTypes.Add("Triangle");
match++; match++;
} }
catch (Exception exception) catch (Exception exception)
{ {
// deserialization failed, try the next one // deserialization failed, try the next one
System.Diagnostics.Debug.WriteLine(String.Format("Failed to deserialize `%s` into Triangle: %s", jsonString, exception.ToString())); System.Diagnostics.Debug.WriteLine(String.Format("Failed to deserialize `{0}` into Triangle: {1}", jsonString, exception.ToString()));
} }
if (match == 0) if (match == 0)

View File

@ -33,15 +33,6 @@ namespace Org.OpenAPITools.Model
[DataContract(Name = "Pig")] [DataContract(Name = "Pig")]
public partial class Pig : AbstractOpenAPISchema, IEquatable<Pig>, IValidatableObject public partial class Pig : AbstractOpenAPISchema, IEquatable<Pig>, IValidatableObject
{ {
/// <summary>
/// Initializes a new instance of the <see cref="Pig" /> class.
/// </summary>
public Pig()
{
this.IsNullable = true;
this.SchemaType= "oneOf";
}
/// <summary> /// <summary>
/// Initializes a new instance of the <see cref="Pig" /> class /// Initializes a new instance of the <see cref="Pig" /> class
/// with the <see cref="BasquePig" /> class /// with the <see cref="BasquePig" /> class
@ -134,7 +125,7 @@ namespace Org.OpenAPITools.Model
/// <returns>JSON string presentation of the object</returns> /// <returns>JSON string presentation of the object</returns>
public override string ToJson() public override string ToJson()
{ {
return JsonConvert.SerializeObject(this.ActualInstance, _serializerSettings); return JsonConvert.SerializeObject(this.ActualInstance, Pig.SerializerSettings);
} }
/// <summary> /// <summary>
@ -144,19 +135,19 @@ namespace Org.OpenAPITools.Model
/// <returns>An instance of Pig</returns> /// <returns>An instance of Pig</returns>
public static Pig FromJson(string jsonString) public static Pig FromJson(string jsonString)
{ {
Pig newPig = new Pig(); Pig newPig = null;
string discriminatorValue = JObject.Parse(jsonString)["className"].ToString(); string discriminatorValue = JObject.Parse(jsonString)["className"].ToString();
switch (discriminatorValue) switch (discriminatorValue)
{ {
case "BasquePig": case "BasquePig":
newPig.ActualInstance = JsonConvert.DeserializeObject<BasquePig>(jsonString, newPig._serializerSettings); newPig = new Pig(JsonConvert.DeserializeObject<BasquePig>(jsonString, Pig.SerializerSettings));
return newPig; return newPig;
case "DanishPig": case "DanishPig":
newPig.ActualInstance = JsonConvert.DeserializeObject<DanishPig>(jsonString, newPig._serializerSettings); newPig = new Pig(JsonConvert.DeserializeObject<DanishPig>(jsonString, Pig.SerializerSettings));
return newPig; return newPig;
default: default:
System.Diagnostics.Debug.WriteLine(String.Format("Failed to lookup discriminator value `%s` for Pig. Possible values: BasquePig DanishPig", discriminatorValue)); System.Diagnostics.Debug.WriteLine(String.Format("Failed to lookup discriminator value `{0}` for Pig. Possible values: BasquePig DanishPig", discriminatorValue));
break; break;
} }
@ -165,26 +156,26 @@ namespace Org.OpenAPITools.Model
try try
{ {
newPig.ActualInstance = JsonConvert.DeserializeObject<BasquePig>(jsonString, newPig._serializerSettings); newPig = new Pig(JsonConvert.DeserializeObject<BasquePig>(jsonString, Pig.SerializerSettings));
matchedTypes.Add("BasquePig"); matchedTypes.Add("BasquePig");
match++; match++;
} }
catch (Exception exception) catch (Exception exception)
{ {
// deserialization failed, try the next one // deserialization failed, try the next one
System.Diagnostics.Debug.WriteLine(String.Format("Failed to deserialize `%s` into BasquePig: %s", jsonString, exception.ToString())); System.Diagnostics.Debug.WriteLine(String.Format("Failed to deserialize `{0}` into BasquePig: {1}", jsonString, exception.ToString()));
} }
try try
{ {
newPig.ActualInstance = JsonConvert.DeserializeObject<DanishPig>(jsonString, newPig._serializerSettings); newPig = new Pig(JsonConvert.DeserializeObject<DanishPig>(jsonString, Pig.SerializerSettings));
matchedTypes.Add("DanishPig"); matchedTypes.Add("DanishPig");
match++; match++;
} }
catch (Exception exception) catch (Exception exception)
{ {
// deserialization failed, try the next one // deserialization failed, try the next one
System.Diagnostics.Debug.WriteLine(String.Format("Failed to deserialize `%s` into DanishPig: %s", jsonString, exception.ToString())); System.Diagnostics.Debug.WriteLine(String.Format("Failed to deserialize `{0}` into DanishPig: {1}", jsonString, exception.ToString()));
} }
if (match == 0) if (match == 0)

View File

@ -33,15 +33,6 @@ namespace Org.OpenAPITools.Model
[DataContract(Name = "Quadrilateral")] [DataContract(Name = "Quadrilateral")]
public partial class Quadrilateral : AbstractOpenAPISchema, IEquatable<Quadrilateral>, IValidatableObject public partial class Quadrilateral : AbstractOpenAPISchema, IEquatable<Quadrilateral>, IValidatableObject
{ {
/// <summary>
/// Initializes a new instance of the <see cref="Quadrilateral" /> class.
/// </summary>
public Quadrilateral()
{
this.IsNullable = true;
this.SchemaType= "oneOf";
}
/// <summary> /// <summary>
/// Initializes a new instance of the <see cref="Quadrilateral" /> class /// Initializes a new instance of the <see cref="Quadrilateral" /> class
/// with the <see cref="ComplexQuadrilateral" /> class /// with the <see cref="ComplexQuadrilateral" /> class
@ -134,7 +125,7 @@ namespace Org.OpenAPITools.Model
/// <returns>JSON string presentation of the object</returns> /// <returns>JSON string presentation of the object</returns>
public override string ToJson() public override string ToJson()
{ {
return JsonConvert.SerializeObject(this.ActualInstance, _serializerSettings); return JsonConvert.SerializeObject(this.ActualInstance, Quadrilateral.SerializerSettings);
} }
/// <summary> /// <summary>
@ -144,19 +135,19 @@ namespace Org.OpenAPITools.Model
/// <returns>An instance of Quadrilateral</returns> /// <returns>An instance of Quadrilateral</returns>
public static Quadrilateral FromJson(string jsonString) public static Quadrilateral FromJson(string jsonString)
{ {
Quadrilateral newQuadrilateral = new Quadrilateral(); Quadrilateral newQuadrilateral = null;
string discriminatorValue = JObject.Parse(jsonString)["quadrilateralType"].ToString(); string discriminatorValue = JObject.Parse(jsonString)["quadrilateralType"].ToString();
switch (discriminatorValue) switch (discriminatorValue)
{ {
case "ComplexQuadrilateral": case "ComplexQuadrilateral":
newQuadrilateral.ActualInstance = JsonConvert.DeserializeObject<ComplexQuadrilateral>(jsonString, newQuadrilateral._serializerSettings); newQuadrilateral = new Quadrilateral(JsonConvert.DeserializeObject<ComplexQuadrilateral>(jsonString, Quadrilateral.SerializerSettings));
return newQuadrilateral; return newQuadrilateral;
case "SimpleQuadrilateral": case "SimpleQuadrilateral":
newQuadrilateral.ActualInstance = JsonConvert.DeserializeObject<SimpleQuadrilateral>(jsonString, newQuadrilateral._serializerSettings); newQuadrilateral = new Quadrilateral(JsonConvert.DeserializeObject<SimpleQuadrilateral>(jsonString, Quadrilateral.SerializerSettings));
return newQuadrilateral; return newQuadrilateral;
default: default:
System.Diagnostics.Debug.WriteLine(String.Format("Failed to lookup discriminator value `%s` for Quadrilateral. Possible values: ComplexQuadrilateral SimpleQuadrilateral", discriminatorValue)); System.Diagnostics.Debug.WriteLine(String.Format("Failed to lookup discriminator value `{0}` for Quadrilateral. Possible values: ComplexQuadrilateral SimpleQuadrilateral", discriminatorValue));
break; break;
} }
@ -165,26 +156,26 @@ namespace Org.OpenAPITools.Model
try try
{ {
newQuadrilateral.ActualInstance = JsonConvert.DeserializeObject<ComplexQuadrilateral>(jsonString, newQuadrilateral._serializerSettings); newQuadrilateral = new Quadrilateral(JsonConvert.DeserializeObject<ComplexQuadrilateral>(jsonString, Quadrilateral.SerializerSettings));
matchedTypes.Add("ComplexQuadrilateral"); matchedTypes.Add("ComplexQuadrilateral");
match++; match++;
} }
catch (Exception exception) catch (Exception exception)
{ {
// deserialization failed, try the next one // deserialization failed, try the next one
System.Diagnostics.Debug.WriteLine(String.Format("Failed to deserialize `%s` into ComplexQuadrilateral: %s", jsonString, exception.ToString())); System.Diagnostics.Debug.WriteLine(String.Format("Failed to deserialize `{0}` into ComplexQuadrilateral: {1}", jsonString, exception.ToString()));
} }
try try
{ {
newQuadrilateral.ActualInstance = JsonConvert.DeserializeObject<SimpleQuadrilateral>(jsonString, newQuadrilateral._serializerSettings); newQuadrilateral = new Quadrilateral(JsonConvert.DeserializeObject<SimpleQuadrilateral>(jsonString, Quadrilateral.SerializerSettings));
matchedTypes.Add("SimpleQuadrilateral"); matchedTypes.Add("SimpleQuadrilateral");
match++; match++;
} }
catch (Exception exception) catch (Exception exception)
{ {
// deserialization failed, try the next one // deserialization failed, try the next one
System.Diagnostics.Debug.WriteLine(String.Format("Failed to deserialize `%s` into SimpleQuadrilateral: %s", jsonString, exception.ToString())); System.Diagnostics.Debug.WriteLine(String.Format("Failed to deserialize `{0}` into SimpleQuadrilateral: {1}", jsonString, exception.ToString()));
} }
if (match == 0) if (match == 0)

View File

@ -33,15 +33,6 @@ namespace Org.OpenAPITools.Model
[DataContract(Name = "Shape")] [DataContract(Name = "Shape")]
public partial class Shape : AbstractOpenAPISchema, IEquatable<Shape>, IValidatableObject public partial class Shape : AbstractOpenAPISchema, IEquatable<Shape>, IValidatableObject
{ {
/// <summary>
/// Initializes a new instance of the <see cref="Shape" /> class.
/// </summary>
public Shape()
{
this.IsNullable = true;
this.SchemaType= "oneOf";
}
/// <summary> /// <summary>
/// Initializes a new instance of the <see cref="Shape" /> class /// Initializes a new instance of the <see cref="Shape" /> class
/// with the <see cref="Quadrilateral" /> class /// with the <see cref="Quadrilateral" /> class
@ -134,7 +125,7 @@ namespace Org.OpenAPITools.Model
/// <returns>JSON string presentation of the object</returns> /// <returns>JSON string presentation of the object</returns>
public override string ToJson() public override string ToJson()
{ {
return JsonConvert.SerializeObject(this.ActualInstance, _serializerSettings); return JsonConvert.SerializeObject(this.ActualInstance, Shape.SerializerSettings);
} }
/// <summary> /// <summary>
@ -144,19 +135,19 @@ namespace Org.OpenAPITools.Model
/// <returns>An instance of Shape</returns> /// <returns>An instance of Shape</returns>
public static Shape FromJson(string jsonString) public static Shape FromJson(string jsonString)
{ {
Shape newShape = new Shape(); Shape newShape = null;
string discriminatorValue = JObject.Parse(jsonString)["shapeType"].ToString(); string discriminatorValue = JObject.Parse(jsonString)["shapeType"].ToString();
switch (discriminatorValue) switch (discriminatorValue)
{ {
case "Quadrilateral": case "Quadrilateral":
newShape.ActualInstance = JsonConvert.DeserializeObject<Quadrilateral>(jsonString, newShape._serializerSettings); newShape = new Shape(JsonConvert.DeserializeObject<Quadrilateral>(jsonString, Shape.SerializerSettings));
return newShape; return newShape;
case "Triangle": case "Triangle":
newShape.ActualInstance = JsonConvert.DeserializeObject<Triangle>(jsonString, newShape._serializerSettings); newShape = new Shape(JsonConvert.DeserializeObject<Triangle>(jsonString, Shape.SerializerSettings));
return newShape; return newShape;
default: default:
System.Diagnostics.Debug.WriteLine(String.Format("Failed to lookup discriminator value `%s` for Shape. Possible values: Quadrilateral Triangle", discriminatorValue)); System.Diagnostics.Debug.WriteLine(String.Format("Failed to lookup discriminator value `{0}` for Shape. Possible values: Quadrilateral Triangle", discriminatorValue));
break; break;
} }
@ -165,26 +156,26 @@ namespace Org.OpenAPITools.Model
try try
{ {
newShape.ActualInstance = JsonConvert.DeserializeObject<Quadrilateral>(jsonString, newShape._serializerSettings); newShape = new Shape(JsonConvert.DeserializeObject<Quadrilateral>(jsonString, Shape.SerializerSettings));
matchedTypes.Add("Quadrilateral"); matchedTypes.Add("Quadrilateral");
match++; match++;
} }
catch (Exception exception) catch (Exception exception)
{ {
// deserialization failed, try the next one // deserialization failed, try the next one
System.Diagnostics.Debug.WriteLine(String.Format("Failed to deserialize `%s` into Quadrilateral: %s", jsonString, exception.ToString())); System.Diagnostics.Debug.WriteLine(String.Format("Failed to deserialize `{0}` into Quadrilateral: {1}", jsonString, exception.ToString()));
} }
try try
{ {
newShape.ActualInstance = JsonConvert.DeserializeObject<Triangle>(jsonString, newShape._serializerSettings); newShape = new Shape(JsonConvert.DeserializeObject<Triangle>(jsonString, Shape.SerializerSettings));
matchedTypes.Add("Triangle"); matchedTypes.Add("Triangle");
match++; match++;
} }
catch (Exception exception) catch (Exception exception)
{ {
// deserialization failed, try the next one // deserialization failed, try the next one
System.Diagnostics.Debug.WriteLine(String.Format("Failed to deserialize `%s` into Triangle: %s", jsonString, exception.ToString())); System.Diagnostics.Debug.WriteLine(String.Format("Failed to deserialize `{0}` into Triangle: {1}", jsonString, exception.ToString()));
} }
if (match == 0) if (match == 0)

View File

@ -134,7 +134,7 @@ namespace Org.OpenAPITools.Model
/// <returns>JSON string presentation of the object</returns> /// <returns>JSON string presentation of the object</returns>
public override string ToJson() public override string ToJson()
{ {
return JsonConvert.SerializeObject(this.ActualInstance, _serializerSettings); return JsonConvert.SerializeObject(this.ActualInstance, ShapeOrNull.SerializerSettings);
} }
/// <summary> /// <summary>
@ -144,19 +144,19 @@ namespace Org.OpenAPITools.Model
/// <returns>An instance of ShapeOrNull</returns> /// <returns>An instance of ShapeOrNull</returns>
public static ShapeOrNull FromJson(string jsonString) public static ShapeOrNull FromJson(string jsonString)
{ {
ShapeOrNull newShapeOrNull = new ShapeOrNull(); ShapeOrNull newShapeOrNull = null;
string discriminatorValue = JObject.Parse(jsonString)["shapeType"].ToString(); string discriminatorValue = JObject.Parse(jsonString)["shapeType"].ToString();
switch (discriminatorValue) switch (discriminatorValue)
{ {
case "Quadrilateral": case "Quadrilateral":
newShapeOrNull.ActualInstance = JsonConvert.DeserializeObject<Quadrilateral>(jsonString, newShapeOrNull._serializerSettings); newShapeOrNull = new ShapeOrNull(JsonConvert.DeserializeObject<Quadrilateral>(jsonString, ShapeOrNull.SerializerSettings));
return newShapeOrNull; return newShapeOrNull;
case "Triangle": case "Triangle":
newShapeOrNull.ActualInstance = JsonConvert.DeserializeObject<Triangle>(jsonString, newShapeOrNull._serializerSettings); newShapeOrNull = new ShapeOrNull(JsonConvert.DeserializeObject<Triangle>(jsonString, ShapeOrNull.SerializerSettings));
return newShapeOrNull; return newShapeOrNull;
default: default:
System.Diagnostics.Debug.WriteLine(String.Format("Failed to lookup discriminator value `%s` for ShapeOrNull. Possible values: Quadrilateral Triangle", discriminatorValue)); System.Diagnostics.Debug.WriteLine(String.Format("Failed to lookup discriminator value `{0}` for ShapeOrNull. Possible values: Quadrilateral Triangle", discriminatorValue));
break; break;
} }
@ -165,26 +165,26 @@ namespace Org.OpenAPITools.Model
try try
{ {
newShapeOrNull.ActualInstance = JsonConvert.DeserializeObject<Quadrilateral>(jsonString, newShapeOrNull._serializerSettings); newShapeOrNull = new ShapeOrNull(JsonConvert.DeserializeObject<Quadrilateral>(jsonString, ShapeOrNull.SerializerSettings));
matchedTypes.Add("Quadrilateral"); matchedTypes.Add("Quadrilateral");
match++; match++;
} }
catch (Exception exception) catch (Exception exception)
{ {
// deserialization failed, try the next one // deserialization failed, try the next one
System.Diagnostics.Debug.WriteLine(String.Format("Failed to deserialize `%s` into Quadrilateral: %s", jsonString, exception.ToString())); System.Diagnostics.Debug.WriteLine(String.Format("Failed to deserialize `{0}` into Quadrilateral: {1}", jsonString, exception.ToString()));
} }
try try
{ {
newShapeOrNull.ActualInstance = JsonConvert.DeserializeObject<Triangle>(jsonString, newShapeOrNull._serializerSettings); newShapeOrNull = new ShapeOrNull(JsonConvert.DeserializeObject<Triangle>(jsonString, ShapeOrNull.SerializerSettings));
matchedTypes.Add("Triangle"); matchedTypes.Add("Triangle");
match++; match++;
} }
catch (Exception exception) catch (Exception exception)
{ {
// deserialization failed, try the next one // deserialization failed, try the next one
System.Diagnostics.Debug.WriteLine(String.Format("Failed to deserialize `%s` into Triangle: %s", jsonString, exception.ToString())); System.Diagnostics.Debug.WriteLine(String.Format("Failed to deserialize `{0}` into Triangle: {1}", jsonString, exception.ToString()));
} }
if (match == 0) if (match == 0)

View File

@ -33,15 +33,6 @@ namespace Org.OpenAPITools.Model
[DataContract(Name = "Triangle")] [DataContract(Name = "Triangle")]
public partial class Triangle : AbstractOpenAPISchema, IEquatable<Triangle>, IValidatableObject public partial class Triangle : AbstractOpenAPISchema, IEquatable<Triangle>, IValidatableObject
{ {
/// <summary>
/// Initializes a new instance of the <see cref="Triangle" /> class.
/// </summary>
public Triangle()
{
this.IsNullable = true;
this.SchemaType= "oneOf";
}
/// <summary> /// <summary>
/// Initializes a new instance of the <see cref="Triangle" /> class /// Initializes a new instance of the <see cref="Triangle" /> class
/// with the <see cref="EquilateralTriangle" /> class /// with the <see cref="EquilateralTriangle" /> class
@ -160,7 +151,7 @@ namespace Org.OpenAPITools.Model
/// <returns>JSON string presentation of the object</returns> /// <returns>JSON string presentation of the object</returns>
public override string ToJson() public override string ToJson()
{ {
return JsonConvert.SerializeObject(this.ActualInstance, _serializerSettings); return JsonConvert.SerializeObject(this.ActualInstance, Triangle.SerializerSettings);
} }
/// <summary> /// <summary>
@ -170,22 +161,22 @@ namespace Org.OpenAPITools.Model
/// <returns>An instance of Triangle</returns> /// <returns>An instance of Triangle</returns>
public static Triangle FromJson(string jsonString) public static Triangle FromJson(string jsonString)
{ {
Triangle newTriangle = new Triangle(); Triangle newTriangle = null;
string discriminatorValue = JObject.Parse(jsonString)["triangleType"].ToString(); string discriminatorValue = JObject.Parse(jsonString)["triangleType"].ToString();
switch (discriminatorValue) switch (discriminatorValue)
{ {
case "EquilateralTriangle": case "EquilateralTriangle":
newTriangle.ActualInstance = JsonConvert.DeserializeObject<EquilateralTriangle>(jsonString, newTriangle._serializerSettings); newTriangle = new Triangle(JsonConvert.DeserializeObject<EquilateralTriangle>(jsonString, Triangle.SerializerSettings));
return newTriangle; return newTriangle;
case "IsoscelesTriangle": case "IsoscelesTriangle":
newTriangle.ActualInstance = JsonConvert.DeserializeObject<IsoscelesTriangle>(jsonString, newTriangle._serializerSettings); newTriangle = new Triangle(JsonConvert.DeserializeObject<IsoscelesTriangle>(jsonString, Triangle.SerializerSettings));
return newTriangle; return newTriangle;
case "ScaleneTriangle": case "ScaleneTriangle":
newTriangle.ActualInstance = JsonConvert.DeserializeObject<ScaleneTriangle>(jsonString, newTriangle._serializerSettings); newTriangle = new Triangle(JsonConvert.DeserializeObject<ScaleneTriangle>(jsonString, Triangle.SerializerSettings));
return newTriangle; return newTriangle;
default: default:
System.Diagnostics.Debug.WriteLine(String.Format("Failed to lookup discriminator value `%s` for Triangle. Possible values: EquilateralTriangle IsoscelesTriangle ScaleneTriangle", discriminatorValue)); System.Diagnostics.Debug.WriteLine(String.Format("Failed to lookup discriminator value `{0}` for Triangle. Possible values: EquilateralTriangle IsoscelesTriangle ScaleneTriangle", discriminatorValue));
break; break;
} }
@ -194,38 +185,38 @@ namespace Org.OpenAPITools.Model
try try
{ {
newTriangle.ActualInstance = JsonConvert.DeserializeObject<EquilateralTriangle>(jsonString, newTriangle._serializerSettings); newTriangle = new Triangle(JsonConvert.DeserializeObject<EquilateralTriangle>(jsonString, Triangle.SerializerSettings));
matchedTypes.Add("EquilateralTriangle"); matchedTypes.Add("EquilateralTriangle");
match++; match++;
} }
catch (Exception exception) catch (Exception exception)
{ {
// deserialization failed, try the next one // deserialization failed, try the next one
System.Diagnostics.Debug.WriteLine(String.Format("Failed to deserialize `%s` into EquilateralTriangle: %s", jsonString, exception.ToString())); System.Diagnostics.Debug.WriteLine(String.Format("Failed to deserialize `{0}` into EquilateralTriangle: {1}", jsonString, exception.ToString()));
} }
try try
{ {
newTriangle.ActualInstance = JsonConvert.DeserializeObject<IsoscelesTriangle>(jsonString, newTriangle._serializerSettings); newTriangle = new Triangle(JsonConvert.DeserializeObject<IsoscelesTriangle>(jsonString, Triangle.SerializerSettings));
matchedTypes.Add("IsoscelesTriangle"); matchedTypes.Add("IsoscelesTriangle");
match++; match++;
} }
catch (Exception exception) catch (Exception exception)
{ {
// deserialization failed, try the next one // deserialization failed, try the next one
System.Diagnostics.Debug.WriteLine(String.Format("Failed to deserialize `%s` into IsoscelesTriangle: %s", jsonString, exception.ToString())); System.Diagnostics.Debug.WriteLine(String.Format("Failed to deserialize `{0}` into IsoscelesTriangle: {1}", jsonString, exception.ToString()));
} }
try try
{ {
newTriangle.ActualInstance = JsonConvert.DeserializeObject<ScaleneTriangle>(jsonString, newTriangle._serializerSettings); newTriangle = new Triangle(JsonConvert.DeserializeObject<ScaleneTriangle>(jsonString, Triangle.SerializerSettings));
matchedTypes.Add("ScaleneTriangle"); matchedTypes.Add("ScaleneTriangle");
match++; match++;
} }
catch (Exception exception) catch (Exception exception)
{ {
// deserialization failed, try the next one // deserialization failed, try the next one
System.Diagnostics.Debug.WriteLine(String.Format("Failed to deserialize `%s` into ScaleneTriangle: %s", jsonString, exception.ToString())); System.Diagnostics.Debug.WriteLine(String.Format("Failed to deserialize `{0}` into ScaleneTriangle: {1}", jsonString, exception.ToString()));
} }
if (match == 0) if (match == 0)

View File

@ -22,7 +22,7 @@ namespace Org.OpenAPITools.Model
/// <summary> /// <summary>
/// Custom JSON serializer /// Custom JSON serializer
/// </summary> /// </summary>
protected readonly JsonSerializerSettings _serializerSettings = new JsonSerializerSettings static public readonly JsonSerializerSettings SerializerSettings = new JsonSerializerSettings
{ {
// OpenAPI generated types generally hide default constructors. // OpenAPI generated types generally hide default constructors.
ConstructorHandling = ConstructorHandling.AllowNonPublicDefaultConstructor, ConstructorHandling = ConstructorHandling.AllowNonPublicDefaultConstructor,

View File

@ -32,15 +32,6 @@ namespace Org.OpenAPITools.Model
[DataContract(Name = "fruit")] [DataContract(Name = "fruit")]
public partial class Fruit : AbstractOpenAPISchema, IEquatable<Fruit>, IValidatableObject public partial class Fruit : AbstractOpenAPISchema, IEquatable<Fruit>, IValidatableObject
{ {
/// <summary>
/// Initializes a new instance of the <see cref="Fruit" /> class.
/// </summary>
public Fruit()
{
this.IsNullable = true;
this.SchemaType= "oneOf";
}
/// <summary> /// <summary>
/// Initializes a new instance of the <see cref="Fruit" /> class /// Initializes a new instance of the <see cref="Fruit" /> class
/// with the <see cref="Apple" /> class /// with the <see cref="Apple" /> class
@ -133,7 +124,7 @@ namespace Org.OpenAPITools.Model
/// <returns>JSON string presentation of the object</returns> /// <returns>JSON string presentation of the object</returns>
public override string ToJson() public override string ToJson()
{ {
return JsonConvert.SerializeObject(this.ActualInstance, _serializerSettings); return JsonConvert.SerializeObject(this.ActualInstance, Fruit.SerializerSettings);
} }
/// <summary> /// <summary>
@ -143,32 +134,32 @@ namespace Org.OpenAPITools.Model
/// <returns>An instance of Fruit</returns> /// <returns>An instance of Fruit</returns>
public static Fruit FromJson(string jsonString) public static Fruit FromJson(string jsonString)
{ {
Fruit newFruit = new Fruit(); Fruit newFruit = null;
int match = 0; int match = 0;
List<string> matchedTypes = new List<string>(); List<string> matchedTypes = new List<string>();
try try
{ {
newFruit.ActualInstance = JsonConvert.DeserializeObject<Apple>(jsonString, newFruit._serializerSettings); newFruit = new Fruit(JsonConvert.DeserializeObject<Apple>(jsonString, Fruit.SerializerSettings));
matchedTypes.Add("Apple"); matchedTypes.Add("Apple");
match++; match++;
} }
catch (Exception exception) catch (Exception exception)
{ {
// deserialization failed, try the next one // deserialization failed, try the next one
System.Diagnostics.Debug.WriteLine(String.Format("Failed to deserialize `%s` into Apple: %s", jsonString, exception.ToString())); System.Diagnostics.Debug.WriteLine(String.Format("Failed to deserialize `{0}` into Apple: {1}", jsonString, exception.ToString()));
} }
try try
{ {
newFruit.ActualInstance = JsonConvert.DeserializeObject<Banana>(jsonString, newFruit._serializerSettings); newFruit = new Fruit(JsonConvert.DeserializeObject<Banana>(jsonString, Fruit.SerializerSettings));
matchedTypes.Add("Banana"); matchedTypes.Add("Banana");
match++; match++;
} }
catch (Exception exception) catch (Exception exception)
{ {
// deserialization failed, try the next one // deserialization failed, try the next one
System.Diagnostics.Debug.WriteLine(String.Format("Failed to deserialize `%s` into Banana: %s", jsonString, exception.ToString())); System.Diagnostics.Debug.WriteLine(String.Format("Failed to deserialize `{0}` into Banana: {1}", jsonString, exception.ToString()));
} }
if (match == 0) if (match == 0)

View File

@ -133,7 +133,7 @@ namespace Org.OpenAPITools.Model
/// <returns>JSON string presentation of the object</returns> /// <returns>JSON string presentation of the object</returns>
public override string ToJson() public override string ToJson()
{ {
return JsonConvert.SerializeObject(this.ActualInstance, _serializerSettings); return JsonConvert.SerializeObject(this.ActualInstance, FruitReq.SerializerSettings);
} }
/// <summary> /// <summary>
@ -143,32 +143,32 @@ namespace Org.OpenAPITools.Model
/// <returns>An instance of FruitReq</returns> /// <returns>An instance of FruitReq</returns>
public static FruitReq FromJson(string jsonString) public static FruitReq FromJson(string jsonString)
{ {
FruitReq newFruitReq = new FruitReq(); FruitReq newFruitReq = null;
int match = 0; int match = 0;
List<string> matchedTypes = new List<string>(); List<string> matchedTypes = new List<string>();
try try
{ {
newFruitReq.ActualInstance = JsonConvert.DeserializeObject<AppleReq>(jsonString, newFruitReq._serializerSettings); newFruitReq = new FruitReq(JsonConvert.DeserializeObject<AppleReq>(jsonString, FruitReq.SerializerSettings));
matchedTypes.Add("AppleReq"); matchedTypes.Add("AppleReq");
match++; match++;
} }
catch (Exception exception) catch (Exception exception)
{ {
// deserialization failed, try the next one // deserialization failed, try the next one
System.Diagnostics.Debug.WriteLine(String.Format("Failed to deserialize `%s` into AppleReq: %s", jsonString, exception.ToString())); System.Diagnostics.Debug.WriteLine(String.Format("Failed to deserialize `{0}` into AppleReq: {1}", jsonString, exception.ToString()));
} }
try try
{ {
newFruitReq.ActualInstance = JsonConvert.DeserializeObject<BananaReq>(jsonString, newFruitReq._serializerSettings); newFruitReq = new FruitReq(JsonConvert.DeserializeObject<BananaReq>(jsonString, FruitReq.SerializerSettings));
matchedTypes.Add("BananaReq"); matchedTypes.Add("BananaReq");
match++; match++;
} }
catch (Exception exception) catch (Exception exception)
{ {
// deserialization failed, try the next one // deserialization failed, try the next one
System.Diagnostics.Debug.WriteLine(String.Format("Failed to deserialize `%s` into BananaReq: %s", jsonString, exception.ToString())); System.Diagnostics.Debug.WriteLine(String.Format("Failed to deserialize `{0}` into BananaReq: {1}", jsonString, exception.ToString()));
} }
if (match == 0) if (match == 0)

View File

@ -33,15 +33,6 @@ namespace Org.OpenAPITools.Model
[DataContract(Name = "mammal")] [DataContract(Name = "mammal")]
public partial class Mammal : AbstractOpenAPISchema, IEquatable<Mammal>, IValidatableObject public partial class Mammal : AbstractOpenAPISchema, IEquatable<Mammal>, IValidatableObject
{ {
/// <summary>
/// Initializes a new instance of the <see cref="Mammal" /> class.
/// </summary>
public Mammal()
{
this.IsNullable = true;
this.SchemaType= "oneOf";
}
/// <summary> /// <summary>
/// Initializes a new instance of the <see cref="Mammal" /> class /// Initializes a new instance of the <see cref="Mammal" /> class
/// with the <see cref="Pig" /> class /// with the <see cref="Pig" /> class
@ -160,7 +151,7 @@ namespace Org.OpenAPITools.Model
/// <returns>JSON string presentation of the object</returns> /// <returns>JSON string presentation of the object</returns>
public override string ToJson() public override string ToJson()
{ {
return JsonConvert.SerializeObject(this.ActualInstance, _serializerSettings); return JsonConvert.SerializeObject(this.ActualInstance, Mammal.SerializerSettings);
} }
/// <summary> /// <summary>
@ -170,44 +161,44 @@ namespace Org.OpenAPITools.Model
/// <returns>An instance of Mammal</returns> /// <returns>An instance of Mammal</returns>
public static Mammal FromJson(string jsonString) public static Mammal FromJson(string jsonString)
{ {
Mammal newMammal = new Mammal(); Mammal newMammal = null;
int match = 0; int match = 0;
List<string> matchedTypes = new List<string>(); List<string> matchedTypes = new List<string>();
try try
{ {
newMammal.ActualInstance = JsonConvert.DeserializeObject<Pig>(jsonString, newMammal._serializerSettings); newMammal = new Mammal(JsonConvert.DeserializeObject<Pig>(jsonString, Mammal.SerializerSettings));
matchedTypes.Add("Pig"); matchedTypes.Add("Pig");
match++; match++;
} }
catch (Exception exception) catch (Exception exception)
{ {
// deserialization failed, try the next one // deserialization failed, try the next one
System.Diagnostics.Debug.WriteLine(String.Format("Failed to deserialize `%s` into Pig: %s", jsonString, exception.ToString())); System.Diagnostics.Debug.WriteLine(String.Format("Failed to deserialize `{0}` into Pig: {1}", jsonString, exception.ToString()));
} }
try try
{ {
newMammal.ActualInstance = JsonConvert.DeserializeObject<Whale>(jsonString, newMammal._serializerSettings); newMammal = new Mammal(JsonConvert.DeserializeObject<Whale>(jsonString, Mammal.SerializerSettings));
matchedTypes.Add("Whale"); matchedTypes.Add("Whale");
match++; match++;
} }
catch (Exception exception) catch (Exception exception)
{ {
// deserialization failed, try the next one // deserialization failed, try the next one
System.Diagnostics.Debug.WriteLine(String.Format("Failed to deserialize `%s` into Whale: %s", jsonString, exception.ToString())); System.Diagnostics.Debug.WriteLine(String.Format("Failed to deserialize `{0}` into Whale: {1}", jsonString, exception.ToString()));
} }
try try
{ {
newMammal.ActualInstance = JsonConvert.DeserializeObject<Zebra>(jsonString, newMammal._serializerSettings); newMammal = new Mammal(JsonConvert.DeserializeObject<Zebra>(jsonString, Mammal.SerializerSettings));
matchedTypes.Add("Zebra"); matchedTypes.Add("Zebra");
match++; match++;
} }
catch (Exception exception) catch (Exception exception)
{ {
// deserialization failed, try the next one // deserialization failed, try the next one
System.Diagnostics.Debug.WriteLine(String.Format("Failed to deserialize `%s` into Zebra: %s", jsonString, exception.ToString())); System.Diagnostics.Debug.WriteLine(String.Format("Failed to deserialize `{0}` into Zebra: {1}", jsonString, exception.ToString()));
} }
if (match == 0) if (match == 0)

View File

@ -134,7 +134,7 @@ namespace Org.OpenAPITools.Model
/// <returns>JSON string presentation of the object</returns> /// <returns>JSON string presentation of the object</returns>
public override string ToJson() public override string ToJson()
{ {
return JsonConvert.SerializeObject(this.ActualInstance, _serializerSettings); return JsonConvert.SerializeObject(this.ActualInstance, NullableShape.SerializerSettings);
} }
/// <summary> /// <summary>
@ -144,32 +144,32 @@ namespace Org.OpenAPITools.Model
/// <returns>An instance of NullableShape</returns> /// <returns>An instance of NullableShape</returns>
public static NullableShape FromJson(string jsonString) public static NullableShape FromJson(string jsonString)
{ {
NullableShape newNullableShape = new NullableShape(); NullableShape newNullableShape = null;
int match = 0; int match = 0;
List<string> matchedTypes = new List<string>(); List<string> matchedTypes = new List<string>();
try try
{ {
newNullableShape.ActualInstance = JsonConvert.DeserializeObject<Quadrilateral>(jsonString, newNullableShape._serializerSettings); newNullableShape = new NullableShape(JsonConvert.DeserializeObject<Quadrilateral>(jsonString, NullableShape.SerializerSettings));
matchedTypes.Add("Quadrilateral"); matchedTypes.Add("Quadrilateral");
match++; match++;
} }
catch (Exception exception) catch (Exception exception)
{ {
// deserialization failed, try the next one // deserialization failed, try the next one
System.Diagnostics.Debug.WriteLine(String.Format("Failed to deserialize `%s` into Quadrilateral: %s", jsonString, exception.ToString())); System.Diagnostics.Debug.WriteLine(String.Format("Failed to deserialize `{0}` into Quadrilateral: {1}", jsonString, exception.ToString()));
} }
try try
{ {
newNullableShape.ActualInstance = JsonConvert.DeserializeObject<Triangle>(jsonString, newNullableShape._serializerSettings); newNullableShape = new NullableShape(JsonConvert.DeserializeObject<Triangle>(jsonString, NullableShape.SerializerSettings));
matchedTypes.Add("Triangle"); matchedTypes.Add("Triangle");
match++; match++;
} }
catch (Exception exception) catch (Exception exception)
{ {
// deserialization failed, try the next one // deserialization failed, try the next one
System.Diagnostics.Debug.WriteLine(String.Format("Failed to deserialize `%s` into Triangle: %s", jsonString, exception.ToString())); System.Diagnostics.Debug.WriteLine(String.Format("Failed to deserialize `{0}` into Triangle: {1}", jsonString, exception.ToString()));
} }
if (match == 0) if (match == 0)

View File

@ -33,15 +33,6 @@ namespace Org.OpenAPITools.Model
[DataContract(Name = "Pig")] [DataContract(Name = "Pig")]
public partial class Pig : AbstractOpenAPISchema, IEquatable<Pig>, IValidatableObject public partial class Pig : AbstractOpenAPISchema, IEquatable<Pig>, IValidatableObject
{ {
/// <summary>
/// Initializes a new instance of the <see cref="Pig" /> class.
/// </summary>
public Pig()
{
this.IsNullable = true;
this.SchemaType= "oneOf";
}
/// <summary> /// <summary>
/// Initializes a new instance of the <see cref="Pig" /> class /// Initializes a new instance of the <see cref="Pig" /> class
/// with the <see cref="BasquePig" /> class /// with the <see cref="BasquePig" /> class
@ -134,7 +125,7 @@ namespace Org.OpenAPITools.Model
/// <returns>JSON string presentation of the object</returns> /// <returns>JSON string presentation of the object</returns>
public override string ToJson() public override string ToJson()
{ {
return JsonConvert.SerializeObject(this.ActualInstance, _serializerSettings); return JsonConvert.SerializeObject(this.ActualInstance, Pig.SerializerSettings);
} }
/// <summary> /// <summary>
@ -144,32 +135,32 @@ namespace Org.OpenAPITools.Model
/// <returns>An instance of Pig</returns> /// <returns>An instance of Pig</returns>
public static Pig FromJson(string jsonString) public static Pig FromJson(string jsonString)
{ {
Pig newPig = new Pig(); Pig newPig = null;
int match = 0; int match = 0;
List<string> matchedTypes = new List<string>(); List<string> matchedTypes = new List<string>();
try try
{ {
newPig.ActualInstance = JsonConvert.DeserializeObject<BasquePig>(jsonString, newPig._serializerSettings); newPig = new Pig(JsonConvert.DeserializeObject<BasquePig>(jsonString, Pig.SerializerSettings));
matchedTypes.Add("BasquePig"); matchedTypes.Add("BasquePig");
match++; match++;
} }
catch (Exception exception) catch (Exception exception)
{ {
// deserialization failed, try the next one // deserialization failed, try the next one
System.Diagnostics.Debug.WriteLine(String.Format("Failed to deserialize `%s` into BasquePig: %s", jsonString, exception.ToString())); System.Diagnostics.Debug.WriteLine(String.Format("Failed to deserialize `{0}` into BasquePig: {1}", jsonString, exception.ToString()));
} }
try try
{ {
newPig.ActualInstance = JsonConvert.DeserializeObject<DanishPig>(jsonString, newPig._serializerSettings); newPig = new Pig(JsonConvert.DeserializeObject<DanishPig>(jsonString, Pig.SerializerSettings));
matchedTypes.Add("DanishPig"); matchedTypes.Add("DanishPig");
match++; match++;
} }
catch (Exception exception) catch (Exception exception)
{ {
// deserialization failed, try the next one // deserialization failed, try the next one
System.Diagnostics.Debug.WriteLine(String.Format("Failed to deserialize `%s` into DanishPig: %s", jsonString, exception.ToString())); System.Diagnostics.Debug.WriteLine(String.Format("Failed to deserialize `{0}` into DanishPig: {1}", jsonString, exception.ToString()));
} }
if (match == 0) if (match == 0)

View File

@ -33,15 +33,6 @@ namespace Org.OpenAPITools.Model
[DataContract(Name = "Quadrilateral")] [DataContract(Name = "Quadrilateral")]
public partial class Quadrilateral : AbstractOpenAPISchema, IEquatable<Quadrilateral>, IValidatableObject public partial class Quadrilateral : AbstractOpenAPISchema, IEquatable<Quadrilateral>, IValidatableObject
{ {
/// <summary>
/// Initializes a new instance of the <see cref="Quadrilateral" /> class.
/// </summary>
public Quadrilateral()
{
this.IsNullable = true;
this.SchemaType= "oneOf";
}
/// <summary> /// <summary>
/// Initializes a new instance of the <see cref="Quadrilateral" /> class /// Initializes a new instance of the <see cref="Quadrilateral" /> class
/// with the <see cref="ComplexQuadrilateral" /> class /// with the <see cref="ComplexQuadrilateral" /> class
@ -134,7 +125,7 @@ namespace Org.OpenAPITools.Model
/// <returns>JSON string presentation of the object</returns> /// <returns>JSON string presentation of the object</returns>
public override string ToJson() public override string ToJson()
{ {
return JsonConvert.SerializeObject(this.ActualInstance, _serializerSettings); return JsonConvert.SerializeObject(this.ActualInstance, Quadrilateral.SerializerSettings);
} }
/// <summary> /// <summary>
@ -144,32 +135,32 @@ namespace Org.OpenAPITools.Model
/// <returns>An instance of Quadrilateral</returns> /// <returns>An instance of Quadrilateral</returns>
public static Quadrilateral FromJson(string jsonString) public static Quadrilateral FromJson(string jsonString)
{ {
Quadrilateral newQuadrilateral = new Quadrilateral(); Quadrilateral newQuadrilateral = null;
int match = 0; int match = 0;
List<string> matchedTypes = new List<string>(); List<string> matchedTypes = new List<string>();
try try
{ {
newQuadrilateral.ActualInstance = JsonConvert.DeserializeObject<ComplexQuadrilateral>(jsonString, newQuadrilateral._serializerSettings); newQuadrilateral = new Quadrilateral(JsonConvert.DeserializeObject<ComplexQuadrilateral>(jsonString, Quadrilateral.SerializerSettings));
matchedTypes.Add("ComplexQuadrilateral"); matchedTypes.Add("ComplexQuadrilateral");
match++; match++;
} }
catch (Exception exception) catch (Exception exception)
{ {
// deserialization failed, try the next one // deserialization failed, try the next one
System.Diagnostics.Debug.WriteLine(String.Format("Failed to deserialize `%s` into ComplexQuadrilateral: %s", jsonString, exception.ToString())); System.Diagnostics.Debug.WriteLine(String.Format("Failed to deserialize `{0}` into ComplexQuadrilateral: {1}", jsonString, exception.ToString()));
} }
try try
{ {
newQuadrilateral.ActualInstance = JsonConvert.DeserializeObject<SimpleQuadrilateral>(jsonString, newQuadrilateral._serializerSettings); newQuadrilateral = new Quadrilateral(JsonConvert.DeserializeObject<SimpleQuadrilateral>(jsonString, Quadrilateral.SerializerSettings));
matchedTypes.Add("SimpleQuadrilateral"); matchedTypes.Add("SimpleQuadrilateral");
match++; match++;
} }
catch (Exception exception) catch (Exception exception)
{ {
// deserialization failed, try the next one // deserialization failed, try the next one
System.Diagnostics.Debug.WriteLine(String.Format("Failed to deserialize `%s` into SimpleQuadrilateral: %s", jsonString, exception.ToString())); System.Diagnostics.Debug.WriteLine(String.Format("Failed to deserialize `{0}` into SimpleQuadrilateral: {1}", jsonString, exception.ToString()));
} }
if (match == 0) if (match == 0)

View File

@ -33,15 +33,6 @@ namespace Org.OpenAPITools.Model
[DataContract(Name = "Shape")] [DataContract(Name = "Shape")]
public partial class Shape : AbstractOpenAPISchema, IEquatable<Shape>, IValidatableObject public partial class Shape : AbstractOpenAPISchema, IEquatable<Shape>, IValidatableObject
{ {
/// <summary>
/// Initializes a new instance of the <see cref="Shape" /> class.
/// </summary>
public Shape()
{
this.IsNullable = true;
this.SchemaType= "oneOf";
}
/// <summary> /// <summary>
/// Initializes a new instance of the <see cref="Shape" /> class /// Initializes a new instance of the <see cref="Shape" /> class
/// with the <see cref="Quadrilateral" /> class /// with the <see cref="Quadrilateral" /> class
@ -134,7 +125,7 @@ namespace Org.OpenAPITools.Model
/// <returns>JSON string presentation of the object</returns> /// <returns>JSON string presentation of the object</returns>
public override string ToJson() public override string ToJson()
{ {
return JsonConvert.SerializeObject(this.ActualInstance, _serializerSettings); return JsonConvert.SerializeObject(this.ActualInstance, Shape.SerializerSettings);
} }
/// <summary> /// <summary>
@ -144,32 +135,32 @@ namespace Org.OpenAPITools.Model
/// <returns>An instance of Shape</returns> /// <returns>An instance of Shape</returns>
public static Shape FromJson(string jsonString) public static Shape FromJson(string jsonString)
{ {
Shape newShape = new Shape(); Shape newShape = null;
int match = 0; int match = 0;
List<string> matchedTypes = new List<string>(); List<string> matchedTypes = new List<string>();
try try
{ {
newShape.ActualInstance = JsonConvert.DeserializeObject<Quadrilateral>(jsonString, newShape._serializerSettings); newShape = new Shape(JsonConvert.DeserializeObject<Quadrilateral>(jsonString, Shape.SerializerSettings));
matchedTypes.Add("Quadrilateral"); matchedTypes.Add("Quadrilateral");
match++; match++;
} }
catch (Exception exception) catch (Exception exception)
{ {
// deserialization failed, try the next one // deserialization failed, try the next one
System.Diagnostics.Debug.WriteLine(String.Format("Failed to deserialize `%s` into Quadrilateral: %s", jsonString, exception.ToString())); System.Diagnostics.Debug.WriteLine(String.Format("Failed to deserialize `{0}` into Quadrilateral: {1}", jsonString, exception.ToString()));
} }
try try
{ {
newShape.ActualInstance = JsonConvert.DeserializeObject<Triangle>(jsonString, newShape._serializerSettings); newShape = new Shape(JsonConvert.DeserializeObject<Triangle>(jsonString, Shape.SerializerSettings));
matchedTypes.Add("Triangle"); matchedTypes.Add("Triangle");
match++; match++;
} }
catch (Exception exception) catch (Exception exception)
{ {
// deserialization failed, try the next one // deserialization failed, try the next one
System.Diagnostics.Debug.WriteLine(String.Format("Failed to deserialize `%s` into Triangle: %s", jsonString, exception.ToString())); System.Diagnostics.Debug.WriteLine(String.Format("Failed to deserialize `{0}` into Triangle: {1}", jsonString, exception.ToString()));
} }
if (match == 0) if (match == 0)

View File

@ -134,7 +134,7 @@ namespace Org.OpenAPITools.Model
/// <returns>JSON string presentation of the object</returns> /// <returns>JSON string presentation of the object</returns>
public override string ToJson() public override string ToJson()
{ {
return JsonConvert.SerializeObject(this.ActualInstance, _serializerSettings); return JsonConvert.SerializeObject(this.ActualInstance, ShapeOrNull.SerializerSettings);
} }
/// <summary> /// <summary>
@ -144,32 +144,32 @@ namespace Org.OpenAPITools.Model
/// <returns>An instance of ShapeOrNull</returns> /// <returns>An instance of ShapeOrNull</returns>
public static ShapeOrNull FromJson(string jsonString) public static ShapeOrNull FromJson(string jsonString)
{ {
ShapeOrNull newShapeOrNull = new ShapeOrNull(); ShapeOrNull newShapeOrNull = null;
int match = 0; int match = 0;
List<string> matchedTypes = new List<string>(); List<string> matchedTypes = new List<string>();
try try
{ {
newShapeOrNull.ActualInstance = JsonConvert.DeserializeObject<Quadrilateral>(jsonString, newShapeOrNull._serializerSettings); newShapeOrNull = new ShapeOrNull(JsonConvert.DeserializeObject<Quadrilateral>(jsonString, ShapeOrNull.SerializerSettings));
matchedTypes.Add("Quadrilateral"); matchedTypes.Add("Quadrilateral");
match++; match++;
} }
catch (Exception exception) catch (Exception exception)
{ {
// deserialization failed, try the next one // deserialization failed, try the next one
System.Diagnostics.Debug.WriteLine(String.Format("Failed to deserialize `%s` into Quadrilateral: %s", jsonString, exception.ToString())); System.Diagnostics.Debug.WriteLine(String.Format("Failed to deserialize `{0}` into Quadrilateral: {1}", jsonString, exception.ToString()));
} }
try try
{ {
newShapeOrNull.ActualInstance = JsonConvert.DeserializeObject<Triangle>(jsonString, newShapeOrNull._serializerSettings); newShapeOrNull = new ShapeOrNull(JsonConvert.DeserializeObject<Triangle>(jsonString, ShapeOrNull.SerializerSettings));
matchedTypes.Add("Triangle"); matchedTypes.Add("Triangle");
match++; match++;
} }
catch (Exception exception) catch (Exception exception)
{ {
// deserialization failed, try the next one // deserialization failed, try the next one
System.Diagnostics.Debug.WriteLine(String.Format("Failed to deserialize `%s` into Triangle: %s", jsonString, exception.ToString())); System.Diagnostics.Debug.WriteLine(String.Format("Failed to deserialize `{0}` into Triangle: {1}", jsonString, exception.ToString()));
} }
if (match == 0) if (match == 0)

View File

@ -33,15 +33,6 @@ namespace Org.OpenAPITools.Model
[DataContract(Name = "Triangle")] [DataContract(Name = "Triangle")]
public partial class Triangle : AbstractOpenAPISchema, IEquatable<Triangle>, IValidatableObject public partial class Triangle : AbstractOpenAPISchema, IEquatable<Triangle>, IValidatableObject
{ {
/// <summary>
/// Initializes a new instance of the <see cref="Triangle" /> class.
/// </summary>
public Triangle()
{
this.IsNullable = true;
this.SchemaType= "oneOf";
}
/// <summary> /// <summary>
/// Initializes a new instance of the <see cref="Triangle" /> class /// Initializes a new instance of the <see cref="Triangle" /> class
/// with the <see cref="EquilateralTriangle" /> class /// with the <see cref="EquilateralTriangle" /> class
@ -160,7 +151,7 @@ namespace Org.OpenAPITools.Model
/// <returns>JSON string presentation of the object</returns> /// <returns>JSON string presentation of the object</returns>
public override string ToJson() public override string ToJson()
{ {
return JsonConvert.SerializeObject(this.ActualInstance, _serializerSettings); return JsonConvert.SerializeObject(this.ActualInstance, Triangle.SerializerSettings);
} }
/// <summary> /// <summary>
@ -170,44 +161,44 @@ namespace Org.OpenAPITools.Model
/// <returns>An instance of Triangle</returns> /// <returns>An instance of Triangle</returns>
public static Triangle FromJson(string jsonString) public static Triangle FromJson(string jsonString)
{ {
Triangle newTriangle = new Triangle(); Triangle newTriangle = null;
int match = 0; int match = 0;
List<string> matchedTypes = new List<string>(); List<string> matchedTypes = new List<string>();
try try
{ {
newTriangle.ActualInstance = JsonConvert.DeserializeObject<EquilateralTriangle>(jsonString, newTriangle._serializerSettings); newTriangle = new Triangle(JsonConvert.DeserializeObject<EquilateralTriangle>(jsonString, Triangle.SerializerSettings));
matchedTypes.Add("EquilateralTriangle"); matchedTypes.Add("EquilateralTriangle");
match++; match++;
} }
catch (Exception exception) catch (Exception exception)
{ {
// deserialization failed, try the next one // deserialization failed, try the next one
System.Diagnostics.Debug.WriteLine(String.Format("Failed to deserialize `%s` into EquilateralTriangle: %s", jsonString, exception.ToString())); System.Diagnostics.Debug.WriteLine(String.Format("Failed to deserialize `{0}` into EquilateralTriangle: {1}", jsonString, exception.ToString()));
} }
try try
{ {
newTriangle.ActualInstance = JsonConvert.DeserializeObject<IsoscelesTriangle>(jsonString, newTriangle._serializerSettings); newTriangle = new Triangle(JsonConvert.DeserializeObject<IsoscelesTriangle>(jsonString, Triangle.SerializerSettings));
matchedTypes.Add("IsoscelesTriangle"); matchedTypes.Add("IsoscelesTriangle");
match++; match++;
} }
catch (Exception exception) catch (Exception exception)
{ {
// deserialization failed, try the next one // deserialization failed, try the next one
System.Diagnostics.Debug.WriteLine(String.Format("Failed to deserialize `%s` into IsoscelesTriangle: %s", jsonString, exception.ToString())); System.Diagnostics.Debug.WriteLine(String.Format("Failed to deserialize `{0}` into IsoscelesTriangle: {1}", jsonString, exception.ToString()));
} }
try try
{ {
newTriangle.ActualInstance = JsonConvert.DeserializeObject<ScaleneTriangle>(jsonString, newTriangle._serializerSettings); newTriangle = new Triangle(JsonConvert.DeserializeObject<ScaleneTriangle>(jsonString, Triangle.SerializerSettings));
matchedTypes.Add("ScaleneTriangle"); matchedTypes.Add("ScaleneTriangle");
match++; match++;
} }
catch (Exception exception) catch (Exception exception)
{ {
// deserialization failed, try the next one // deserialization failed, try the next one
System.Diagnostics.Debug.WriteLine(String.Format("Failed to deserialize `%s` into ScaleneTriangle: %s", jsonString, exception.ToString())); System.Diagnostics.Debug.WriteLine(String.Format("Failed to deserialize `{0}` into ScaleneTriangle: {1}", jsonString, exception.ToString()));
} }
if (match == 0) if (match == 0)