<value>Members '{0}' and '{1}' on type '{2}' cannot both bind with parameter '{3}' in constructor '{4}' on deserialization.</value>
</data>
<data name="ConstructorParamIncompleteBinding" xml:space="preserve">
- <value>Each parameter in constructor '{0}' on type '{1}' must bind to an object member on deserialization. Each parameter name must be the camel case equivalent of an object member named with the pascal case naming convention.</value>
+ <value>Each parameter in constructor '{0}' on type '{1}' must bind to an object property or field on deserialization. Each parameter name must match with a property or field on the object. The match can be case-insensitive.</value>
</data>
<data name="ConstructorMaxOf64Parameters" xml:space="preserve">
<value>The constructor '{0}' on type '{1}' may not have more than 64 parameters for deserialization.</value>
<data name="NumberHandlingOnPropertyTypeMustBeNumberOrCollection" xml:space="preserve">
<value>When 'JsonNumberHandlingAttribute' is placed on a property or field, the property or field must be a number or a collection. See member '{0}' on type '{1}'.</value>
</data>
-</root>
\ No newline at end of file
+</root>
<Compile Include="System\Text\Json\Serialization\JsonPropertyInfo.cs" />
<Compile Include="System\Text\Json\Serialization\JsonPropertyInfoOfT.cs" />
<Compile Include="System\Text\Json\Serialization\JsonResumableConverterOfT.cs" />
+ <Compile Include="System\Text\Json\Serialization\JsonSerializer.cs" />
<Compile Include="System\Text\Json\Serialization\JsonSerializer.Read.HandleMetadata.cs" />
<Compile Include="System\Text\Json\Serialization\JsonSerializer.Read.HandlePropertyName.cs" />
<Compile Include="System\Text\Json\Serialization\JsonSerializer.Read.Helpers.cs" />
throw ThrowHelper.GetInvalidOperationException_ExpectedNumber(TokenType);
}
- ReadOnlySpan<byte> span = HasValueSequence ? ValueSequence.ToArray() : ValueSpan;;
+ ReadOnlySpan<byte> span = HasValueSequence ? ValueSequence.ToArray() : ValueSpan;
if (Utf8Parser.TryParse(span, out float tmp, out int bytesConsumed, _numberFormat)
&& span.Length == bytesConsumed)
/// The specified converter type must derive from <see cref="JsonConverter"/>.
/// When placed on a property or field, the specified converter will always be used.
/// When placed on a type, the specified converter will be used unless a compatible converter is added to
- /// <see cref="JsonSerializerOptions.Converters"/> or there is another <see cref="JsonConverterAttribute"/> on a member
+ /// <see cref="JsonSerializerOptions.Converters"/> or there is another <see cref="JsonConverterAttribute"/> on a property or field
/// of the same type.
/// </remarks>
[AttributeUsage(AttributeTargets.Class | AttributeTargets.Struct | AttributeTargets.Enum | AttributeTargets.Property | AttributeTargets.Field, AllowMultiple = false)]
/// During serializing, the name of the extension data member is not included in the JSON;
/// the data contained within the extension data is serialized as properties of the JSON object.
///
- /// If there is more than one extension member on a type, or it the member is not of the correct type,
+ /// If there is more than one extension member on a type, or the member is not of the correct type,
/// an <see cref="InvalidOperationException"/> is thrown during the first serialization or deserialization of that type.
/// </remarks>
[AttributeUsage(AttributeTargets.Property | AttributeTargets.Field, AllowMultiple = false)]
namespace System.Text.Json.Serialization
{
/// <summary>
- /// Indicates that the member should be included for serialization and deserialization.
+ /// Indicates that the property or field should be included for serialization and deserialization.
/// </summary>
/// <remarks>
- /// When applied to a property, indicates that non-public getters and setters can be used for serialization and deserialization.
+ /// When applied to a public property, indicates that non-public getters and setters should be used for serialization and deserialization.
+ ///
+ /// Non-public properties and fields are not allowed when serializing and deserializing. If the attribute is used on a non-public property or field,
+ /// an <see cref="InvalidOperationException"/> is thrown during the first serialization or deserialization of the declaring type.
/// </remarks>
[AttributeUsage(AttributeTargets.Property | System.AttributeTargets.Field, AllowMultiple = false)]
public sealed class JsonIncludeAttribute : JsonAttribute
{
/// <summary>
/// When placed on a type, property, or field, indicates what <see cref="JsonNumberHandling"/>
- /// settings should be used when serializing or deserialing numbers.
+ /// settings should be used when serializing or deserializing numbers.
/// </summary>
[AttributeUsage(AttributeTargets.Class | AttributeTargets.Struct | AttributeTargets.Property | AttributeTargets.Field, AllowMultiple = false)]
public sealed class JsonNumberHandlingAttribute : JsonAttribute
{
/// <summary>
- /// Indicates what settings should be used when serializing or deserialing numbers.
+ /// Indicates what settings should be used when serializing or deserializing numbers.
/// </summary>
public JsonNumberHandling Handling { get; }
/// </summary>
WriteAsString = 0x2,
/// <summary>
- /// The "NaN", "Infinity", and "-Infinity" <see cref="JsonTokenType.String"/> tokens can be read as floating-point constants,
- /// and the <see cref="float.NaN"/>, <see cref="double.PositiveInfinity"/>, and <see cref="float.NegativeInfinity"/>
- /// values will be written as their corresponding JSON string representations.
+ /// The "NaN", "Infinity", and "-Infinity" <see cref="JsonTokenType.String"/> tokens can be read as
+ /// floating-point constants, and the <see cref="float"/> and <see cref="double"/> values for these
+ /// constants will be written as their corresponding JSON string representations.
/// </summary>
AllowNamedFloatingPointLiterals = 0x4
}
using System.Diagnostics;
using System.Diagnostics.CodeAnalysis;
-using System.Runtime.CompilerServices;
using System.Text.Json.Serialization;
namespace System.Text.Json
Debug.Assert(value == null || value is TValue);
return (TValue)value!;
}
-
- internal static bool IsValidNumberHandlingValue(JsonNumberHandling handling)
- {
- int handlingValue = (int)handling;
- return handlingValue >= 0 && handlingValue <= 7;
- }
}
}
--- /dev/null
+// Licensed to the .NET Foundation under one or more agreements.
+// The .NET Foundation licenses this file to you under the MIT license.
+
+using System.Text.Json.Serialization;
+
+namespace System.Text.Json
+{
+ public static partial class JsonSerializer
+ {
+ internal static bool IsValidNumberHandlingValue(JsonNumberHandling handling)
+ {
+ return JsonHelpers.IsInRangeInclusive((int)handling, 0, 7);
+ }
+ }
+}
}
[Fact]
- public static void ExtensioFieldNotUsed()
+ public static void ExtensionFieldNotUsed()
{
string json = @"{""MyNestedClass"":" + SimpleTestClass.s_json + "}";
ClassWithExtensionField obj = JsonSerializer.Deserialize<ClassWithExtensionField>(json);