Skip to content

Commit

Permalink
Fixed polymorphic serialization
Browse files Browse the repository at this point in the history
  • Loading branch information
Arlodotexe committed Mar 9, 2024
1 parent 2cfc7c2 commit 38cc58d
Showing 1 changed file with 17 additions and 5 deletions.
22 changes: 17 additions & 5 deletions src/Models/JsonConverters/ApplicationConnectionJsonConverter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -90,15 +90,27 @@ public override bool CanConvert(Type objectType)
/// <inheritdoc/>
public override object? ReadJson(JsonReader reader, Type objectType, object? existingValue, JsonSerializer serializer)
{
if (reader.Value is null)
return null;

if (reader.TokenType == JsonToken.Null)
return null;

var token = JToken.Load(reader);
if (reader.TokenType == JsonToken.PropertyName)
{
return reader.Value;
}

if (reader.TokenType == JsonToken.StartObject)
{
var jobj = JObject.Load(reader);
return ApplicationConnectionSerializationHelpers.ReadConnection(jobj, serializer);
}

if (reader.TokenType == JsonToken.StartArray)
{
var jarray = JArray.Load(reader);
return ApplicationConnectionSerializationHelpers.ReadConnection(jarray, serializer);
}

return ApplicationConnectionSerializationHelpers.ReadConnection(token, serializer);
throw new NotSupportedException($"Token type {reader.TokenType} is not supported.");
}

/// <inheritdoc/>
Expand Down

0 comments on commit 38cc58d

Please sign in to comment.