|
| 1 | +// <auto-generated /> |
| 2 | +#nullable enable |
| 3 | + |
| 4 | +namespace Thinktecture.Tests; |
| 5 | + |
| 6 | +[global::System.Text.Json.Serialization.JsonConverterAttribute(typeof(JsonConverterFactory))] |
| 7 | +partial class TestValueObject |
| 8 | +{ |
| 9 | + public sealed class JsonConverter : global::System.Text.Json.Serialization.JsonConverter<global::Thinktecture.Tests.TestValueObject> |
| 10 | + { |
| 11 | + private readonly global::System.Text.Json.Serialization.JsonConverter<global::Thinktecture.Tests.ClassDisallowingDefaultValues> _nonNullableReferenceTypeConverter; |
| 12 | + private readonly string _nonNullableReferenceTypePropertyName; |
| 13 | + private readonly global::System.Text.Json.Serialization.JsonConverter<global::Thinktecture.Tests.ClassDisallowingDefaultValues?> _nullableReferenceTypeConverter; |
| 14 | + private readonly string _nullableReferenceTypePropertyName; |
| 15 | + private readonly global::System.Text.Json.Serialization.JsonConverter<global::Thinktecture.Tests.StructDisallowingDefaultValues> _nonNullableStructConverter; |
| 16 | + private readonly string _nonNullableStructPropertyName; |
| 17 | + private readonly global::System.Text.Json.Serialization.JsonConverter<global::Thinktecture.Tests.StructDisallowingDefaultValues?> _nullableStructConverter; |
| 18 | + private readonly string _nullableStructPropertyName; |
| 19 | + |
| 20 | + public JsonConverter(global::System.Text.Json.JsonSerializerOptions options) |
| 21 | + { |
| 22 | + if(options is null) |
| 23 | + throw new global::System.ArgumentNullException(nameof(options)); |
| 24 | + |
| 25 | + var namingPolicy = options.PropertyNamingPolicy; |
| 26 | + |
| 27 | + this._nonNullableReferenceTypeConverter = (global::System.Text.Json.Serialization.JsonConverter<global::Thinktecture.Tests.ClassDisallowingDefaultValues>)global::Thinktecture.Internal.JsonSerializerOptionsExtensions.GetCustomMemberConverter(options, typeof(global::Thinktecture.Tests.ClassDisallowingDefaultValues)); |
| 28 | + this._nonNullableReferenceTypePropertyName = namingPolicy?.ConvertName("_nonNullableReferenceType") ?? "_nonNullableReferenceType"; |
| 29 | + this._nullableReferenceTypeConverter = (global::System.Text.Json.Serialization.JsonConverter<global::Thinktecture.Tests.ClassDisallowingDefaultValues?>)global::Thinktecture.Internal.JsonSerializerOptionsExtensions.GetCustomMemberConverter(options, typeof(global::Thinktecture.Tests.ClassDisallowingDefaultValues)); |
| 30 | + this._nullableReferenceTypePropertyName = namingPolicy?.ConvertName("_nullableReferenceType") ?? "_nullableReferenceType"; |
| 31 | + this._nonNullableStructConverter = (global::System.Text.Json.Serialization.JsonConverter<global::Thinktecture.Tests.StructDisallowingDefaultValues>)global::Thinktecture.Internal.JsonSerializerOptionsExtensions.GetCustomMemberConverter(options, typeof(global::Thinktecture.Tests.StructDisallowingDefaultValues)); |
| 32 | + this._nonNullableStructPropertyName = namingPolicy?.ConvertName("_nonNullableStruct") ?? "_nonNullableStruct"; |
| 33 | + this._nullableStructConverter = (global::System.Text.Json.Serialization.JsonConverter<global::Thinktecture.Tests.StructDisallowingDefaultValues?>)global::Thinktecture.Internal.JsonSerializerOptionsExtensions.GetCustomMemberConverter(options, typeof(global::Thinktecture.Tests.StructDisallowingDefaultValues?)); |
| 34 | + this._nullableStructPropertyName = namingPolicy?.ConvertName("_nullableStruct") ?? "_nullableStruct"; |
| 35 | + } |
| 36 | + |
| 37 | + /// <inheritdoc /> |
| 38 | + public override global::Thinktecture.Tests.TestValueObject? Read(ref global::System.Text.Json.Utf8JsonReader reader, global::System.Type typeToConvert, global::System.Text.Json.JsonSerializerOptions options) |
| 39 | + { |
| 40 | + if (reader.TokenType == global::System.Text.Json.JsonTokenType.Null) |
| 41 | + return default; |
| 42 | + |
| 43 | + if (reader.TokenType != global::System.Text.Json.JsonTokenType.StartObject) |
| 44 | + throw new global::System.Text.Json.JsonException($"Unexpected token \"{reader.TokenType}\" when trying to deserialize \"TestValueObject\". Expected token: \"{(global::System.Text.Json.JsonTokenType.StartObject)}\"."); |
| 45 | + |
| 46 | + global::Thinktecture.Tests.ClassDisallowingDefaultValues? @nonNullableReferenceType = default; |
| 47 | + global::Thinktecture.Tests.ClassDisallowingDefaultValues? @nullableReferenceType = default; |
| 48 | + global::Thinktecture.Argument<global::Thinktecture.Tests.StructDisallowingDefaultValues> @nonNullableStruct = default; |
| 49 | + global::Thinktecture.Tests.StructDisallowingDefaultValues? @nullableStruct = default; |
| 50 | + |
| 51 | + var comparer = options.PropertyNameCaseInsensitive ? global::System.StringComparer.OrdinalIgnoreCase : global::System.StringComparer.Ordinal; |
| 52 | + |
| 53 | + while (reader.Read()) |
| 54 | + { |
| 55 | + if (reader.TokenType == global::System.Text.Json.JsonTokenType.EndObject) |
| 56 | + break; |
| 57 | + |
| 58 | + if (reader.TokenType != global::System.Text.Json.JsonTokenType.PropertyName) |
| 59 | + throw new global::System.Text.Json.JsonException($"Unexpected token \"{reader.TokenType}\" when trying to deserialize \"TestValueObject\". Expected token: \"{(global::System.Text.Json.JsonTokenType.PropertyName)}\"."); |
| 60 | + |
| 61 | + var propName = reader.GetString(); |
| 62 | + |
| 63 | + if(!reader.Read()) |
| 64 | + throw new global::System.Text.Json.JsonException($"Unexpected end of the JSON message when trying the read the value of \"{propName}\" during deserialization of \"TestValueObject\"."); |
| 65 | + |
| 66 | + if (comparer.Equals(propName, this._nonNullableReferenceTypePropertyName)) |
| 67 | + { |
| 68 | + @nonNullableReferenceType = this._nonNullableReferenceTypeConverter.Read(ref reader, typeof(global::Thinktecture.Tests.ClassDisallowingDefaultValues), options); |
| 69 | + } |
| 70 | + else if (comparer.Equals(propName, this._nullableReferenceTypePropertyName)) |
| 71 | + { |
| 72 | + @nullableReferenceType = this._nullableReferenceTypeConverter.Read(ref reader, typeof(global::Thinktecture.Tests.ClassDisallowingDefaultValues), options); |
| 73 | + } |
| 74 | + else if (comparer.Equals(propName, this._nonNullableStructPropertyName)) |
| 75 | + { |
| 76 | + @nonNullableStruct = this._nonNullableStructConverter.Read(ref reader, typeof(global::Thinktecture.Tests.StructDisallowingDefaultValues), options); |
| 77 | + } |
| 78 | + else if (comparer.Equals(propName, this._nullableStructPropertyName)) |
| 79 | + { |
| 80 | + @nullableStruct = this._nullableStructConverter.Read(ref reader, typeof(global::Thinktecture.Tests.StructDisallowingDefaultValues?), options); |
| 81 | + } |
| 82 | + else |
| 83 | + { |
| 84 | + throw new global::System.Text.Json.JsonException($"Unknown member \"{propName}\" encountered when trying to deserialize \"TestValueObject\"."); |
| 85 | + } |
| 86 | + } |
| 87 | + |
| 88 | + if (!@nonNullableStruct.IsSet) |
| 89 | + throw new global::System.Text.Json.JsonException($"Cannot deserialize type \"TestValueObject\" because the member \"_nonNullableStruct\" of type \"global::Thinktecture.Tests.StructDisallowingDefaultValues\" is missing and does not allow default values."); |
| 90 | + |
| 91 | + var validationError = global::Thinktecture.Tests.TestValueObject.Validate( |
| 92 | + @nonNullableReferenceType!, |
| 93 | + @nullableReferenceType!, |
| 94 | + @nonNullableStruct.Value, |
| 95 | + @nullableStruct!, |
| 96 | + out var obj); |
| 97 | + |
| 98 | + if (validationError is not null) |
| 99 | + throw new global::System.Text.Json.JsonException(validationError.ToString() ?? "Unable to deserialize \"TestValueObject\"."); |
| 100 | + |
| 101 | + return obj; |
| 102 | + } |
| 103 | + |
| 104 | + /// <inheritdoc /> |
| 105 | + public override void Write(global::System.Text.Json.Utf8JsonWriter writer, global::Thinktecture.Tests.TestValueObject value, global::System.Text.Json.JsonSerializerOptions options) |
| 106 | + { |
| 107 | + writer.WriteStartObject(); |
| 108 | + |
| 109 | + var ignoreNullValues = options.DefaultIgnoreCondition is global::System.Text.Json.Serialization.JsonIgnoreCondition.WhenWritingNull or global::System.Text.Json.Serialization.JsonIgnoreCondition.WhenWritingDefault; |
| 110 | + var ignoreDefaultValues = options.DefaultIgnoreCondition == global::System.Text.Json.Serialization.JsonIgnoreCondition.WhenWritingDefault; |
| 111 | + |
| 112 | + var @nonNullableReferenceTypePropertyValue = value._nonNullableReferenceType; |
| 113 | + |
| 114 | + if(!ignoreNullValues || @nonNullableReferenceTypePropertyValue is not null) |
| 115 | + { |
| 116 | + writer.WritePropertyName(this._nonNullableReferenceTypePropertyName); |
| 117 | + this._nonNullableReferenceTypeConverter.Write(writer, @nonNullableReferenceTypePropertyValue, options); |
| 118 | + } |
| 119 | + var @nullableReferenceTypePropertyValue = value._nullableReferenceType; |
| 120 | + |
| 121 | + if(!ignoreNullValues || @nullableReferenceTypePropertyValue is not null) |
| 122 | + { |
| 123 | + writer.WritePropertyName(this._nullableReferenceTypePropertyName); |
| 124 | + this._nullableReferenceTypeConverter.Write(writer, @nullableReferenceTypePropertyValue, options); |
| 125 | + } |
| 126 | + var @nonNullableStructPropertyValue = value._nonNullableStruct; |
| 127 | + |
| 128 | + if(!ignoreDefaultValues || !@nonNullableStructPropertyValue.Equals(default(global::Thinktecture.Tests.StructDisallowingDefaultValues))) |
| 129 | + { |
| 130 | + writer.WritePropertyName(this._nonNullableStructPropertyName); |
| 131 | + this._nonNullableStructConverter.Write(writer, @nonNullableStructPropertyValue, options); |
| 132 | + } |
| 133 | + var @nullableStructPropertyValue = value._nullableStruct; |
| 134 | + |
| 135 | + if(!ignoreNullValues || @nullableStructPropertyValue is not null) |
| 136 | + { |
| 137 | + writer.WritePropertyName(this._nullableStructPropertyName); |
| 138 | + this._nullableStructConverter.Write(writer, @nullableStructPropertyValue, options); |
| 139 | + } |
| 140 | + writer.WriteEndObject(); |
| 141 | + } |
| 142 | + } |
| 143 | + |
| 144 | + public class JsonConverterFactory : global::System.Text.Json.Serialization.JsonConverterFactory |
| 145 | + { |
| 146 | + /// <inheritdoc /> |
| 147 | + public override bool CanConvert(global::System.Type typeToConvert) |
| 148 | + { |
| 149 | + return typeof(global::Thinktecture.Tests.TestValueObject).IsAssignableFrom(typeToConvert); |
| 150 | + } |
| 151 | + |
| 152 | + /// <inheritdoc /> |
| 153 | + public override global::System.Text.Json.Serialization.JsonConverter CreateConverter(global::System.Type typeToConvert, global::System.Text.Json.JsonSerializerOptions options) |
| 154 | + { |
| 155 | + if (typeToConvert is null) |
| 156 | + throw new global::System.ArgumentNullException(nameof(typeToConvert)); |
| 157 | + if (options is null) |
| 158 | + throw new global::System.ArgumentNullException(nameof(options)); |
| 159 | + |
| 160 | + return new JsonConverter(options); |
| 161 | + } |
| 162 | + } |
| 163 | +} |
0 commit comments