Skip to content

Commit

Permalink
Remove stack overflow exception (#178)
Browse files Browse the repository at this point in the history
  • Loading branch information
JoschaMetze authored Mar 25, 2022
1 parent d4b0a28 commit b9005dd
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 5 deletions.
10 changes: 8 additions & 2 deletions BO4E/BO/Energiemenge.cs
Original file line number Diff line number Diff line change
Expand Up @@ -145,8 +145,11 @@ public override Energiemenge Read(ref Utf8JsonReader reader, Type typeToConvert,
if (Energiemenge.EnergiemengeSerializerOptions == null)
{
Energiemenge.EnergiemengeSerializerOptions = new JsonSerializerOptions(options);
Energiemenge.EnergiemengeSerializerOptions.Converters.Remove(
while (Energiemenge.EnergiemengeSerializerOptions.Converters.Any(s => s.GetType() == typeof(EnergiemengeConverter)))
{
Energiemenge.EnergiemengeSerializerOptions.Converters.Remove(
Energiemenge.EnergiemengeSerializerOptions.Converters.First(s => s.GetType() == typeof(EnergiemengeConverter)));
}
}
}
var e = JsonSerializer.Deserialize<Energiemenge>(ref reader, Energiemenge.EnergiemengeSerializerOptions);
Expand All @@ -170,8 +173,11 @@ public override void Write(Utf8JsonWriter writer, Energiemenge value, JsonSerial
if (Energiemenge.EnergiemengeSerializerOptions == null)
{
Energiemenge.EnergiemengeSerializerOptions = new JsonSerializerOptions(options);
Energiemenge.EnergiemengeSerializerOptions.Converters.Remove(
while (Energiemenge.EnergiemengeSerializerOptions.Converters.Any(s => s.GetType() == typeof(EnergiemengeConverter)))
{
Energiemenge.EnergiemengeSerializerOptions.Converters.Remove(
Energiemenge.EnergiemengeSerializerOptions.Converters.First(s => s.GetType() == typeof(EnergiemengeConverter)));
}
}
}
JsonSerializer.Serialize(writer, value, Energiemenge.EnergiemengeSerializerOptions);
Expand Down
10 changes: 8 additions & 2 deletions BO4E/BO/Vertrag.cs
Original file line number Diff line number Diff line change
Expand Up @@ -230,8 +230,11 @@ public override Vertrag Read(ref Utf8JsonReader reader, Type typeToConvert, Json
if (Vertrag.VertragsSerializerOptions == null)
{
Vertrag.VertragsSerializerOptions = new JsonSerializerOptions(options);
Vertrag.VertragsSerializerOptions.Converters.Remove(
while (Vertrag.VertragsSerializerOptions.Converters.Any(s => s.GetType() == typeof(VertragsConverter)))
{
Vertrag.VertragsSerializerOptions.Converters.Remove(
Vertrag.VertragsSerializerOptions.Converters.First(s => s.GetType() == typeof(VertragsConverter)));
}
}
}
var v = JsonSerializer.Deserialize<Vertrag>(ref reader, Vertrag.VertragsSerializerOptions);
Expand Down Expand Up @@ -263,8 +266,11 @@ public override void Write(Utf8JsonWriter writer, Vertrag value, JsonSerializerO
if (Vertrag.VertragsSerializerOptions == null)
{
Vertrag.VertragsSerializerOptions = new JsonSerializerOptions(options);
Vertrag.VertragsSerializerOptions.Converters.Remove(
while (Vertrag.VertragsSerializerOptions.Converters.Any(s => s.GetType() == typeof(VertragsConverter)))
{
Vertrag.VertragsSerializerOptions.Converters.Remove(
Vertrag.VertragsSerializerOptions.Converters.First(s => s.GetType() == typeof(VertragsConverter)));
}
}
}
JsonSerializer.Serialize(writer, value, Vertrag.VertragsSerializerOptions);
Expand Down
3 changes: 2 additions & 1 deletion BO4ETestProject/TestBoMapper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -138,10 +138,11 @@ public void TestVertragStringToIntNewtonsoft()
json = JsonConvert.DeserializeObject<JObject>(jsonString);
}

const LenientParsing lenients = LenientParsing.STRING_TO_INT;
const LenientParsing lenients = LenientParsing.MOST_LENIENT;
var v = JsonConvert.DeserializeObject<Vertrag>(json["input"].ToString(),
lenients.GetJsonSerializerSettings());
Assert.AreEqual(v.Vertragskonditionen.AnzahlAbschlaege, 12);
v.Vertragsende.Should().Be(DateTimeOffset.MinValue);
}


Expand Down

0 comments on commit b9005dd

Please sign in to comment.