feat: add json property path supports for object keys
All checks were successful
default / dotnet-default-workflow (pull_request) Successful in 2m4s
default / dotnet-default-workflow (push) Successful in 3m25s

This commit is contained in:
Louis Seubert 2026-05-30 21:17:14 +02:00
commit eff887b49f
Signed by: louis9902
GPG key ID: 4B9DB28F826553BD
3 changed files with 58 additions and 0 deletions

View file

@ -399,9 +399,26 @@ internal sealed class PropertyPathJsonConverter : JsonConverter<PropertyPath>
throw new JsonException($"Expected {nameof(JsonTokenType.String)} but got {reader.TokenType}.");
}
/// <inheritdoc />
public override PropertyPath ReadAsPropertyName(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options)
{
if (reader.TokenType is JsonTokenType.PropertyName)
{
return new PropertyPath(reader.GetString()!);
}
throw new JsonException($"Expected {nameof(JsonTokenType.PropertyName)} but got {reader.TokenType}.");
}
/// <inheritdoc />
public override void Write(Utf8JsonWriter writer, PropertyPath value, JsonSerializerOptions options)
{
writer.WriteStringValue(value.ToJsonName(options.PropertyNamingPolicy));
}
/// <inheritdoc />
public override void WriteAsPropertyName(Utf8JsonWriter writer, PropertyPath value, JsonSerializerOptions options)
{
writer.WritePropertyName(value.ToJsonName(options.DictionaryKeyPolicy));
}
}