| | 1 | | // Copyright (c) Microsoft Corporation. All rights reserved. |
| | 2 | | // Licensed under the MIT License. |
| | 3 | |
|
| | 4 | | // <auto-generated/> |
| | 5 | |
|
| | 6 | | #nullable disable |
| | 7 | |
|
| | 8 | | using System.Text.Json; |
| | 9 | | using Azure.Core; |
| | 10 | |
|
| | 11 | | namespace Azure.Search.Documents.Indexes.Models |
| | 12 | | { |
| | 13 | | public partial class FieldMapping : IUtf8JsonSerializable |
| | 14 | | { |
| | 15 | | void IUtf8JsonSerializable.Write(Utf8JsonWriter writer) |
| | 16 | | { |
| 6 | 17 | | writer.WriteStartObject(); |
| 6 | 18 | | writer.WritePropertyName("sourceFieldName"); |
| 6 | 19 | | writer.WriteStringValue(SourceFieldName); |
| 6 | 20 | | if (Optional.IsDefined(TargetFieldName)) |
| | 21 | | { |
| 1 | 22 | | writer.WritePropertyName("targetFieldName"); |
| 1 | 23 | | writer.WriteStringValue(TargetFieldName); |
| | 24 | | } |
| 6 | 25 | | if (Optional.IsDefined(MappingFunction)) |
| | 26 | | { |
| 0 | 27 | | if (MappingFunction != null) |
| | 28 | | { |
| 0 | 29 | | writer.WritePropertyName("mappingFunction"); |
| 0 | 30 | | writer.WriteObjectValue(MappingFunction); |
| | 31 | | } |
| | 32 | | else |
| | 33 | | { |
| 0 | 34 | | writer.WriteNull("mappingFunction"); |
| | 35 | | } |
| | 36 | | } |
| 6 | 37 | | writer.WriteEndObject(); |
| 6 | 38 | | } |
| | 39 | |
|
| | 40 | | internal static FieldMapping DeserializeFieldMapping(JsonElement element) |
| | 41 | | { |
| 6 | 42 | | string sourceFieldName = default; |
| 6 | 43 | | Optional<string> targetFieldName = default; |
| 6 | 44 | | Optional<FieldMappingFunction> mappingFunction = default; |
| 48 | 45 | | foreach (var property in element.EnumerateObject()) |
| | 46 | | { |
| 18 | 47 | | if (property.NameEquals("sourceFieldName")) |
| | 48 | | { |
| 6 | 49 | | sourceFieldName = property.Value.GetString(); |
| 6 | 50 | | continue; |
| | 51 | | } |
| 12 | 52 | | if (property.NameEquals("targetFieldName")) |
| | 53 | | { |
| 6 | 54 | | targetFieldName = property.Value.GetString(); |
| 6 | 55 | | continue; |
| | 56 | | } |
| 6 | 57 | | if (property.NameEquals("mappingFunction")) |
| | 58 | | { |
| 6 | 59 | | if (property.Value.ValueKind == JsonValueKind.Null) |
| | 60 | | { |
| 6 | 61 | | mappingFunction = null; |
| 6 | 62 | | continue; |
| | 63 | | } |
| 0 | 64 | | mappingFunction = FieldMappingFunction.DeserializeFieldMappingFunction(property.Value); |
| | 65 | | continue; |
| | 66 | | } |
| | 67 | | } |
| 6 | 68 | | return new FieldMapping(sourceFieldName, targetFieldName.Value, mappingFunction.Value); |
| | 69 | | } |
| | 70 | | } |
| | 71 | | } |