Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

New serializer converter model for objects and collections #2259

Merged
merged 3 commits into from
Feb 11, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions src/libraries/System.Text.Json/src/Resources/Strings.resx
Original file line number Diff line number Diff line change
Expand Up @@ -354,11 +354,11 @@
<data name="SerializationDuplicateTypeAttribute" xml:space="preserve">
<value>The type '{0}' cannot have more than one property that has the attribute '{1}'.</value>
</data>
<data name="SerializationNotSupportedCollectionType" xml:space="preserve">
<value>The collection type '{0}' is not supported.</value>
<data name="SerializationNotSupportedType" xml:space="preserve">
<value>The type '{0}' is not supported.</value>
</data>
<data name="SerializationNotSupportedCollection" xml:space="preserve">
<value>The collection type '{0}' on '{1}' is not supported.</value>
<data name="SerializationNotSupported" xml:space="preserve">
<value>The type '{0}' on '{1}' is not supported.</value>
</data>
<data name="InvalidCharacterAtStartOfComment" xml:space="preserve">
<value>'{0}' is invalid after '/' at the beginning of the comment. Expected either '/' or '*'.</value>
Expand Down Expand Up @@ -485,4 +485,4 @@
<data name="MetadataInvalidPropertyWithLeadingDollarSign" xml:space="preserve">
<value>Properties that start with '$' are not allowed on preserve mode, either escape the character or turn off preserve references by setting ReferenceHandling to ReferenceHandling.Default.</value>
</data>
</root>
</root>
61 changes: 39 additions & 22 deletions src/libraries/System.Text.Json/src/System.Text.Json.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -51,11 +51,35 @@
<Compile Include="System\Text\Json\Reader\Utf8JsonReader.TryGet.cs" />
<Compile Include="System\Text\Json\Serialization\ClassType.cs" />
<Compile Include="System\Text\Json\Serialization\ConverterList.cs" />
<Compile Include="System\Text\Json\Serialization\Converters\DefaultArrayConverter.cs" />
<Compile Include="System\Text\Json\Serialization\Converters\DefaultImmutableEnumerableConverter.cs" />
<Compile Include="System\Text\Json\Serialization\Converters\DefaultImmutableDictionaryConverter.cs" />
<Compile Include="System\Text\Json\Serialization\DefaultReferenceResolver.cs" />
<Compile Include="System\Text\Json\Serialization\ExtensionMethods.cs" />
<Compile Include="System\Text\Json\Serialization\Converters\EnumConverterOptions.cs" />
<Compile Include="System\Text\Json\Serialization\Converters\JsonArrayConverter.cs" />
<Compile Include="System\Text\Json\Serialization\Converters\JsonConcurrentQueueOfTConverter.cs" />
<Compile Include="System\Text\Json\Serialization\Converters\JsonConcurrentStackOfTConverter.cs" />
<Compile Include="System\Text\Json\Serialization\Converters\JsonConverterEnum.cs" />
<Compile Include="System\Text\Json\Serialization\Converters\JsonDictionaryDefaultConverter.cs" />
<Compile Include="System\Text\Json\Serialization\Converters\JsonDictionaryOfStringTValueConverter.cs" />
<Compile Include="System\Text\Json\Serialization\Converters\JsonICollectionOfTConverter.cs" />
<Compile Include="System\Text\Json\Serialization\Converters\JsonIDictionaryConverter.cs" />
<Compile Include="System\Text\Json\Serialization\Converters\JsonIDictionaryOfStringTValueConverter.cs" />
<Compile Include="System\Text\Json\Serialization\Converters\JsonIEnumerableConverter.cs" />
<Compile Include="System\Text\Json\Serialization\Converters\JsonIEnumerableConverterFactory.cs" />
<Compile Include="System\Text\Json\Serialization\Converters\JsonIEnumerableDefaultConverter.cs" />
<Compile Include="System\Text\Json\Serialization\Converters\JsonIEnumerableOfTConverter.cs" />
<Compile Include="System\Text\Json\Serialization\Converters\JsonIEnumerableWithAddMethodConverter.cs" />
<Compile Include="System\Text\Json\Serialization\Converters\JsonIListConverter.cs" />
<Compile Include="System\Text\Json\Serialization\Converters\JsonIListOfTConverter.cs" />
<Compile Include="System\Text\Json\Serialization\Converters\JsonImmutableDictionaryOfStringTValueConverter.cs" />
<Compile Include="System\Text\Json\Serialization\Converters\JsonImmutableEnumerableOfTConverter.cs" />
<Compile Include="System\Text\Json\Serialization\Converters\JsonIReadOnlyDictionaryOfStringTValueConverter.cs" />
<Compile Include="System\Text\Json\Serialization\Converters\JsonISetOfTConverter.cs" />
<Compile Include="System\Text\Json\Serialization\Converters\JsonKeyValuePairConverter.cs" />
<Compile Include="System\Text\Json\Serialization\Converters\JsonListOfTConverter.cs" />
<Compile Include="System\Text\Json\Serialization\Converters\JsonObjectDefaultConverter.cs" />
<Compile Include="System\Text\Json\Serialization\Converters\JsonObjectConverterFactory.cs" />
<Compile Include="System\Text\Json\Serialization\Converters\JsonQueueOfTConverter.cs" />
<Compile Include="System\Text\Json\Serialization\Converters\JsonStackOfTConverter.cs" />
<Compile Include="System\Text\Json\Serialization\Converters\JsonValueConverterBoolean.cs" />
<Compile Include="System\Text\Json\Serialization\Converters\JsonValueConverterByte.cs" />
<Compile Include="System\Text\Json\Serialization\Converters\JsonValueConverterByteArray.cs" />
Expand All @@ -64,14 +88,15 @@
<Compile Include="System\Text\Json\Serialization\Converters\JsonValueConverterDateTimeOffset.cs" />
<Compile Include="System\Text\Json\Serialization\Converters\JsonValueConverterDecimal.cs" />
<Compile Include="System\Text\Json\Serialization\Converters\JsonValueConverterDouble.cs" />
<Compile Include="System\Text\Json\Serialization\Converters\JsonConverterEnum.cs" />
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for fixing up the ordering :)

Copy link
Member Author

@steveharter steveharter Feb 4, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

BTW we should fix the csproj to use the default sorting by VS (which treats directory ordering different that what we have). I think the easiest would be to remove and add all files.

<Compile Include="System\Text\Json\Serialization\Converters\JsonValueConverterEnum.cs" />
<Compile Include="System\Text\Json\Serialization\Converters\JsonValueConverterGuid.cs" />
<Compile Include="System\Text\Json\Serialization\Converters\JsonValueConverterInt16.cs" />
<Compile Include="System\Text\Json\Serialization\Converters\JsonValueConverterInt32.cs" />
<Compile Include="System\Text\Json\Serialization\Converters\JsonValueConverterInt64.cs" />
<Compile Include="System\Text\Json\Serialization\Converters\JsonValueConverterJsonElement.cs" />
<Compile Include="System\Text\Json\Serialization\Converters\JsonValueConverterKeyValuePair.cs" />
<Compile Include="System\Text\Json\Serialization\Converters\JsonValueConverterNullable.cs" />
<Compile Include="System\Text\Json\Serialization\Converters\JsonValueConverterNullableFactory.cs" />
<Compile Include="System\Text\Json\Serialization\Converters\JsonValueConverterObject.cs" />
<Compile Include="System\Text\Json\Serialization\Converters\JsonValueConverterSByte.cs" />
<Compile Include="System\Text\Json\Serialization\Converters\JsonValueConverterSingle.cs" />
Expand All @@ -80,55 +105,45 @@
<Compile Include="System\Text\Json\Serialization\Converters\JsonValueConverterUInt32.cs" />
<Compile Include="System\Text\Json\Serialization\Converters\JsonValueConverterUInt64.cs" />
<Compile Include="System\Text\Json\Serialization\Converters\JsonValueConverterUri.cs" />
<Compile Include="System\Text\Json\Serialization\DefaultReferenceResolver.cs" />
<Compile Include="System\Text\Json\Serialization\ExtensionDataWriteStatus.cs" />
<Compile Include="System\Text\Json\Serialization\ImmutableCollectionCreator.cs" />
<Compile Include="System\Text\Json\Serialization\JsonAttribute.cs" />
<Compile Include="System\Text\Json\Serialization\JsonCamelCaseNamingPolicy.cs" />
<Compile Include="System\Text\Json\Serialization\JsonClassInfo.cs" />
<Compile Include="System\Text\Json\Serialization\JsonClassInfo.AddProperty.cs" />
<Compile Include="System\Text\Json\Serialization\JsonCollectionConverter.cs" />
<Compile Include="System\Text\Json\Serialization\JsonConverter.cs" />
<Compile Include="System\Text\Json\Serialization\JsonConverter.ReadAhead.cs" />
<Compile Include="System\Text\Json\Serialization\JsonConverterAttribute.cs" />
<Compile Include="System\Text\Json\Serialization\JsonConverterFactory.cs" />
<Compile Include="System\Text\Json\Serialization\JsonConverterOfT.cs" />
<Compile Include="System\Text\Json\Serialization\JsonDefaultNamingPolicy.cs" />
<Compile Include="System\Text\Json\Serialization\JsonDictionaryConverter.cs" />
<Compile Include="System\Text\Json\Serialization\JsonEnumerableConverter.cs" />
<Compile Include="System\Text\Json\Serialization\JsonExtensionDataAttribute.cs" />
<Compile Include="System\Text\Json\Serialization\JsonIgnoreAttribute.cs" />
<Compile Include="System\Text\Json\Serialization\JsonNamingPolicy.cs" />
<Compile Include="System\Text\Json\Serialization\JsonPreservableArrayReference.cs" />
<Compile Include="System\Text\Json\Serialization\JsonObjectConverter.cs" />
<Compile Include="System\Text\Json\Serialization\JsonPropertyInfo.cs" />
<Compile Include="System\Text\Json\Serialization\JsonPropertyInfoCommon.cs" />
<Compile Include="System\Text\Json\Serialization\JsonPropertyInfoNotNullable.cs" />
<Compile Include="System\Text\Json\Serialization\JsonPropertyInfoNotNullableContravariant.cs" />
<Compile Include="System\Text\Json\Serialization\JsonPropertyInfoNullable.cs" />
<Compile Include="System\Text\Json\Serialization\JsonPropertyInfoOfTConverter.cs" />
<Compile Include="System\Text\Json\Serialization\JsonPropertyNameAttribute.cs" />
<Compile Include="System\Text\Json\Serialization\JsonSerializer.Read.HandleArray.cs" />
<Compile Include="System\Text\Json\Serialization\JsonSerializer.Read.HandleDictionary.cs" />
<Compile Include="System\Text\Json\Serialization\JsonResumableConverterOfT.cs" />
<Compile Include="System\Text\Json\Serialization\JsonSerializer.Read.HandleMetadata.cs" />
<Compile Include="System\Text\Json\Serialization\JsonSerializer.Read.HandleObject.cs" />
<Compile Include="System\Text\Json\Serialization\JsonSerializer.Read.HandlePropertyName.cs" />
<Compile Include="System\Text\Json\Serialization\JsonSerializer.Read.HandleValue.cs" />
<Compile Include="System\Text\Json\Serialization\JsonSerializer.Read.Helpers.cs" />
<Compile Include="System\Text\Json\Serialization\JsonSerializer.Read.Stream.cs" />
<Compile Include="System\Text\Json\Serialization\JsonSerializer.Read.String.cs" />
<Compile Include="System\Text\Json\Serialization\JsonSerializer.Read.cs" />
<Compile Include="System\Text\Json\Serialization\JsonSerializer.Read.HandleNull.cs" />
<Compile Include="System\Text\Json\Serialization\JsonSerializer.Read.Span.cs" />
<Compile Include="System\Text\Json\Serialization\JsonSerializer.Read.Utf8JsonReader.cs" />
<Compile Include="System\Text\Json\Serialization\JsonSerializer.Write.cs" />
<Compile Include="System\Text\Json\Serialization\JsonSerializer.Write.ByteArray.cs" />
<Compile Include="System\Text\Json\Serialization\JsonSerializer.Write.HandleDictionary.cs" />
<Compile Include="System\Text\Json\Serialization\JsonSerializer.Write.HandleEnumerable.cs" />
<Compile Include="System\Text\Json\Serialization\JsonSerializer.Write.HandleObject.cs" />
<Compile Include="System\Text\Json\Serialization\JsonSerializer.Write.HandleMetadata.cs" />
<Compile Include="System\Text\Json\Serialization\JsonSerializer.Write.Helpers.cs" />
<Compile Include="System\Text\Json\Serialization\JsonSerializer.Write.Stream.cs" />
<Compile Include="System\Text\Json\Serialization\JsonSerializer.Write.String.cs" />
<Compile Include="System\Text\Json\Serialization\JsonSerializer.Write.Utf8JsonWriter.cs" />
<Compile Include="System\Text\Json\Serialization\JsonSerializerOptions.cs" />
<Compile Include="System\Text\Json\Serialization\JsonSerializerOptions.Converters.cs" />
<Compile Include="System\Text\Json\Serialization\JsonStringEnumConverter.cs" />
<Compile Include="System\Text\Json\Serialization\JsonValueConverterOfT.cs" />
<Compile Include="System\Text\Json\Serialization\MemberAccessor.cs" />
<Compile Include="System\Text\Json\Serialization\MetadataPropertyName.cs" />
<Compile Include="System\Text\Json\Serialization\PooledByteBufferWriter.cs" />
Expand All @@ -139,6 +154,8 @@
<Compile Include="System\Text\Json\Serialization\ReferenceHandling.cs" />
<Compile Include="System\Text\Json\Serialization\ReflectionEmitMemberAccessor.cs" />
<Compile Include="System\Text\Json\Serialization\ReflectionMemberAccessor.cs" />
<Compile Include="System\Text\Json\Serialization\StackFrameObjectState.cs" />
<Compile Include="System\Text\Json\Serialization\StackFramePropertyState.cs" />
<Compile Include="System\Text\Json\Serialization\WriteStack.cs" />
<Compile Include="System\Text\Json\Serialization\WriteStackFrame.cs" />
<Compile Include="System\Text\Json\Writer\JsonWriterHelper.cs" />
Expand Down Expand Up @@ -232,4 +249,4 @@
<Compile Include="System\Text\Json\Node\JsonObjectProperty.cs" />
<Compile Include="System\Text\Json\Node\JsonString.cs" />
</ItemGroup>
</Project>
</Project>
22 changes: 22 additions & 0 deletions src/libraries/System.Text.Json/src/System/Text/Json/JsonHelpers.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,24 @@
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.

using System.Buffers;
using System.Collections.Generic;
using System.Diagnostics;
using System.Runtime.CompilerServices;

namespace System.Text.Json
{
internal static partial class JsonHelpers
{
/// <summary>
/// Returns the span for the given reader.
/// </summary>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static ReadOnlySpan<byte> GetSpan(this ref Utf8JsonReader reader)
{
return reader.HasValueSequence ? reader.ValueSequence.ToArray() : reader.ValueSpan;
}

#if !BUILDING_INBOX_LIBRARY
/// <summary>
/// Returns <see langword="true"/> if <paramref name="value"/> is a valid Unicode scalar
Expand Down Expand Up @@ -64,6 +75,17 @@ public static bool IsInRangeInclusive(JsonTokenType value, JsonTokenType lowerBo
/// </summary>
public static bool IsDigit(byte value) => (uint)(value - '0') <= '9' - '0';

/// <summary>
/// Perform a Read() with a Debug.Assert verifying the reader did not return false.
/// This should be called when the Read() return value is not used, such as non-Stream cases where there is only one buffer.
/// </summary>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static void ReadWithVerify(this ref Utf8JsonReader reader)
{
bool result = reader.Read();
Debug.Assert(result);
}

/// <summary>
/// Calls Encoding.UTF8.GetString that supports netstandard.
/// </summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,17 @@ namespace System.Text.Json
/// </remarks>
internal enum ClassType : byte
{
// typeof(object)
Unknown = 0x1,
// POCO or rich data type
Object = 0x2,
// Value or object with a converter.
Value = 0x4,
// IEnumerable
// JsonObjectConverter<> - objects with properties.
Object = 0x1,
// JsonConverter<> - simple values.
Value = 0x2,
// JsonValueConverter<> - simple values that need to re-enter the serializer such as KeyValuePair<TKey, TValue>.
NewValue = 0x4,
layomia marked this conversation as resolved.
Show resolved Hide resolved
// JsonIEnumerbleConverter<> - all enumerable collections except dictionaries.
Enumerable = 0x8,
// IDictionary
// JsonDictionaryConverter<,> - dictionary types.
Dictionary = 0x10,
// Invalid (not used directly for serialization)
Invalid = 0x20
}
}

This file was deleted.

This file was deleted.

Loading