| | | 1 | | // Licensed to the .NET Foundation under one or more agreements. |
| | | 2 | | // The .NET Foundation licenses this file to you under the MIT license. |
| | | 3 | | |
| | | 4 | | using System.Diagnostics; |
| | | 5 | | using System.Text.Json.Nodes; |
| | | 6 | | using System.Text.Json.Schema; |
| | | 7 | | |
| | | 8 | | namespace System.Text.Json.Serialization.Converters |
| | | 9 | | { |
| | | 10 | | internal sealed class GuidConverter : JsonPrimitiveConverter<Guid> |
| | | 11 | | { |
| | | 12 | | public override Guid Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options) |
| | 690 | 13 | | { |
| | 690 | 14 | | return reader.GetGuid(); |
| | 0 | 15 | | } |
| | | 16 | | |
| | | 17 | | public override void Write(Utf8JsonWriter writer, Guid value, JsonSerializerOptions options) |
| | 0 | 18 | | { |
| | 0 | 19 | | writer.WriteStringValue(value); |
| | 0 | 20 | | } |
| | | 21 | | |
| | | 22 | | internal override Guid ReadAsPropertyNameCore(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptio |
| | 0 | 23 | | { |
| | 0 | 24 | | Debug.Assert(reader.TokenType == JsonTokenType.PropertyName); |
| | 0 | 25 | | return reader.GetGuidNoValidation(); |
| | 0 | 26 | | } |
| | | 27 | | |
| | | 28 | | internal override void WriteAsPropertyNameCore(Utf8JsonWriter writer, Guid value, JsonSerializerOptions options, |
| | 0 | 29 | | { |
| | 0 | 30 | | writer.WritePropertyName(value); |
| | 0 | 31 | | } |
| | | 32 | | |
| | | 33 | | internal override JsonSchema? GetSchema(JsonNumberHandling numberHandling) => |
| | 0 | 34 | | new() { Type = JsonSchemaType.String, Format = "uuid" }; |
| | | 35 | | } |
| | | 36 | | } |