Skip to content

Commit

Permalink
Make nullability asssumptions explicit in VertragsConverter
Browse files Browse the repository at this point in the history
  • Loading branch information
hf-kklein committed Aug 18, 2024
1 parent 6f36e91 commit 87aea60
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions BO4E/BO/Vertrag.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Runtime.Serialization;
using System.Text.Json;
Expand Down Expand Up @@ -251,15 +252,19 @@ public override Vertrag Read(ref Utf8JsonReader reader, Type typeToConvert, Json
}

var v = JsonSerializer.Deserialize<Vertrag>(ref reader, Vertrag.VertragsSerializerOptions);
if (v is null)
{
throw new InvalidDataException("Could not deserialize Vertrag");
}
if ((v.Vertragsteile == null || v.Vertragsteile.Count == 0) && v.UserProperties != null &&
v.UserProperties.ContainsKey("lokationsId"))
v.UserProperties.TryGetValue("lokationsId", out var property))
v.Vertragsteile = new List<Vertragsteil>
{
new()
{
Vertragsteilbeginn = v.Vertragsbeginn,
Vertragsteilende = v.Vertragsende,
Lokation = ((JsonElement) v.UserProperties["lokationsId"]).GetString()
Lokation = ((JsonElement) property).GetString()
}
};
return v;
Expand Down

0 comments on commit 87aea60

Please sign in to comment.