feat: add json property path supports for object keys
This commit is contained in:
parent
29be774abc
commit
eff887b49f
3 changed files with 58 additions and 0 deletions
|
|
@ -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));
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue