From b743bb985b7680f2798d14dc12a5122377a1184c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tamara=20Gei=C3=9Fler?= Date: Mon, 19 Sep 2022 17:53:02 +0200 Subject: [PATCH] chore: Drop support for Newtonsoft.Json except Bson --- .../Api.Rest.Dtos.Tests.csproj | 1 - .../Benchmarks/SerializationBenchmark.cs | 73 +---- .../Compatibility/CompatibilityTests.cs | 31 +- .../Data/ConfigurationSerializationTests.cs | 12 +- .../InspectionPlanDtoBaseConverterTests.cs | 81 +++-- .../Data/InspectionPlanSerializationTests.cs | 15 +- .../Data/MeasurementSerializationTests.cs | 11 +- .../Data/SerializationTestHelper.cs | 5 - .../Data/ValueSerializationTests.cs | 11 +- src/Api.Rest.Dtos/Api.Rest.Dtos.csproj | 1 - .../Converter/AttributeArrayConverter.cs | 148 ++++----- .../Converter/AttributeConverter.cs | 160 +++++---- .../Converter/AttributeDefinitionConverter.cs | 305 +++++++++++------- .../Converter/DataValueConverter.cs | 28 +- .../InspectionPlanDtoBaseConverter.cs | 263 +++++++-------- .../Converter/PathInformationConverter.cs | 97 +++--- .../Data/AbstractAttributeDefinitionDto.cs | 4 +- .../Data/AttributeDefinitionDto.cs | 2 - src/Api.Rest.Dtos/Data/AttributeDto.cs | 4 +- src/Api.Rest.Dtos/Data/AttributeTypeDto.cs | 1 - .../Data/CatalogAttributeDefinitionDto.cs | 2 - src/Api.Rest.Dtos/Data/CatalogDto.cs | 2 - src/Api.Rest.Dtos/Data/CatalogEntryDto.cs | 5 +- src/Api.Rest.Dtos/Data/ConfigurationDto.cs | 7 - src/Api.Rest.Dtos/Data/DataMeasurementDto.cs | 4 - src/Api.Rest.Dtos/Data/DataValueDto.cs | 11 +- src/Api.Rest.Dtos/Data/EntityDto.cs | 1 - src/Api.Rest.Dtos/Data/FieldTypeDto.cs | 1 - .../Data/InspectionPlanCharacteristicDto.cs | 1 - .../Data/InspectionPlanDtoBase.cs | 12 +- .../Data/InspectionPlanEntityDto.cs | 1 - .../Data/InspectionPlanPartDto.cs | 1 - .../Data/MeasurementMergeConditionDto.cs | 1 - src/Api.Rest.Dtos/Data/OperationDto.cs | 1 - .../Data/OperationExecutionStatusDto.cs | 79 +++-- src/Api.Rest.Dtos/Data/OperationStatusDto.cs | 89 +++-- src/Api.Rest.Dtos/Data/OrderDirectionDto.cs | 1 - src/Api.Rest.Dtos/Data/OrderDto.cs | 3 - src/Api.Rest.Dtos/Data/PathInformationDto.cs | 4 +- .../Data/ServiceInformationDto.cs | 15 - src/Api.Rest.Dtos/Data/SimpleCatalogDto.cs | 2 - .../Data/SimpleMeasurementDto.cs | 12 +- .../Data/SimpleMeasurementStatusDto.cs | 3 - src/Api.Rest.Dtos/Data/SimplePartDto.cs | 1 - src/Api.Rest.Dtos/Data/VersioningTypeDto.cs | 1 - src/Api.Rest.Dtos/InterfaceVersionRange.cs | 1 - .../JsonAttributeArrayConverter.cs | 70 ---- .../JsonConverters/JsonAttributeConverter.cs | 100 ------ .../JsonAttributeDefinitionConverter.cs | 185 ----------- .../JsonConverters/JsonDataValueConverter.cs | 45 --- .../JsonInspectionPlanDtoBaseConverter.cs | 118 ------- .../JsonPathInformationConverter.cs | 47 --- .../RawData/RawDataArchiveBulkQueryDto.cs | 1 - .../RawData/RawDataArchiveContentDto.cs | 5 - .../RawData/RawDataArchiveEntriesDto.cs | 2 - .../RawData/RawDataArchiveSelectorDto.cs | 3 - .../RawData/RawDataBulkQueryDto.cs | 1 - src/Api.Rest.Dtos/RawData/RawDataEntityDto.cs | 1 - .../RawData/RawDataInformationDto.cs | 9 - .../RawData/RawDataSelectorDto.cs | 2 - .../RawData/RawDataTargetEntityDto.cs | 2 - .../RawData/ServiceInformationDto.cs | 2 - src/Api.Rest.Tests/Api.Rest.Tests.csproj | 1 - .../Data/DataServiceRestClientTest.cs | 11 +- .../RawData/RawDataServiceRestClientTest.cs | 9 +- src/Api.Rest.Tests/SimpleRequestTest.cs | 6 +- .../Common/Client/ObjectSerializer.cs | 139 ++------ .../Converter/StreamingReaderConverter.cs | 77 ----- .../Converter/StreamingWriterConverter.cs | 66 ---- .../HttpClient/Data/DataServiceRestClient.cs | 2 +- .../HttpClient/Data/VersioningInformation.cs | 5 - .../OAuth/OAuthServiceRestClient.cs | 2 +- .../HttpClient/OAuth/OAuthTokenInformation.cs | 1 - .../RawData/RawDataServiceRestClient.cs | 2 +- 74 files changed, 729 insertions(+), 1699 deletions(-) delete mode 100644 src/Api.Rest.Dtos/JsonConverters/JsonAttributeArrayConverter.cs delete mode 100644 src/Api.Rest.Dtos/JsonConverters/JsonAttributeConverter.cs delete mode 100644 src/Api.Rest.Dtos/JsonConverters/JsonAttributeDefinitionConverter.cs delete mode 100644 src/Api.Rest.Dtos/JsonConverters/JsonDataValueConverter.cs delete mode 100644 src/Api.Rest.Dtos/JsonConverters/JsonInspectionPlanDtoBaseConverter.cs delete mode 100644 src/Api.Rest.Dtos/JsonConverters/JsonPathInformationConverter.cs delete mode 100644 src/Api.Rest/Common/Data/Converter/StreamingReaderConverter.cs delete mode 100644 src/Api.Rest/Common/Data/Converter/StreamingWriterConverter.cs diff --git a/src/Api.Rest.Dtos.Tests/Api.Rest.Dtos.Tests.csproj b/src/Api.Rest.Dtos.Tests/Api.Rest.Dtos.Tests.csproj index 43e0a8cc..f6699268 100644 --- a/src/Api.Rest.Dtos.Tests/Api.Rest.Dtos.Tests.csproj +++ b/src/Api.Rest.Dtos.Tests/Api.Rest.Dtos.Tests.csproj @@ -15,7 +15,6 @@ - all diff --git a/src/Api.Rest.Dtos.Tests/Benchmarks/SerializationBenchmark.cs b/src/Api.Rest.Dtos.Tests/Benchmarks/SerializationBenchmark.cs index fe59ba4f..fc9a37fb 100644 --- a/src/Api.Rest.Dtos.Tests/Benchmarks/SerializationBenchmark.cs +++ b/src/Api.Rest.Dtos.Tests/Benchmarks/SerializationBenchmark.cs @@ -5,6 +5,7 @@ namespace Zeiss.PiWeb.Api.Rest.Dtos.Tests.Benchmarks using System; using System.Collections.Generic; using System.Diagnostics.CodeAnalysis; + using System.Text.Json; using BenchmarkDotNet.Attributes; using BenchmarkDotNet.Configs; using BenchmarkDotNet.Filters; @@ -46,9 +47,9 @@ public class SerializationBenchmark private static readonly string MeasurementsJson = SerializationTestHelper.ReadResourceString( "Samples.measurements.json" ); private static readonly string ValuesJson = SerializationTestHelper.ReadResourceString( "Samples.values.json" ); - private static readonly IReadOnlyList Characteristics = Newtonsoft.Json.JsonConvert.DeserializeObject>( CharacteristicJson ); - private static readonly IReadOnlyList Measurements = Newtonsoft.Json.JsonConvert.DeserializeObject>( MeasurementsJson ); - private static readonly IReadOnlyList Values = Newtonsoft.Json.JsonConvert.DeserializeObject>( ValuesJson ); + private static readonly IReadOnlyList Characteristics = JsonSerializer.Deserialize>( CharacteristicJson ); + private static readonly IReadOnlyList Measurements = JsonSerializer.Deserialize>( MeasurementsJson ); + private static readonly IReadOnlyList Values = JsonSerializer.Deserialize>( ValuesJson ); private static readonly IReadOnlyList TestCases = new[] { @@ -98,88 +99,46 @@ private static void ExecuteBenchmarks( params string[] categories ) Console.Out.WriteLine( summary ); } - [Benchmark] - [BenchmarkCategory( SerializationCategory, InspectionPlanCategory, NewtonsoftJsonCategory )] - public string SerializeCharacteristicsNewtonsoftJson() - { - return Newtonsoft.Json.JsonConvert.SerializeObject( Characteristics ); - } - [Benchmark] [BenchmarkCategory( SerializationCategory, InspectionPlanCategory, SystemTextJsonCategory )] - public string SerializeCharacteristicsSystemTextJson() - { - return System.Text.Json.JsonSerializer.Serialize( Characteristics ); - } - - [Benchmark] - [BenchmarkCategory( SerializationCategory, MeasurementCategory, NewtonsoftJsonCategory )] - public string SerializeMeasurementsNewtonsoftJson() + public string SerializeCharacteristics() { - return Newtonsoft.Json.JsonConvert.SerializeObject( Measurements ); + return JsonSerializer.Serialize( Characteristics ); } [Benchmark] [BenchmarkCategory( SerializationCategory, MeasurementCategory, SystemTextJsonCategory )] - public string SerializeMeasurementsSystemTextJson() - { - return System.Text.Json.JsonSerializer.Serialize( Measurements ); - } - - [Benchmark] - [BenchmarkCategory( SerializationCategory, ValueCategory, NewtonsoftJsonCategory )] - public string SerializeValuesNewtonsoftJson() + public string SerializeMeasurements() { - return Newtonsoft.Json.JsonConvert.SerializeObject( Values ); + return JsonSerializer.Serialize( Measurements ); } [Benchmark] [BenchmarkCategory( SerializationCategory, ValueCategory, SystemTextJsonCategory )] - public string SerializeValuesSystemTextJson() + public string SerializeValues() { - return System.Text.Json.JsonSerializer.Serialize( Values ); - } - - [Benchmark] - [BenchmarkCategory( DeserializationCategory, InspectionPlanCategory, NewtonsoftJsonCategory )] - public IReadOnlyList DeserializeCharacteristicsNewtonsoftJson() - { - return Newtonsoft.Json.JsonConvert.DeserializeObject>( CharacteristicJson ); + return JsonSerializer.Serialize( Values ); } [Benchmark] [BenchmarkCategory( DeserializationCategory, InspectionPlanCategory, SystemTextJsonCategory )] - public IReadOnlyList DeserializeCharacteristicsSystemTextJson() - { - return System.Text.Json.JsonSerializer.Deserialize>( CharacteristicJson ); - } - - [Benchmark] - [BenchmarkCategory( DeserializationCategory, MeasurementCategory, NewtonsoftJsonCategory )] - public IReadOnlyList DeserializeMeasurementsNewtonsoftJson() + public IReadOnlyList DeserializeCharacteristics() { - return Newtonsoft.Json.JsonConvert.DeserializeObject>( MeasurementsJson ); + return JsonSerializer.Deserialize>( CharacteristicJson ); } [Benchmark] [BenchmarkCategory( DeserializationCategory, MeasurementCategory, SystemTextJsonCategory )] - public IReadOnlyList DeserializeMeasurementsSystemTextJson() - { - return System.Text.Json.JsonSerializer.Deserialize>( MeasurementsJson ); - } - - [Benchmark] - [BenchmarkCategory( DeserializationCategory, ValueCategory, NewtonsoftJsonCategory )] - public IReadOnlyList DeserializeValuesNewtonsoftJson() + public IReadOnlyList DeserializeMeasurements() { - return Newtonsoft.Json.JsonConvert.DeserializeObject>( ValuesJson ); + return JsonSerializer.Deserialize>( MeasurementsJson ); } [Benchmark] [BenchmarkCategory( DeserializationCategory, ValueCategory, SystemTextJsonCategory )] - public IReadOnlyList DeserializeValuesSystemTextJson() + public IReadOnlyList DeserializeValues() { - return System.Text.Json.JsonSerializer.Deserialize>( ValuesJson ); + return JsonSerializer.Deserialize>( ValuesJson ); } #endregion diff --git a/src/Api.Rest.Dtos.Tests/Compatibility/CompatibilityTests.cs b/src/Api.Rest.Dtos.Tests/Compatibility/CompatibilityTests.cs index 0da178b6..5f89a2bf 100644 --- a/src/Api.Rest.Dtos.Tests/Compatibility/CompatibilityTests.cs +++ b/src/Api.Rest.Dtos.Tests/Compatibility/CompatibilityTests.cs @@ -19,10 +19,10 @@ namespace Zeiss.PiWeb.Api.Rest.Dtos.Tests.Compatibility using System.Linq; using System.Net.Mime; using System.Text; + using System.Text.Json; using NUnit.Framework; using Zeiss.PiWeb.Api.Rest.Dtos.Converter; using Zeiss.PiWeb.Api.Rest.Dtos.Data; - using Zeiss.PiWeb.Api.Rest.Dtos.JsonConverters; using Zeiss.PiWeb.Api.Rest.Dtos.RawData; using static PiWeb.Api.Definitions.WellKnownKeys; @@ -380,43 +380,22 @@ public class CompatibilityTests } .ToDictionary( pair => pair.Key, pair => pair.Value ); - private static readonly Newtonsoft.Json.JsonSerializerSettings Settings = new() - { - NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore, - Converters = { new Newtonsoft.Json.Converters.VersionConverter(), new InspectionPlanDtoBaseConverter() } - }; - - private static readonly System.Text.Json.JsonSerializerOptions Options = new() + private static readonly JsonSerializerOptions Options = new() { DefaultIgnoreCondition = System.Text.Json.Serialization.JsonIgnoreCondition.WhenWritingNull, - Converters = { new JsonInspectionPlanDtoBaseConverter() } + Converters = { new InspectionPlanDtoBaseConverter() } }; #endregion #region methods - [TestCaseSource( nameof( TestCases ) )] - public void Backward_Compatible( T value ) - { - var json = Newtonsoft.Json.JsonConvert.SerializeObject( value, Settings ); - - var deserializedValue = System.Text.Json.JsonSerializer.Deserialize( json, Options ); - - var equatable = EquatableFromType[typeof( T )]; - - var expected = equatable( value ); - var actual = equatable( deserializedValue ); - - Assert.AreEqual( expected, actual, $"{typeof( T ).Name}" ); - } - [TestCaseSource( nameof( TestCases ) )] public void Forward_Compatible( T value ) { - var json = System.Text.Json.JsonSerializer.Serialize( value, Options ); + var json = JsonSerializer.Serialize( value, Options ); - var deserializedValue = Newtonsoft.Json.JsonConvert.DeserializeObject( json, Settings ); + var deserializedValue = JsonSerializer.Deserialize( json, Options ); var equatable = EquatableFromType[typeof( T )]; diff --git a/src/Api.Rest.Dtos.Tests/Data/ConfigurationSerializationTests.cs b/src/Api.Rest.Dtos.Tests/Data/ConfigurationSerializationTests.cs index 68a39086..4c488a56 100644 --- a/src/Api.Rest.Dtos.Tests/Data/ConfigurationSerializationTests.cs +++ b/src/Api.Rest.Dtos.Tests/Data/ConfigurationSerializationTests.cs @@ -12,13 +12,9 @@ namespace Zeiss.PiWeb.Api.Rest.Dtos.Tests.Data { #region usings - using System; - using System.Collections.Generic; - using System.IO; - using Newtonsoft.Json; + using System.Text.Json; using NUnit.Framework; using Zeiss.PiWeb.Api.Definitions; - using Zeiss.PiWeb.Api.Rest.Dtos.Converter; using Zeiss.PiWeb.Api.Rest.Dtos.Data; #endregion @@ -37,8 +33,8 @@ public class ConfigurationSerializationTests [Test] public void SerializingConfiguration_SerializesProperly() { - var deserialized = JsonConvert.DeserializeObject( ConfigurationJson ); - var serialized = JsonConvert.SerializeObject( deserialized ); + var deserialized = JsonSerializer.Deserialize( ConfigurationJson ); + var serialized = JsonSerializer.Serialize( deserialized ); Assert.That( serialized, Is.Not.Null.Or.Empty ); } @@ -46,7 +42,7 @@ public void SerializingConfiguration_SerializesProperly() [Test] public void DeserializingConfiguration_RestoresStructureProperly() { - var deserialized = JsonConvert.DeserializeObject( ConfigurationJson ); + var deserialized = JsonSerializer.Deserialize( ConfigurationJson ); Assert.That( deserialized, Is.Not.Null ); Assert.That( deserialized.AllAttributes, Has.Exactly( 80 ).Items ); diff --git a/src/Api.Rest.Dtos.Tests/Data/Converter/InspectionPlanDtoBaseConverterTests.cs b/src/Api.Rest.Dtos.Tests/Data/Converter/InspectionPlanDtoBaseConverterTests.cs index 5484561d..3c87e5ad 100644 --- a/src/Api.Rest.Dtos.Tests/Data/Converter/InspectionPlanDtoBaseConverterTests.cs +++ b/src/Api.Rest.Dtos.Tests/Data/Converter/InspectionPlanDtoBaseConverterTests.cs @@ -8,12 +8,11 @@ #endregion - namespace Zeiss.PiWeb.Api.Rest.Dtos.Tests.Data.Converter { #region usings - using Newtonsoft.Json; + using System.Text.Json; using NUnit.Framework; using Zeiss.PiWeb.Api.Rest.Dtos.Converter; using Zeiss.PiWeb.Api.Rest.Dtos.Data; @@ -23,66 +22,62 @@ namespace Zeiss.PiWeb.Api.Rest.Dtos.Tests.Data.Converter [TestFixture] public class InspectionPlanDtoBaseConverterTests { + #region members + + private static readonly JsonSerializerOptions Options = new() + { + DefaultIgnoreCondition = System.Text.Json.Serialization.JsonIgnoreCondition.WhenWritingNull, + Converters = { new InspectionPlanDtoBaseConverter() } + }; + + #endregion + #region methods [Test] public void Parse_HappyPath_ReturnsInspectionPlanPartDto() { - var json = "{\"attributes\": {\"1\": \"test\"}," + - "\"path\": \"/\"," + - "\"history\": null," + - "\"charChangeDate\": \"0001-01-01T00:00:00\"," + - "\"uuid\": \"00000000-0000-0000-0000-000000000000\"," + - "\"comment\": null," + - "\"version\": 0," + - "\"timestamp\": \"0001-01-01T00:00:00\"}"; - - var deserialized = JsonConvert.DeserializeObject( - json, - new InspectionPlanDtoBaseConverter() ); - - Assert.AreEqual( typeof( InspectionPlanPartDto ), deserialized.GetType() ); + const string json = "{\"attributes\": {\"1\": \"test\"}," + + "\"path\": \"/\"," + + "\"history\": null," + + "\"charChangeDate\": \"0001-01-01T00:00:00\"," + + "\"uuid\": \"00000000-0000-0000-0000-000000000000\"," + + "\"comment\": null," + + "\"version\": 0," + + "\"timestamp\": \"0001-01-01T00:00:00\"}"; + + var deserialized = JsonSerializer.Deserialize( json, Options ); + + Assert.That( deserialized, Is.TypeOf() ); } [Test] public void Parse_HappyPath_ReturnsSimplePartDto() { - var json = "{\"attributes\": {\"1\": \"test\"}," + - "\"path\": \"/\"," + - "\"charChangeDate\": \"0001-01-01T00:00:00\"," + - "\"uuid\": \"00000000-0000-0000-0000-000000000000\"," + - "\"timestamp\": \"0001-01-01T00:00:00\"}"; + const string json = "{\"attributes\": {\"1\": \"test\"}," + + "\"path\": \"/\"," + + "\"charChangeDate\": \"0001-01-01T00:00:00\"," + + "\"uuid\": \"00000000-0000-0000-0000-000000000000\"," + + "\"timestamp\": \"0001-01-01T00:00:00\"}"; - var deserialized = JsonConvert.DeserializeObject( - json, - new InspectionPlanDtoBaseConverter() ); + var deserialized = JsonSerializer.Deserialize( json, Options ); - Assert.AreEqual( typeof( SimplePartDto ), deserialized.GetType() ); + Assert.That( deserialized, Is.TypeOf() ); } [Test] public void Parse_HappyPath_ReturnsInspectionPlanCharacteristicDto() { - var json = "{\"attributes\": {\"1\": \"test\"}," + - "\"path\": \"C:/merkmal/\"," + - "\"uuid\": \"00000000-0000-0000-0000-000000000000\"," + - "\"comment\": null," + - "\"version\": 0," + - "\"timestamp\": \"0001-01-01T00:00:00\"}"; - - var deserialized = JsonConvert.DeserializeObject( - json, - new InspectionPlanDtoBaseConverter() ); - - Assert.AreEqual( typeof( InspectionPlanCharacteristicDto ), deserialized.GetType() ); - } + const string json = "{\"attributes\": {\"1\": \"test\"}," + + "\"path\": \"C:/merkmal/\"," + + "\"uuid\": \"00000000-0000-0000-0000-000000000000\"," + + "\"comment\": null," + + "\"version\": 0," + + "\"timestamp\": \"0001-01-01T00:00:00\"}"; - [Test] - public void Parse_EmptyJson_ReturnsNull() - { - var deserialized = JsonConvert.DeserializeObject( string.Empty, new InspectionPlanDtoBaseConverter() ); + var deserialized = JsonSerializer.Deserialize( json, Options ); - Assert.AreEqual( null, deserialized ); + Assert.That( deserialized, Is.TypeOf() ); } #endregion diff --git a/src/Api.Rest.Dtos.Tests/Data/InspectionPlanSerializationTests.cs b/src/Api.Rest.Dtos.Tests/Data/InspectionPlanSerializationTests.cs index f902cc83..63ba8613 100644 --- a/src/Api.Rest.Dtos.Tests/Data/InspectionPlanSerializationTests.cs +++ b/src/Api.Rest.Dtos.Tests/Data/InspectionPlanSerializationTests.cs @@ -14,8 +14,7 @@ namespace Zeiss.PiWeb.Api.Rest.Dtos.Tests.Data using System; using System.Collections.Generic; - using System.IO; - using Newtonsoft.Json; + using System.Text.Json; using NUnit.Framework; using Zeiss.PiWeb.Api.Rest.Dtos.Data; @@ -36,8 +35,8 @@ public class InspectionPlanSerializationTests [Test] public void SerializingParts_SerializesProperly() { - var deserialized = JsonConvert.DeserializeObject>( PartJson ); - var serialized = JsonConvert.SerializeObject( deserialized ); + var deserialized = JsonSerializer.Deserialize>( PartJson ); + var serialized = JsonSerializer.Serialize( deserialized ); Assert.That( serialized, Is.Not.Null.Or.Empty ); } @@ -45,8 +44,8 @@ public void SerializingParts_SerializesProperly() [Test] public void SerializingCharacteristics_SerializesProperly() { - var deserialized = JsonConvert.DeserializeObject>( CharacteristicJson ); - var serialized = JsonConvert.SerializeObject( deserialized ); + var deserialized = JsonSerializer.Deserialize>( CharacteristicJson ); + var serialized = JsonSerializer.Serialize( deserialized ); Assert.That( serialized, Is.Not.Null.Or.Empty ); } @@ -54,7 +53,7 @@ public void SerializingCharacteristics_SerializesProperly() [Test] public void DeserializingParts_RestoresStructureProperly() { - var deserialized = JsonConvert.DeserializeObject>( PartJson ); + var deserialized = JsonSerializer.Deserialize>( PartJson ); Assert.That( deserialized, Is.Not.Null ); Assert.That( deserialized, Has.Exactly( 2 ).Items ); @@ -84,7 +83,7 @@ public void DeserializingParts_RestoresStructureProperly() [Test] public void DeserializingCharacteristics_RestoresStructureProperly() { - var deserialized = JsonConvert.DeserializeObject>( CharacteristicJson ); + var deserialized = JsonSerializer.Deserialize>( CharacteristicJson ); Assert.That( deserialized, Is.Not.Null ); Assert.That( deserialized, Has.Exactly( 45 ).Items ); diff --git a/src/Api.Rest.Dtos.Tests/Data/MeasurementSerializationTests.cs b/src/Api.Rest.Dtos.Tests/Data/MeasurementSerializationTests.cs index 55696758..899909cb 100644 --- a/src/Api.Rest.Dtos.Tests/Data/MeasurementSerializationTests.cs +++ b/src/Api.Rest.Dtos.Tests/Data/MeasurementSerializationTests.cs @@ -14,11 +14,8 @@ namespace Zeiss.PiWeb.Api.Rest.Dtos.Tests.Data using System; using System.Collections.Generic; - using System.IO; - using Newtonsoft.Json; + using System.Text.Json; using NUnit.Framework; - using Zeiss.PiWeb.Api.Definitions; - using Zeiss.PiWeb.Api.Rest.Dtos.Converter; using Zeiss.PiWeb.Api.Rest.Dtos.Data; #endregion @@ -37,8 +34,8 @@ public class MeasurementSerializationTests [Test] public void SerializingMeasurements_SerializesProperly() { - var deserialized = JsonConvert.DeserializeObject>( MeasurementsJson ); - var serialized = JsonConvert.SerializeObject( deserialized ); + var deserialized = JsonSerializer.Deserialize>( MeasurementsJson ); + var serialized = JsonSerializer.Serialize( deserialized ); Assert.That( serialized, Is.Not.Null.Or.Empty ); } @@ -46,7 +43,7 @@ public void SerializingMeasurements_SerializesProperly() [Test] public void DeserializingMeasurements_RestoresStructureProperly() { - var deserialized = JsonConvert.DeserializeObject>( MeasurementsJson ); + var deserialized = JsonSerializer.Deserialize>( MeasurementsJson ); Assert.That( deserialized, Is.Not.Null ); Assert.That( deserialized, Has.Exactly( 600 ).Items ); diff --git a/src/Api.Rest.Dtos.Tests/Data/SerializationTestHelper.cs b/src/Api.Rest.Dtos.Tests/Data/SerializationTestHelper.cs index 395f6c12..83036b3c 100644 --- a/src/Api.Rest.Dtos.Tests/Data/SerializationTestHelper.cs +++ b/src/Api.Rest.Dtos.Tests/Data/SerializationTestHelper.cs @@ -12,12 +12,7 @@ namespace Zeiss.PiWeb.Api.Rest.Dtos.Tests.Data { #region usings - using System; - using System.Collections.Generic; using System.IO; - using Newtonsoft.Json; - using NUnit.Framework; - using Zeiss.PiWeb.Api.Rest.Dtos.Data; #endregion diff --git a/src/Api.Rest.Dtos.Tests/Data/ValueSerializationTests.cs b/src/Api.Rest.Dtos.Tests/Data/ValueSerializationTests.cs index 61218c21..7168ce3c 100644 --- a/src/Api.Rest.Dtos.Tests/Data/ValueSerializationTests.cs +++ b/src/Api.Rest.Dtos.Tests/Data/ValueSerializationTests.cs @@ -14,12 +14,9 @@ namespace Zeiss.PiWeb.Api.Rest.Dtos.Tests.Data using System; using System.Collections.Generic; - using System.IO; using System.Linq; - using Newtonsoft.Json; + using System.Text.Json; using NUnit.Framework; - using Zeiss.PiWeb.Api.Definitions; - using Zeiss.PiWeb.Api.Rest.Dtos.Converter; using Zeiss.PiWeb.Api.Rest.Dtos.Data; #endregion @@ -38,8 +35,8 @@ public class ValueSerializationTests [Test] public void SerializingValues_SerializesProperly() { - var deserialized = JsonConvert.DeserializeObject>( ValuesJson ); - var serialized = JsonConvert.SerializeObject( deserialized ); + var deserialized = JsonSerializer.Deserialize>( ValuesJson ); + var serialized = JsonSerializer.Serialize( deserialized ); Assert.That( serialized, Is.Not.Null.Or.Empty ); } @@ -47,7 +44,7 @@ public void SerializingValues_SerializesProperly() [Test] public void DeserializingValues_RestoresStructureProperly() { - var deserialized = JsonConvert.DeserializeObject>( ValuesJson ); + var deserialized = JsonSerializer.Deserialize>( ValuesJson ); Assert.That( deserialized, Is.Not.Null ); Assert.That( deserialized, Has.Exactly( 600 ).Items ); diff --git a/src/Api.Rest.Dtos/Api.Rest.Dtos.csproj b/src/Api.Rest.Dtos/Api.Rest.Dtos.csproj index 1043ba36..c8fb4191 100644 --- a/src/Api.Rest.Dtos/Api.Rest.Dtos.csproj +++ b/src/Api.Rest.Dtos/Api.Rest.Dtos.csproj @@ -51,7 +51,6 @@ - all diff --git a/src/Api.Rest.Dtos/Converter/AttributeArrayConverter.cs b/src/Api.Rest.Dtos/Converter/AttributeArrayConverter.cs index dd5b7969..05c3e27b 100644 --- a/src/Api.Rest.Dtos/Converter/AttributeArrayConverter.cs +++ b/src/Api.Rest.Dtos/Converter/AttributeArrayConverter.cs @@ -1,80 +1,70 @@ -#region copyright - -/* * * * * * * * * * * * * * * * * * * * * * * * * */ -/* Carl Zeiss IMT (IZfM Dresden) */ -/* Softwaresystem PiWeb */ -/* (c) Carl Zeiss 2015 */ -/* * * * * * * * * * * * * * * * * * * * * * * * * */ - -#endregion - -namespace Zeiss.PiWeb.Api.Rest.Dtos.Converter -{ - #region usings - - using System; - using System.Collections.Generic; - using Newtonsoft.Json; - using Zeiss.PiWeb.Api.Rest.Dtos.Data; - - #endregion - - /// - /// Specialized for collections. - /// - public sealed class AttributeArrayConverter : JsonConverter - { - #region methods - - /// - public override bool CanConvert( Type objectType ) - { - return typeof( IReadOnlyList ) == objectType; - } - - /// - public override object ReadJson( JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer ) - { - if( reader.TokenType != JsonToken.StartObject ) - return Array.Empty(); - - return ReadAttributes( reader ); - } - - internal static IReadOnlyList ReadAttributes( JsonReader reader ) - { - var result = new List(); - while( reader.Read() && reader.TokenType == JsonToken.PropertyName ) - { - var key = ushort.Parse( (string)reader.Value ); - var value = reader.ReadAsString(); - - result.Add( new AttributeDto( key, value ) ); - } - - return result; - } - - /// - public override void WriteJson( JsonWriter writer, object value, JsonSerializer serializer ) - { - writer.WriteStartObject(); - WriteAttributes( writer, (IReadOnlyList)value ); - writer.WriteEndObject(); - } - - internal static void WriteAttributes( JsonWriter writer, IReadOnlyList attributes ) - { - if( attributes == null || attributes.Count == 0 ) - return; - - foreach( var attribute in attributes ) - { - writer.WritePropertyName( AttributeKeyCache.StringForKey( attribute.Key ) ); - writer.WriteValue( attribute.RawValue ?? attribute.Value ); - } - } - - #endregion - } +#region copyright + +/* * * * * * * * * * * * * * * * * * * * * * * * * */ +/* Carl Zeiss IMT (IZfM Dresden) */ +/* Softwaresystem PiWeb */ +/* (c) Carl Zeiss 2022 */ +/* * * * * * * * * * * * * * * * * * * * * * * * * */ + +#endregion + +namespace Zeiss.PiWeb.Api.Rest.Dtos.Converter +{ + #region usings + + using System; + using System.Collections.Generic; + using System.Text.Json; + using System.Text.Json.Serialization; + using Zeiss.PiWeb.Api.Rest.Dtos.Data; + + #endregion + + /// + /// Specialized for collections. + /// + public sealed class AttributeArrayConverter : JsonConverter> + { + #region methods + + /// + public override IReadOnlyList Read( ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options ) + { + if( reader.TokenType != JsonTokenType.StartObject ) + return Array.Empty(); + + return ReadAttributes( ref reader ); + } + + internal static IReadOnlyList ReadAttributes( ref Utf8JsonReader reader ) + { + var result = new List(); + + while( reader.Read() && reader.TokenType == JsonTokenType.PropertyName ) + { + if( AttributeConverter.TryReadFromProperty( ref reader, out var attribute ) ) + result.Add( attribute ); + } + + return result; + } + + /// + public override void Write( Utf8JsonWriter writer, IReadOnlyList value, JsonSerializerOptions options ) + { + writer.WriteStartObject(); + + WriteAttributes( writer, value, options ); + + writer.WriteEndObject(); + } + + internal static void WriteAttributes( Utf8JsonWriter writer, IEnumerable value, JsonSerializerOptions options ) + { + foreach( var attribute in value ) + AttributeConverter.WriteAsProperty( writer, attribute, options ); + } + + #endregion + } } diff --git a/src/Api.Rest.Dtos/Converter/AttributeConverter.cs b/src/Api.Rest.Dtos/Converter/AttributeConverter.cs index 57aa6ab6..868a86f4 100644 --- a/src/Api.Rest.Dtos/Converter/AttributeConverter.cs +++ b/src/Api.Rest.Dtos/Converter/AttributeConverter.cs @@ -1,61 +1,99 @@ -#region copyright - -/* * * * * * * * * * * * * * * * * * * * * * * * * */ -/* Carl Zeiss IMT (IZM Dresden) */ -/* Softwaresystem PiWeb */ -/* (c) Carl Zeiss 2016 */ -/* * * * * * * * * * * * * * * * * * * * * * * * * */ - -#endregion - -namespace Zeiss.PiWeb.Api.Rest.Dtos.Converter -{ - #region usings - - using System; - using Newtonsoft.Json; - using Zeiss.PiWeb.Api.Rest.Dtos.Data; - - #endregion - - public sealed class AttributeConverter : JsonConverter - { - #region methods - - /// - public override bool CanConvert( Type objectType ) - { - return typeof( AttributeDto ) == objectType; - } - - /// - public override object ReadJson( JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer ) - { - AttributeDto result = default; - - while( reader.Read() && reader.TokenType == JsonToken.PropertyName ) - { - var key = ushort.Parse( (string)reader.Value ); - var value = reader.ReadAsString(); - - result = new AttributeDto( key, value ); - } - - return result; - } - - /// - public override void WriteJson( JsonWriter writer, object value, JsonSerializer serializer ) - { - writer.WriteStartObject(); - - var att = (AttributeDto)value; - writer.WritePropertyName( AttributeKeyCache.StringForKey( att.Key ) ); - writer.WriteValue( att.RawValue ?? att.Value ); - - writer.WriteEndObject(); - } - - #endregion - } -} +#region copyright + +/* * * * * * * * * * * * * * * * * * * * * * * * * */ +/* Carl Zeiss IMT (IZM Dresden) */ +/* Softwaresystem PiWeb */ +/* (c) Carl Zeiss 2016 */ +/* * * * * * * * * * * * * * * * * * * * * * * * * */ + +#endregion + +namespace Zeiss.PiWeb.Api.Rest.Dtos.Converter +{ + #region usings + + using System; + using System.Buffers; + using System.Buffers.Text; + using System.Text; + using System.Text.Json; + using System.Text.Json.Serialization; + using Zeiss.PiWeb.Api.Rest.Dtos.Data; + + #endregion + + /// + /// Specialized for -objects. + /// + public sealed class AttributeConverter : JsonConverter + { + #region methods + + /// + public override AttributeDto Read( ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options ) + { + AttributeDto result = default; + + while( reader.Read() && reader.TokenType == JsonTokenType.PropertyName ) + TryReadFromProperty( ref reader, out result ); + + return result; + } + + internal static bool TryReadFromProperty( ref Utf8JsonReader reader, out AttributeDto attribute ) + { + var keySpan = reader.HasValueSequence ? reader.ValueSequence.ToArray() : reader.ValueSpan; + + if( !Utf8Parser.TryParse( keySpan, out ushort key, out var bytesConsumed ) || keySpan.Length != bytesConsumed ) + throw new FormatException( $"Input span was not in a correct format, on converting to '{nameof( UInt16 )}'" ); + + reader.Read(); + + switch( reader.TokenType ) + { + case JsonTokenType.String: + attribute = new AttributeDto( key, reader.GetString() ); + return true; + + case JsonTokenType.Number: + var valueSpan = reader.HasValueSequence ? reader.ValueSequence.ToArray() : reader.ValueSpan; +#if NETSTANDARD + var value = Encoding.UTF8.GetString( valueSpan.ToArray() ); +#else + var value = Encoding.UTF8.GetString( valueSpan ); +#endif + attribute = new AttributeDto( key, value ); + return true; + } + + attribute = default; + + return false; + } + + /// + public override void Write( Utf8JsonWriter writer, AttributeDto value, JsonSerializerOptions options ) + { + writer.WriteStartObject(); + + WriteAsProperty( writer, value, options ); + + writer.WriteEndObject(); + } + + internal static void WriteAsProperty( Utf8JsonWriter writer, in AttributeDto value, JsonSerializerOptions options ) + { + var key = AttributeKeyCache.StringForKey( value.Key ); + + if( value.RawValue is not null ) + { + writer.WritePropertyName( key ); + JsonSerializer.Serialize( writer, value.RawValue, options ); + } + else + writer.WriteString( key, value.Value ); + } + + #endregion + } +} \ No newline at end of file diff --git a/src/Api.Rest.Dtos/Converter/AttributeDefinitionConverter.cs b/src/Api.Rest.Dtos/Converter/AttributeDefinitionConverter.cs index 2d17b2e6..f0c257ff 100644 --- a/src/Api.Rest.Dtos/Converter/AttributeDefinitionConverter.cs +++ b/src/Api.Rest.Dtos/Converter/AttributeDefinitionConverter.cs @@ -1,122 +1,185 @@ -#region copyright - -/* * * * * * * * * * * * * * * * * * * * * * * * * */ -/* Carl Zeiss IMT (IZfM Dresden) */ -/* Softwaresystem PiWeb */ -/* (c) Carl Zeiss 2015 */ -/* * * * * * * * * * * * * * * * * * * * * * * * * */ - -#endregion - -namespace Zeiss.PiWeb.Api.Rest.Dtos.Converter -{ - #region usings - - using System; - using System.Globalization; - using Newtonsoft.Json; - using Zeiss.PiWeb.Api.Rest.Dtos.Data; - - #endregion - - /// - /// Specialized for -objects. - /// - public sealed class AttributeDefinitionConverter : JsonConverter - { - #region methods - - /// - public override bool CanConvert( Type objectType ) - { - return typeof( AbstractAttributeDefinitionDto ) == objectType || typeof( AttributeDefinitionDto ) == objectType || typeof( CatalogAttributeDefinitionDto ) == objectType; - } - - /// - public override object ReadJson( JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer ) - { - var key = default( ushort ); - var length = default( ushort? ); - var queryEfficient = default( bool ); - var description = default( string ); - var attributeDefinitionType = default( string ); - var type = default( AttributeTypeDto ); - var catalogUuid = default( Guid ); - - while( reader.Read() && reader.TokenType == JsonToken.PropertyName ) - { - switch( reader.Value.ToString() ) - { - case "key": - key = ushort.Parse( reader.ReadAsString(), CultureInfo.InvariantCulture ); - break; - case "queryEfficient": - queryEfficient = bool.Parse( reader.ReadAsString() ); - break; - case "description": - description = reader.ReadAsString(); - break; - case "length": - length = ushort.Parse( reader.ReadAsString(), CultureInfo.InvariantCulture ); - break; - case "type": - type = (AttributeTypeDto)Enum.Parse( typeof( AttributeTypeDto ), reader.ReadAsString() ); - break; - case "catalog": - catalogUuid = Guid.Parse( reader.ReadAsString() ); - break; - case "definitionType": - attributeDefinitionType = reader.ReadAsString(); - break; - } - } - - if( attributeDefinitionType == "AttributeDefinition" ) - return new AttributeDefinitionDto { Description = description, Key = key, Length = length, QueryEfficient = queryEfficient, Type = type }; - - if( attributeDefinitionType == "CatalogAttributeDefinition" ) - return new CatalogAttributeDefinitionDto { Description = description, Key = key, QueryEfficient = queryEfficient, Catalog = catalogUuid }; - - return null; - } - - /// - public override void WriteJson( JsonWriter writer, object value, JsonSerializer serializer ) - { - if( value is AbstractAttributeDefinitionDto definition ) - { - writer.WriteStartObject(); - writer.WritePropertyName( "key" ); - writer.WriteValue( definition.Key ); - writer.WritePropertyName( "description" ); - writer.WriteValue( definition.Description ); - - if( definition is AttributeDefinitionDto attributeDef ) - { - if( attributeDef.Length.HasValue ) - { - writer.WritePropertyName( "length" ); - writer.WriteValue( attributeDef.Length.Value ); - } - - writer.WritePropertyName( "type" ); - serializer.Serialize( writer, attributeDef.Type ); - writer.WritePropertyName( "definitionType" ); - writer.WriteValue( "AttributeDefinition" ); - } - - if( definition is CatalogAttributeDefinitionDto catalogDef ) - { - writer.WritePropertyName( "catalog" ); - writer.WriteValue( catalogDef.Catalog ); - writer.WritePropertyName( "definitionType" ); - writer.WriteValue( "CatalogAttributeDefinition" ); - } - - writer.WriteEndObject(); - } - } - - #endregion - } +#region copyright + +/* * * * * * * * * * * * * * * * * * * * * * * * * */ +/* Carl Zeiss IMT (IZfM Dresden) */ +/* Softwaresystem PiWeb */ +/* (c) Carl Zeiss 2015 */ +/* * * * * * * * * * * * * * * * * * * * * * * * * */ + +#endregion + +namespace Zeiss.PiWeb.Api.Rest.Dtos.Converter +{ + #region usings + + using System; + using System.Text; + using System.Text.Json; + using System.Text.Json.Serialization; + using Zeiss.PiWeb.Api.Rest.Dtos.Data; + + #endregion + + /// + /// Specialized for -objects. + /// + public sealed class AbstractAttributeDefinitionConverter : JsonConverter + { + #region members + + private static readonly byte[] KeyPropertyName = Encoding.UTF8.GetBytes( "key" ); + private static readonly byte[] QueryEfficientPropertyName = Encoding.UTF8.GetBytes( "queryEfficient" ); + private static readonly byte[] DescriptionPropertyName = Encoding.UTF8.GetBytes( "description" ); + private static readonly byte[] LengthPropertyName = Encoding.UTF8.GetBytes( "length" ); + private static readonly byte[] TypePropertyName = Encoding.UTF8.GetBytes( "type" ); + private static readonly byte[] CatalogPropertyName = Encoding.UTF8.GetBytes( "catalog" ); + private static readonly byte[] DefinitionTypePropertyName = Encoding.UTF8.GetBytes( "definitionType" ); + + private static readonly byte[] AttributeDefinitionTypeId = Encoding.UTF8.GetBytes( "AttributeDefinition" ); + private static readonly byte[] CatalogAttributeDefinitionTypeId = Encoding.UTF8.GetBytes( "CatalogAttributeDefinition" ); + + #endregion + + #region methods + + /// + public override bool CanConvert( Type typeToConvert ) + { + return typeof( AbstractAttributeDefinitionDto ).IsAssignableFrom( typeToConvert ); + } + + /// + public override AbstractAttributeDefinitionDto Read( ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options ) + { + return ReadFromObject( ref reader, options ); + } + + internal static AbstractAttributeDefinitionDto ReadFromObject( ref Utf8JsonReader reader, JsonSerializerOptions options ) + { + var key = default( ushort ); + var length = default( ushort? ); + var queryEfficient = default( bool ); + var description = default( string ); + var attributeDefinitionType = default( ReadOnlySpan ); + var type = default( AttributeTypeDto ); + var catalogUuid = default( Guid ); + + while( reader.Read() && reader.TokenType == JsonTokenType.PropertyName ) + { + if( reader.ValueTextEquals( KeyPropertyName ) ) + { + reader.Read(); + key = reader.GetUInt16(); + } + else if( reader.ValueTextEquals( QueryEfficientPropertyName ) ) + { + reader.Read(); + queryEfficient = reader.GetBoolean(); + } + else if( reader.ValueTextEquals( DescriptionPropertyName ) ) + { + reader.Read(); + description = reader.GetString(); + } + else if( reader.ValueTextEquals( LengthPropertyName ) ) + { + reader.Read(); + length = reader.GetUInt16(); + } + else if( reader.ValueTextEquals( TypePropertyName ) ) + { + reader.Read(); + type = JsonSerializer.Deserialize( ref reader, options ); + } + else if( reader.ValueTextEquals( CatalogPropertyName ) ) + { + reader.Read(); + catalogUuid = reader.GetGuid(); + } + else if( reader.ValueTextEquals( DefinitionTypePropertyName ) ) + { + reader.Read(); + attributeDefinitionType = reader.ValueSpan; + } + } + + if( attributeDefinitionType.SequenceEqual( AttributeDefinitionTypeId ) ) + return new AttributeDefinitionDto { Description = description, Key = key, Length = length, QueryEfficient = queryEfficient, Type = type }; + else if( attributeDefinitionType.SequenceEqual( CatalogAttributeDefinitionTypeId ) ) + return new CatalogAttributeDefinitionDto { Description = description, Key = key, QueryEfficient = queryEfficient, Catalog = catalogUuid }; + + return null; + } + + /// + public override void Write( Utf8JsonWriter writer, AbstractAttributeDefinitionDto value, JsonSerializerOptions options ) + { + WriteAsObject( writer, value, options ); + } + + internal static void WriteAsObject( Utf8JsonWriter writer, AbstractAttributeDefinitionDto value, JsonSerializerOptions options ) + { + writer.WriteStartObject(); + + writer.WriteNumber( KeyPropertyName, value.Key ); + writer.WriteString( DescriptionPropertyName, value.Description ); + + if( value is AttributeDefinitionDto attributeDef ) + { + if( attributeDef.Length.HasValue ) + writer.WriteNumber( LengthPropertyName, attributeDef.Length.Value ); + + writer.WritePropertyName( TypePropertyName ); + JsonSerializer.Serialize( writer, attributeDef.Type, options ); + + writer.WriteString( DefinitionTypePropertyName, AttributeDefinitionTypeId ); + } + + if( value is CatalogAttributeDefinitionDto catalogDef ) + { + writer.WriteString( CatalogPropertyName, catalogDef.Catalog ); + writer.WriteString( DefinitionTypePropertyName, CatalogAttributeDefinitionTypeId ); + } + + writer.WriteEndObject(); + } + + #endregion + } + + /// + /// Specialized for -objects. + /// + public sealed class JsonAttributeDefinitionConverter : JsonConverter + { + /// + public override AttributeDefinitionDto Read( ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options ) + { + return (AttributeDefinitionDto)AbstractAttributeDefinitionConverter.ReadFromObject( ref reader, options ); + } + + /// + public override void Write( Utf8JsonWriter writer, AttributeDefinitionDto value, JsonSerializerOptions options ) + { + AbstractAttributeDefinitionConverter.WriteAsObject( writer, value, options ); + } + } + + /// + /// Specialized for -objects. + /// + public sealed class JsonCatalogAttributeDefinitionConverter : JsonConverter + { + /// + public override CatalogAttributeDefinitionDto Read( ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options ) + { + return (CatalogAttributeDefinitionDto)AbstractAttributeDefinitionConverter.ReadFromObject( ref reader, options ); + } + + /// + public override void Write( Utf8JsonWriter writer, CatalogAttributeDefinitionDto value, JsonSerializerOptions options ) + { + AbstractAttributeDefinitionConverter.WriteAsObject( writer, value, options ); + } + } } \ No newline at end of file diff --git a/src/Api.Rest.Dtos/Converter/DataValueConverter.cs b/src/Api.Rest.Dtos/Converter/DataValueConverter.cs index 179bd17e..fd55a247 100644 --- a/src/Api.Rest.Dtos/Converter/DataValueConverter.cs +++ b/src/Api.Rest.Dtos/Converter/DataValueConverter.cs @@ -1,9 +1,9 @@ #region copyright /* * * * * * * * * * * * * * * * * * * * * * * * * */ -/* Carl Zeiss IMT (IZfM Dresden) */ +/* Carl Zeiss IMT (IZM Dresden) */ /* Softwaresystem PiWeb */ -/* (c) Carl Zeiss 2015 */ +/* (c) Carl Zeiss 2022 */ /* * * * * * * * * * * * * * * * * * * * * * * * * */ #endregion @@ -13,38 +13,30 @@ namespace Zeiss.PiWeb.Api.Rest.Dtos.Converter #region usings using System; - using System.Collections.Generic; - using System.Globalization; - using System.Linq; - using Newtonsoft.Json; + using System.Text.Json; + using System.Text.Json.Serialization; using Zeiss.PiWeb.Api.Rest.Dtos.Data; #endregion /// - /// Specialized for -objects. + /// Specialized for -objects. /// - public sealed class DataValueConverter : JsonConverter + public sealed class DataValueConverter : JsonConverter { #region methods /// - public override bool CanConvert( Type objectType ) + public override DataValueDto Read( ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options ) { - return objectType == typeof( IReadOnlyCollection ); + return new DataValueDto( AttributeArrayConverter.ReadAttributes( ref reader ) ); } /// - public override object ReadJson( JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer ) - { - return new DataValueDto( AttributeArrayConverter.ReadAttributes( reader ) ); - } - - /// - public override void WriteJson( JsonWriter writer, object value, JsonSerializer serializer ) + public override void Write( Utf8JsonWriter writer, DataValueDto value, JsonSerializerOptions options ) { writer.WriteStartObject(); - AttributeArrayConverter.WriteAttributes( writer, ((DataValueDto)value ).Attributes ); + AttributeArrayConverter.WriteAttributes( writer, value.Attributes, options ); writer.WriteEndObject(); } diff --git a/src/Api.Rest.Dtos/Converter/InspectionPlanDtoBaseConverter.cs b/src/Api.Rest.Dtos/Converter/InspectionPlanDtoBaseConverter.cs index 77abeb5d..a0193c65 100644 --- a/src/Api.Rest.Dtos/Converter/InspectionPlanDtoBaseConverter.cs +++ b/src/Api.Rest.Dtos/Converter/InspectionPlanDtoBaseConverter.cs @@ -1,147 +1,118 @@ -#region copyright - -/* * * * * * * * * * * * * * * * * * * * * * * * * */ -/* Carl Zeiss IMT (IZfM Dresden) */ -/* Softwaresystem PiWeb */ -/* (c) Carl Zeiss 2021 */ -/* * * * * * * * * * * * * * * * * * * * * * * * * */ - -#endregion - -namespace Zeiss.PiWeb.Api.Rest.Dtos.Converter -{ - #region usings - - using System; - using System.Collections.Generic; - using System.Linq; - using Newtonsoft.Json; - using Newtonsoft.Json.Linq; - using Zeiss.PiWeb.Api.Rest.Dtos.Data; - - #endregion - - /// - /// Specialized for -objects. - /// - public sealed class InspectionPlanDtoBaseConverter : JsonConverter - { - #region constants - - private const string HistoryFieldName = "history"; - private const string CharChangeDateFieldName = "charChangeDate"; - - #endregion - - #region methods - - /// - public override void WriteJson( JsonWriter writer, object value, JsonSerializer serializer ) - { - switch( value ) - { - case null: - writer.WriteNull(); - break; - - case InspectionPlanPartDto _: - serializer.Serialize( writer, value, typeof( InspectionPlanPartDto ) ); - break; - - case InspectionPlanCharacteristicDto _: - serializer.Serialize( writer, value, typeof( InspectionPlanCharacteristicDto ) ); - break; - - case SimplePartDto _: - serializer.Serialize( writer, value, typeof( SimplePartDto ) ); - break; - - default: - throw new JsonSerializationException( $"{nameof( value )} is invalid!" ); - } - } - - /// - public override object ReadJson( JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer ) - { - if( reader == null ) - throw new ArgumentNullException( nameof( reader ) ); - - if( reader.TokenType == JsonToken.Null ) - return null; - - var jToken = JToken.Load( reader ); - - if( jToken == null ) - throw new ArgumentNullException( nameof( jToken ) ); - - var target = existingValue ?? Create( jToken, serializer ); - - if( target == null ) - throw new JsonSerializationException( "No object created." ); - - return target; - } - - private static object Create( JToken jObject, JsonSerializer serializer ) - { - using( var jsonReader = new JTokenReader( jObject ) ) - { - var type = GetType( jObject ); - - switch( type ) - { - case InspectionPlanItemType.SimplePartDto: - return serializer.Deserialize( jsonReader ); - - case InspectionPlanItemType.InspectionPlanPartDto: - return serializer.Deserialize( jsonReader ); - - case InspectionPlanItemType.InspectionPlanCharacteristicDto: - return serializer.Deserialize( jsonReader ); - - default: - throw new InvalidOperationException( "No object created." ); - } - } - } - - private static InspectionPlanItemType GetType( JToken jToken ) - { - var fields = CollectFields( jToken ); - - if( fields.Exists( x => x.Equals( HistoryFieldName, StringComparison.OrdinalIgnoreCase ) ) && - fields.Exists( x => x.Equals( CharChangeDateFieldName, StringComparison.OrdinalIgnoreCase ) ) ) - return InspectionPlanItemType.InspectionPlanPartDto; - - if( fields.Exists( x => x.Equals( CharChangeDateFieldName, StringComparison.OrdinalIgnoreCase ) ) ) - return InspectionPlanItemType.SimplePartDto; - - return InspectionPlanItemType.InspectionPlanCharacteristicDto; - } - - private static List CollectFields( JToken jToken ) - { - return jToken.Children().Select( i => i.Path ).ToList(); - } - - /// - public override bool CanConvert( Type objectType ) - { - return objectType == typeof( InspectionPlanDtoBase ); - } - - #endregion - - #region class InspectionPlanItemType - - private enum InspectionPlanItemType - { - SimplePartDto, - InspectionPlanPartDto, - InspectionPlanCharacteristicDto - } - - #endregion - } +#region copyright + +/* * * * * * * * * * * * * * * * * * * * * * * * * */ +/* Carl Zeiss IMT (IZfM Dresden) */ +/* Softwaresystem PiWeb */ +/* (c) Carl Zeiss 2022 */ +/* * * * * * * * * * * * * * * * * * * * * * * * * */ + +#endregion + +namespace Zeiss.PiWeb.Api.Rest.Dtos.Converter +{ + #region usings + + using System; + using System.Collections.Generic; + using System.Linq; + using System.Text.Json; + using System.Text.Json.Serialization; + using Zeiss.PiWeb.Api.Rest.Dtos.Data; + + #endregion + + /// + /// Specialized for -objects. + /// + public sealed class InspectionPlanDtoBaseConverter : JsonConverter + { + #region methods + + /// + public override void Write( Utf8JsonWriter writer, InspectionPlanDtoBase value, JsonSerializerOptions options ) + { + switch( value ) + { + case null: + writer.WriteNullValue(); + break; + + case InspectionPlanPartDto inspectionPlanPart: + JsonSerializer.Serialize( writer, inspectionPlanPart, options ); + break; + + case SimplePartDto simplePart: + JsonSerializer.Serialize( writer, simplePart, options ); + break; + + case InspectionPlanCharacteristicDto inspectionPlanCharacteristic: + JsonSerializer.Serialize( writer, inspectionPlanCharacteristic, options ); + break; + + default: + throw new NotImplementedException( $"{value.GetType().Name}" ); + } + } + + /// + public override InspectionPlanDtoBase Read( ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options ) + { + var type = GetType( ref reader ); + + return type switch + { + InspectionPlanItemType.InspectionPlanPartDto => JsonSerializer.Deserialize( ref reader, options ), + + InspectionPlanItemType.SimplePartDto => JsonSerializer.Deserialize( ref reader, options ), + + InspectionPlanItemType.InspectionPlanCharacteristicDto => JsonSerializer.Deserialize( ref reader, options ), + + _ => throw new NotImplementedException($"{type}") + }; + } + + private static InspectionPlanItemType GetType( ref Utf8JsonReader reader ) + { + var propertyNames = CollectPropertyNames( reader ); + + if( propertyNames.Any( propertyName => propertyName.Equals( nameof( InspectionPlanPartDto.History ), StringComparison.OrdinalIgnoreCase ) ) && + propertyNames.Any( propertyName => propertyName.Equals( nameof( InspectionPlanPartDto.CharChangeDate ), StringComparison.OrdinalIgnoreCase ) ) ) + return InspectionPlanItemType.InspectionPlanPartDto; + + if( propertyNames.Any( propertyName => propertyName.Equals( nameof( SimplePartDto.CharChangeDate ), StringComparison.OrdinalIgnoreCase ) ) ) + return InspectionPlanItemType.SimplePartDto; + + return InspectionPlanItemType.InspectionPlanCharacteristicDto; + } + + private static IReadOnlyList CollectPropertyNames( Utf8JsonReader reader ) + { + var propertyNames = new List(); + + var startDepth = reader.CurrentDepth; + + while( reader.Read() && ( reader.TokenType != JsonTokenType.EndObject || reader.CurrentDepth != startDepth ) ) + { + if( reader.TokenType == JsonTokenType.PropertyName && reader.CurrentDepth == startDepth + 1 ) + propertyNames.Add( reader.GetString() ); + else + reader.TrySkip(); + } + + return propertyNames; + } + + #endregion + + #region InspectionPlanItemType + + private enum InspectionPlanItemType + { + InspectionPlanPartDto, + SimplePartDto, + InspectionPlanCharacteristicDto + } + + #endregion + } } \ No newline at end of file diff --git a/src/Api.Rest.Dtos/Converter/PathInformationConverter.cs b/src/Api.Rest.Dtos/Converter/PathInformationConverter.cs index bcb15007..d07b2372 100644 --- a/src/Api.Rest.Dtos/Converter/PathInformationConverter.cs +++ b/src/Api.Rest.Dtos/Converter/PathInformationConverter.cs @@ -1,52 +1,47 @@ -#region copyright - -/* * * * * * * * * * * * * * * * * * * * * * * * * */ -/* Carl Zeiss IMT (IZfM Dresden) */ -/* Softwaresystem PiWeb */ -/* (c) Carl Zeiss 2015 */ -/* * * * * * * * * * * * * * * * * * * * * * * * * */ - -#endregion - -namespace Zeiss.PiWeb.Api.Rest.Dtos.Converter -{ - #region usings - - using System; - using Newtonsoft.Json; - using Zeiss.PiWeb.Api.Rest.Dtos.Data; - - #endregion - - /// - /// Specialized for -objects. - /// - public sealed class PathInformationConverter : JsonConverter - { - #region methods - - /// - public override bool CanConvert( Type objectType ) - { - return typeof( PathInformationDto ) == objectType; - } - - /// - public override object ReadJson( JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer ) - { - if( reader.TokenType != JsonToken.String ) - return null; - - return PathHelper.RoundtripString2PathInformation( (string)reader.Value ); - - } - - /// - public override void WriteJson( JsonWriter writer, object value, JsonSerializer serializer ) - { - writer.WriteValue( PathHelper.PathInformation2RoundtripString( (PathInformationDto)value ) ); - } - - #endregion - } +#region copyright + +/* * * * * * * * * * * * * * * * * * * * * * * * * */ +/* Carl Zeiss IMT (IZfM Dresden) */ +/* Softwaresystem PiWeb */ +/* (c) Carl Zeiss 2015 */ +/* * * * * * * * * * * * * * * * * * * * * * * * * */ + +#endregion + +namespace Zeiss.PiWeb.Api.Rest.Dtos.Converter +{ + #region usings + + using System; + using System.Text.Json; + using System.Text.Json.Serialization; + using Zeiss.PiWeb.Api.Rest.Dtos.Data; + + #endregion + + /// + /// Specialized for -objects. + /// + public sealed class PathInformationConverter : JsonConverter + { + #region methods + + /// + public override PathInformationDto Read( ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options ) + { + if( reader.TokenType != JsonTokenType.String ) + return null; + + return PathHelper.RoundtripString2PathInformation( reader.GetString() ); + + } + + /// + public override void Write( Utf8JsonWriter writer, PathInformationDto value, JsonSerializerOptions options ) + { + writer.WriteStringValue( PathHelper.PathInformation2RoundtripString( value ) ); + } + + #endregion + } } \ No newline at end of file diff --git a/src/Api.Rest.Dtos/Data/AbstractAttributeDefinitionDto.cs b/src/Api.Rest.Dtos/Data/AbstractAttributeDefinitionDto.cs index 7dfd2b71..a86a2787 100644 --- a/src/Api.Rest.Dtos/Data/AbstractAttributeDefinitionDto.cs +++ b/src/Api.Rest.Dtos/Data/AbstractAttributeDefinitionDto.cs @@ -14,7 +14,6 @@ namespace Zeiss.PiWeb.Api.Rest.Dtos.Data using System.Text.Json.Serialization; using Zeiss.PiWeb.Api.Rest.Dtos.Converter; - using Zeiss.PiWeb.Api.Rest.Dtos.JsonConverters; #endregion @@ -22,8 +21,7 @@ namespace Zeiss.PiWeb.Api.Rest.Dtos.Data /// Abstract base class of ans . /// It holds attribute's base properties key and description. /// - [Newtonsoft.Json.JsonConverter( typeof( AttributeDefinitionConverter ) )] - [JsonConverter( typeof( JsonAbstractAttributeDefinitionConverter ) )] + [JsonConverter( typeof( AbstractAttributeDefinitionConverter ) )] public abstract class AbstractAttributeDefinitionDto { #region constructors diff --git a/src/Api.Rest.Dtos/Data/AttributeDefinitionDto.cs b/src/Api.Rest.Dtos/Data/AttributeDefinitionDto.cs index aeb71127..1d58aef9 100644 --- a/src/Api.Rest.Dtos/Data/AttributeDefinitionDto.cs +++ b/src/Api.Rest.Dtos/Data/AttributeDefinitionDto.cs @@ -14,14 +14,12 @@ namespace Zeiss.PiWeb.Api.Rest.Dtos.Data using System.Text.Json.Serialization; using Zeiss.PiWeb.Api.Rest.Dtos.Converter; - using Zeiss.PiWeb.Api.Rest.Dtos.JsonConverters; #endregion /// /// Defines an entity's attribute. /// - [Newtonsoft.Json.JsonConverter( typeof( AttributeDefinitionConverter ) )] [JsonConverter( typeof( JsonAttributeDefinitionConverter ) )] public sealed class AttributeDefinitionDto : AbstractAttributeDefinitionDto { diff --git a/src/Api.Rest.Dtos/Data/AttributeDto.cs b/src/Api.Rest.Dtos/Data/AttributeDto.cs index c65a0e7e..341a4c42 100644 --- a/src/Api.Rest.Dtos/Data/AttributeDto.cs +++ b/src/Api.Rest.Dtos/Data/AttributeDto.cs @@ -18,7 +18,6 @@ namespace Zeiss.PiWeb.Api.Rest.Dtos.Data using System.Xml; using JetBrains.Annotations; using Zeiss.PiWeb.Api.Rest.Dtos.Converter; - using Zeiss.PiWeb.Api.Rest.Dtos.JsonConverters; #endregion @@ -27,8 +26,7 @@ namespace Zeiss.PiWeb.Api.Rest.Dtos.Data /// /// This class is immutable. [Serializable] - [Newtonsoft.Json.JsonConverter( typeof( AttributeConverter ) )] - [JsonConverter( typeof( JsonAttributeConverter ) )] + [JsonConverter( typeof( AttributeConverter ) )] public readonly struct AttributeDto : IEquatable { #region members diff --git a/src/Api.Rest.Dtos/Data/AttributeTypeDto.cs b/src/Api.Rest.Dtos/Data/AttributeTypeDto.cs index 71440375..a01386c6 100644 --- a/src/Api.Rest.Dtos/Data/AttributeTypeDto.cs +++ b/src/Api.Rest.Dtos/Data/AttributeTypeDto.cs @@ -19,7 +19,6 @@ namespace Zeiss.PiWeb.Api.Rest.Dtos.Data /// /// Holds attributes' possible data types. /// - [Newtonsoft.Json.JsonConverter( typeof( Newtonsoft.Json.Converters.StringEnumConverter ) )] [JsonConverter( typeof( JsonStringEnumConverter ) )] public enum AttributeTypeDto { diff --git a/src/Api.Rest.Dtos/Data/CatalogAttributeDefinitionDto.cs b/src/Api.Rest.Dtos/Data/CatalogAttributeDefinitionDto.cs index 965cd6f0..3ebd87f3 100644 --- a/src/Api.Rest.Dtos/Data/CatalogAttributeDefinitionDto.cs +++ b/src/Api.Rest.Dtos/Data/CatalogAttributeDefinitionDto.cs @@ -15,14 +15,12 @@ namespace Zeiss.PiWeb.Api.Rest.Dtos.Data using System; using System.Text.Json.Serialization; using Zeiss.PiWeb.Api.Rest.Dtos.Converter; - using Zeiss.PiWeb.Api.Rest.Dtos.JsonConverters; #endregion /// /// Defines an entity's attribute which is based on a . /// - [Newtonsoft.Json.JsonConverter( typeof( AttributeDefinitionConverter ) )] [JsonConverter( typeof( JsonCatalogAttributeDefinitionConverter ) )] public sealed class CatalogAttributeDefinitionDto : AbstractAttributeDefinitionDto { diff --git a/src/Api.Rest.Dtos/Data/CatalogDto.cs b/src/Api.Rest.Dtos/Data/CatalogDto.cs index 72a86c13..636361ba 100644 --- a/src/Api.Rest.Dtos/Data/CatalogDto.cs +++ b/src/Api.Rest.Dtos/Data/CatalogDto.cs @@ -53,7 +53,6 @@ public CatalogEntryDto this[ short key ] /// /// Gets or sets a list of possible catalog entry attribute (i.e. columns of a catalog). /// - [Newtonsoft.Json.JsonProperty( "validAttributes" )] [JsonPropertyName( "validAttributes" )] public IReadOnlyList ValidAttributes { @@ -64,7 +63,6 @@ public IReadOnlyList ValidAttributes /// /// Gets or sets the list of catalog entries that belong to this catalog. /// - [Newtonsoft.Json.JsonProperty( "catalogEntries" )] [JsonPropertyName( "catalogEntries" )] public IReadOnlyList CatalogEntries { diff --git a/src/Api.Rest.Dtos/Data/CatalogEntryDto.cs b/src/Api.Rest.Dtos/Data/CatalogEntryDto.cs index aaf2e446..ae977988 100644 --- a/src/Api.Rest.Dtos/Data/CatalogEntryDto.cs +++ b/src/Api.Rest.Dtos/Data/CatalogEntryDto.cs @@ -20,7 +20,6 @@ namespace Zeiss.PiWeb.Api.Rest.Dtos.Data using System.Text.Json.Serialization; using JetBrains.Annotations; using Zeiss.PiWeb.Api.Rest.Dtos.Converter; - using Zeiss.PiWeb.Api.Rest.Dtos.JsonConverters; #endregion @@ -52,7 +51,6 @@ public CatalogEntryDto() /// /// Gets or sets the unique key of this catalog entry. /// - [Newtonsoft.Json.JsonProperty( "key" )] [JsonPropertyName( "key" )] public short Key { get; set; } @@ -111,8 +109,7 @@ private static object GetTypedAttributeValue( AttributeDto attribute ) #region interface IAttributeItemDto /// - [Newtonsoft.Json.JsonProperty( "attributes" ), Newtonsoft.Json.JsonConverter( typeof( AttributeArrayConverter ) )] - [JsonPropertyName( "attributes" ), JsonConverter( typeof( JsonAttributeArrayConverter ) )] + [JsonPropertyName( "attributes" ), JsonConverter( typeof( AttributeArrayConverter ) )] public IReadOnlyList Attributes { [NotNull] get => _Attributes; diff --git a/src/Api.Rest.Dtos/Data/ConfigurationDto.cs b/src/Api.Rest.Dtos/Data/ConfigurationDto.cs index 101b40b1..c9f21eb9 100644 --- a/src/Api.Rest.Dtos/Data/ConfigurationDto.cs +++ b/src/Api.Rest.Dtos/Data/ConfigurationDto.cs @@ -72,7 +72,6 @@ private Dictionary CatalogAttributesDict /// /// Returns a list of all attribute definitions in this configuration. /// - [Newtonsoft.Json.JsonIgnore] [JsonIgnore] public IReadOnlyCollection AllAttributes { @@ -82,7 +81,6 @@ public IReadOnlyCollection AllAttributes /// /// Gets or sets a list of all part attribute definitions. /// - [Newtonsoft.Json.JsonProperty( "partAttributes" )] [JsonPropertyName( "partAttributes" )] public IReadOnlyList PartAttributes { @@ -97,7 +95,6 @@ public IReadOnlyList PartAttributes /// /// Gets or sets a list of all characteristic attribute definitions. /// - [Newtonsoft.Json.JsonProperty( "characteristicAttributes" )] [JsonPropertyName( "characteristicAttributes" )] public IReadOnlyList CharacteristicAttributes { @@ -112,7 +109,6 @@ public IReadOnlyList CharacteristicAttributes /// /// Gets or sets a list of all measurement attribute definitions. /// - [Newtonsoft.Json.JsonProperty( "measurementAttributes" )] [JsonPropertyName( "measurementAttributes" )] public IReadOnlyList MeasurementAttributes { @@ -127,7 +123,6 @@ public IReadOnlyList MeasurementAttributes /// /// Gets or sets a list of all value attribute definitions. /// - [Newtonsoft.Json.JsonProperty( "valueAttributes" )] [JsonPropertyName( "valueAttributes" )] public IReadOnlyList ValueAttributes { @@ -142,7 +137,6 @@ public IReadOnlyList ValueAttributes /// /// Gets or sets a list of all catalog attribute definitions. /// - [Newtonsoft.Json.JsonProperty( "catalogAttributes" )] [JsonPropertyName( "catalogAttributes" )] public IReadOnlyList CatalogAttributes { @@ -158,7 +152,6 @@ public IReadOnlyList CatalogAttributes /// The attribute versioningType defines, whether updates to parts or characteristics /// overwrite existing values, or whether they create a new version of the entity. /// - [Newtonsoft.Json.JsonProperty( "versioningType" )] [JsonPropertyName( "versioningType" )] public VersioningTypeDto VersioningType { get; set; } diff --git a/src/Api.Rest.Dtos/Data/DataMeasurementDto.cs b/src/Api.Rest.Dtos/Data/DataMeasurementDto.cs index eeb37ea7..8ddcfd5e 100644 --- a/src/Api.Rest.Dtos/Data/DataMeasurementDto.cs +++ b/src/Api.Rest.Dtos/Data/DataMeasurementDto.cs @@ -16,7 +16,6 @@ namespace Zeiss.PiWeb.Api.Rest.Dtos.Data using System.Collections.Generic; using System.Text.Json.Serialization; using JetBrains.Annotations; - using Newtonsoft.Json; #endregion @@ -27,8 +26,6 @@ public class DataMeasurementDto : SimpleMeasurementDto { #region members - // Newtonsoft.Json is not able to create an empty dictionary if the property is not set. - // If Newtonsoft.Json support is discontinued, this initialization should no longer be necessary. [NotNull] private IReadOnlyDictionary _Characteristics = new Dictionary(); #endregion @@ -38,7 +35,6 @@ public class DataMeasurementDto : SimpleMeasurementDto /// /// Gets or sets the measurement values. /// - [JsonProperty( "characteristics" )] [JsonPropertyName( "characteristics" )] public IReadOnlyDictionary Characteristics { diff --git a/src/Api.Rest.Dtos/Data/DataValueDto.cs b/src/Api.Rest.Dtos/Data/DataValueDto.cs index b9af1c0e..30868c88 100644 --- a/src/Api.Rest.Dtos/Data/DataValueDto.cs +++ b/src/Api.Rest.Dtos/Data/DataValueDto.cs @@ -16,18 +16,15 @@ namespace Zeiss.PiWeb.Api.Rest.Dtos.Data using System.Collections.Generic; using System.Text.Json.Serialization; using JetBrains.Annotations; - using Newtonsoft.Json; using Zeiss.PiWeb.Api.Definitions; using Zeiss.PiWeb.Api.Rest.Dtos.Converter; - using Zeiss.PiWeb.Api.Rest.Dtos.JsonConverters; #endregion /// /// This class represents a single measurement value that belongs to one characteristic and one measurement. /// - [System.Text.Json.Serialization.JsonConverter( typeof( JsonDataValueConverter ) )] - [Newtonsoft.Json.JsonConverter( typeof( DataValueConverter ) )] + [JsonConverter( typeof( DataValueConverter ) )] public struct DataValueDto : IAttributeItemDto, IEquatable { #region members @@ -63,8 +60,7 @@ public DataValueDto( [NotNull] IReadOnlyList attributes ) /// /// Convinience property for accessing the measurement value (K1). /// - [Newtonsoft.Json.JsonIgnore] - [System.Text.Json.Serialization.JsonIgnore] + [JsonIgnore] public double? MeasuredValue => this.GetDoubleAttributeValue( WellKnownKeys.Value.MeasuredValue ); #endregion @@ -72,8 +68,7 @@ public DataValueDto( [NotNull] IReadOnlyList attributes ) #region interface IAttributeItemDto /// - [JsonProperty( "attributes" ), Newtonsoft.Json.JsonConverter( typeof( AttributeArrayConverter ) )] - [JsonPropertyName( "attributes" ), System.Text.Json.Serialization.JsonConverter( typeof( JsonAttributeArrayConverter ) )] + [JsonPropertyName( "attributes" ), JsonConverter( typeof( AttributeArrayConverter ) )] public IReadOnlyList Attributes { get => _Attributes ?? Array.Empty(); diff --git a/src/Api.Rest.Dtos/Data/EntityDto.cs b/src/Api.Rest.Dtos/Data/EntityDto.cs index bf9073f6..8032c04f 100644 --- a/src/Api.Rest.Dtos/Data/EntityDto.cs +++ b/src/Api.Rest.Dtos/Data/EntityDto.cs @@ -19,7 +19,6 @@ namespace Zeiss.PiWeb.Api.Rest.Dtos.Data /// /// Enumeration of possible entities. /// - [Newtonsoft.Json.JsonConverter( typeof( Newtonsoft.Json.Converters.StringEnumConverter ) )] [JsonConverter( typeof(JsonStringEnumConverter) )] public enum EntityDto { diff --git a/src/Api.Rest.Dtos/Data/FieldTypeDto.cs b/src/Api.Rest.Dtos/Data/FieldTypeDto.cs index a6362825..c817f7ce 100644 --- a/src/Api.Rest.Dtos/Data/FieldTypeDto.cs +++ b/src/Api.Rest.Dtos/Data/FieldTypeDto.cs @@ -19,7 +19,6 @@ namespace Zeiss.PiWeb.Api.Rest.Dtos.Data /// /// These are the possible data types of attributes. /// - [Newtonsoft.Json.JsonConverter( typeof( Newtonsoft.Json.Converters.StringEnumConverter ) )] [JsonConverter( typeof( JsonStringEnumConverter ) )] public enum FieldTypeDto { diff --git a/src/Api.Rest.Dtos/Data/InspectionPlanCharacteristicDto.cs b/src/Api.Rest.Dtos/Data/InspectionPlanCharacteristicDto.cs index f50ea0ea..dfe81dc0 100644 --- a/src/Api.Rest.Dtos/Data/InspectionPlanCharacteristicDto.cs +++ b/src/Api.Rest.Dtos/Data/InspectionPlanCharacteristicDto.cs @@ -50,7 +50,6 @@ public InspectionPlanCharacteristicDto() { } /// when the inspection plan search is performed with the versioning flag set. When creating new parts, /// this information will be ignored by the server. /// - [Newtonsoft.Json.JsonProperty( "history" )] [JsonPropertyName( "history" )] public IReadOnlyList History { get; set; } diff --git a/src/Api.Rest.Dtos/Data/InspectionPlanDtoBase.cs b/src/Api.Rest.Dtos/Data/InspectionPlanDtoBase.cs index 89c59488..9b0ad478 100644 --- a/src/Api.Rest.Dtos/Data/InspectionPlanDtoBase.cs +++ b/src/Api.Rest.Dtos/Data/InspectionPlanDtoBase.cs @@ -18,7 +18,6 @@ namespace Zeiss.PiWeb.Api.Rest.Dtos.Data using System.Text.Json.Serialization; using JetBrains.Annotations; using Zeiss.PiWeb.Api.Rest.Dtos.Converter; - using Zeiss.PiWeb.Api.Rest.Dtos.JsonConverters; #endregion @@ -33,7 +32,6 @@ public abstract class InspectionPlanDtoBase : IAttributeItemDto private IReadOnlyList _Attributes; - [Newtonsoft.Json.JsonProperty( "path" ), Newtonsoft.Json.JsonConverter( typeof( PathInformationConverter ) )] private PathInformationDto _Path; #endregion @@ -53,22 +51,19 @@ public string this[ ushort key ] /// Gets or sets the uuid of this inspection plan entity. The uuid is always constant, even if /// this entity is renamed. /// - [Newtonsoft.Json.JsonProperty( "uuid" )] [JsonPropertyName( "uuid" )] public Guid Uuid { get; set; } /// /// Gets or sets the comment of this inspection plan entity. /// - [Newtonsoft.Json.JsonProperty( "comment" )] [JsonPropertyName( "comment" )] public string Comment { get; set; } /// /// Gets or sets the path of this inspection plan entity. /// - [Newtonsoft.Json.JsonIgnore] - [JsonPropertyName( "path" ), JsonConverter( typeof( JsonPathInformationConverter ) )] + [JsonPropertyName( "path" ), JsonConverter( typeof( PathInformationConverter ) )] public PathInformationDto Path { [NotNull] get => _Path ?? PathInformationDto.Root; @@ -80,14 +75,12 @@ public PathInformationDto Path /// version changes of the whole inspection plan. This means, that single instances of a part or characteristic can /// have non consecutive version numbers. /// - [Newtonsoft.Json.JsonProperty( "version" )] [JsonPropertyName( "version" )] public uint Version { get; set; } /// /// Contains the date and time of the last change applied to this instance. /// - [Newtonsoft.Json.JsonProperty( "timestamp" )] [JsonPropertyName( "timestamp" )] public DateTime Timestamp { get; set; } @@ -106,8 +99,7 @@ public override string ToString() #region interface IAttributeItemDto /// - [Newtonsoft.Json.JsonProperty( "attributes" ), Newtonsoft.Json.JsonConverter( typeof( AttributeArrayConverter ) )] - [JsonPropertyName( "attributes" ), JsonConverter( typeof( JsonAttributeArrayConverter ) )] + [JsonPropertyName( "attributes" ), JsonConverter( typeof( AttributeArrayConverter ) )] public IReadOnlyList Attributes { [NotNull] get => _Attributes ?? Array.Empty(); diff --git a/src/Api.Rest.Dtos/Data/InspectionPlanEntityDto.cs b/src/Api.Rest.Dtos/Data/InspectionPlanEntityDto.cs index d15de747..785a47c7 100644 --- a/src/Api.Rest.Dtos/Data/InspectionPlanEntityDto.cs +++ b/src/Api.Rest.Dtos/Data/InspectionPlanEntityDto.cs @@ -19,7 +19,6 @@ namespace Zeiss.PiWeb.Api.Rest.Dtos.Data /// /// Enumeration of possible inspection plan entities. /// - [Newtonsoft.Json.JsonConverter( typeof( Newtonsoft.Json.Converters.StringEnumConverter ) )] [JsonConverter( typeof( JsonStringEnumConverter ) )] public enum InspectionPlanEntityDto : byte { diff --git a/src/Api.Rest.Dtos/Data/InspectionPlanPartDto.cs b/src/Api.Rest.Dtos/Data/InspectionPlanPartDto.cs index cd2ad133..1e45959e 100644 --- a/src/Api.Rest.Dtos/Data/InspectionPlanPartDto.cs +++ b/src/Api.Rest.Dtos/Data/InspectionPlanPartDto.cs @@ -50,7 +50,6 @@ public InspectionPlanPartDto() { } /// when the inspection plan search is performed with the versioning flag set. When creating new parts, /// this information will be ignored by the server. /// - [Newtonsoft.Json.JsonProperty( "history" )] [JsonPropertyName( "history" )] public IReadOnlyList History { get; set; } diff --git a/src/Api.Rest.Dtos/Data/MeasurementMergeConditionDto.cs b/src/Api.Rest.Dtos/Data/MeasurementMergeConditionDto.cs index 78830ec9..fa731680 100644 --- a/src/Api.Rest.Dtos/Data/MeasurementMergeConditionDto.cs +++ b/src/Api.Rest.Dtos/Data/MeasurementMergeConditionDto.cs @@ -21,7 +21,6 @@ namespace Zeiss.PiWeb.Api.Rest.Dtos.Data /// beim Koppeln von Messungen verschiedener Teile anhand eines primären Messungsschlüssels /// für jeden im Suchergebnis enthaltenen Attributwert des Schlüssels erfüllt sein muss. /// - [Newtonsoft.Json.JsonConverter( typeof( Newtonsoft.Json.Converters.StringEnumConverter ) )] [JsonConverter( typeof( JsonStringEnumConverter ) )] public enum MeasurementMergeConditionDto { diff --git a/src/Api.Rest.Dtos/Data/OperationDto.cs b/src/Api.Rest.Dtos/Data/OperationDto.cs index d348ced3..8cb15872 100644 --- a/src/Api.Rest.Dtos/Data/OperationDto.cs +++ b/src/Api.Rest.Dtos/Data/OperationDto.cs @@ -24,7 +24,6 @@ namespace Zeiss.PiWeb.Api.Rest.Dtos.Data /// * When a value inside the values list should contain a comma, the entry has to be quoted, i.e. "'value,with,two commas', othervalue" /// * Dates have to be specified in ISO-8601 format /// - [Newtonsoft.Json.JsonConverter( typeof( Newtonsoft.Json.Converters.StringEnumConverter ) )] [JsonConverter( typeof( JsonStringEnumConverter ) )] public enum OperationDto { diff --git a/src/Api.Rest.Dtos/Data/OperationExecutionStatusDto.cs b/src/Api.Rest.Dtos/Data/OperationExecutionStatusDto.cs index abc1b590..8e754bcb 100644 --- a/src/Api.Rest.Dtos/Data/OperationExecutionStatusDto.cs +++ b/src/Api.Rest.Dtos/Data/OperationExecutionStatusDto.cs @@ -1,41 +1,40 @@ -#region copyright - -/* * * * * * * * * * * * * * * * * * * * * * * * * */ -/* Carl Zeiss IMT (IZfM Dresden) */ -/* Softwaresystem PiWeb */ -/* (c) Carl Zeiss 2021 */ -/* * * * * * * * * * * * * * * * * * * * * * * * * */ - -#endregion - -namespace Zeiss.PiWeb.Api.Rest.Dtos.Data -{ - #region usings - - using System.Text.Json.Serialization; - - #endregion - - /// - /// Possible execution statuses of a long running operation. - /// - [Newtonsoft.Json.JsonConverter( typeof( Newtonsoft.Json.Converters.StringEnumConverter ) )] - [JsonConverter( typeof( JsonStringEnumConverter ) )] - public enum OperationExecutionStatusDto - { - /// - /// Operation is currently running. - /// - Running, - - /// - /// Operation has finished. - /// - Finished, - - /// - /// Operation has finished with an exception. - /// - Exception - } +#region copyright + +/* * * * * * * * * * * * * * * * * * * * * * * * * */ +/* Carl Zeiss IMT (IZfM Dresden) */ +/* Softwaresystem PiWeb */ +/* (c) Carl Zeiss 2021 */ +/* * * * * * * * * * * * * * * * * * * * * * * * * */ + +#endregion + +namespace Zeiss.PiWeb.Api.Rest.Dtos.Data +{ + #region usings + + using System.Text.Json.Serialization; + + #endregion + + /// + /// Possible execution statuses of a long running operation. + /// + [JsonConverter( typeof( JsonStringEnumConverter ) )] + public enum OperationExecutionStatusDto + { + /// + /// Operation is currently running. + /// + Running, + + /// + /// Operation has finished. + /// + Finished, + + /// + /// Operation has finished with an exception. + /// + Exception + } } \ No newline at end of file diff --git a/src/Api.Rest.Dtos/Data/OperationStatusDto.cs b/src/Api.Rest.Dtos/Data/OperationStatusDto.cs index aaafc17e..0110d9e1 100644 --- a/src/Api.Rest.Dtos/Data/OperationStatusDto.cs +++ b/src/Api.Rest.Dtos/Data/OperationStatusDto.cs @@ -1,46 +1,45 @@ -#region copyright - -/* * * * * * * * * * * * * * * * * * * * * * * * * */ -/* Carl Zeiss IMT (IZfM Dresden) */ -/* Softwaresystem PiWeb */ -/* (c) Carl Zeiss 2021 */ -/* * * * * * * * * * * * * * * * * * * * * * * * * */ - -#endregion - -namespace Zeiss.PiWeb.Api.Rest.Dtos.Data -{ - #region usings - - using System; - using System.Text.Json.Serialization; - - #endregion - - /// - /// Contains information about the execution status of a long running operation. - /// - public class OperationStatusDto - { - #region properties - - /// - /// Uuid to identify the operation. - /// - public Guid OperationUuid { get; set; } - - /// - /// Status of execution, e.g. Running, Finished or Exception. - /// - public OperationExecutionStatusDto ExecutionStatus { get; set; } - - /// - /// Thrown exception during execution, wrapped in an error object. - /// - [Newtonsoft.Json.JsonProperty( NullValueHandling = Newtonsoft.Json.NullValueHandling.Include )] - [JsonIgnore( Condition = JsonIgnoreCondition.Never )] - public Error Exception { get; set; } - - #endregion - } +#region copyright + +/* * * * * * * * * * * * * * * * * * * * * * * * * */ +/* Carl Zeiss IMT (IZfM Dresden) */ +/* Softwaresystem PiWeb */ +/* (c) Carl Zeiss 2021 */ +/* * * * * * * * * * * * * * * * * * * * * * * * * */ + +#endregion + +namespace Zeiss.PiWeb.Api.Rest.Dtos.Data +{ + #region usings + + using System; + using System.Text.Json.Serialization; + + #endregion + + /// + /// Contains information about the execution status of a long running operation. + /// + public class OperationStatusDto + { + #region properties + + /// + /// Uuid to identify the operation. + /// + public Guid OperationUuid { get; set; } + + /// + /// Status of execution, e.g. Running, Finished or Exception. + /// + public OperationExecutionStatusDto ExecutionStatus { get; set; } + + /// + /// Thrown exception during execution, wrapped in an error object. + /// + [JsonIgnore( Condition = JsonIgnoreCondition.Never )] + public Error Exception { get; set; } + + #endregion + } } \ No newline at end of file diff --git a/src/Api.Rest.Dtos/Data/OrderDirectionDto.cs b/src/Api.Rest.Dtos/Data/OrderDirectionDto.cs index 4871c415..29c0d81b 100644 --- a/src/Api.Rest.Dtos/Data/OrderDirectionDto.cs +++ b/src/Api.Rest.Dtos/Data/OrderDirectionDto.cs @@ -19,7 +19,6 @@ namespace Zeiss.PiWeb.Api.Rest.Dtos.Data /// /// This enumeration specifies the order direction when searching for measurement . /// - [Newtonsoft.Json.JsonConverter( typeof( Newtonsoft.Json.Converters.StringEnumConverter ) )] [JsonConverter( typeof( JsonStringEnumConverter ) )] public enum OrderDirectionDto { diff --git a/src/Api.Rest.Dtos/Data/OrderDto.cs b/src/Api.Rest.Dtos/Data/OrderDto.cs index 4a1e89be..aa774088 100644 --- a/src/Api.Rest.Dtos/Data/OrderDto.cs +++ b/src/Api.Rest.Dtos/Data/OrderDto.cs @@ -51,21 +51,18 @@ public OrderDto( ushort attribute, OrderDirectionDto direction, EntityDto entity /// /// Gets or sets the entity that is used for sorting. /// - [Newtonsoft.Json.JsonProperty( "entity" )] [JsonPropertyName( "entity" )] public EntityDto Entity { get; set; } /// /// Gets or sets the key of the attribute that is used for sorting. /// - [Newtonsoft.Json.JsonProperty( "attribute" )] [JsonPropertyName( "attribute" )] public ushort Attribute { get; set; } /// /// Gets or sets the sort direction. /// - [Newtonsoft.Json.JsonProperty( "direction" )] [JsonPropertyName( "direction" )] public OrderDirectionDto Direction { get; set; } diff --git a/src/Api.Rest.Dtos/Data/PathInformationDto.cs b/src/Api.Rest.Dtos/Data/PathInformationDto.cs index d13cb355..9731b595 100644 --- a/src/Api.Rest.Dtos/Data/PathInformationDto.cs +++ b/src/Api.Rest.Dtos/Data/PathInformationDto.cs @@ -19,7 +19,6 @@ namespace Zeiss.PiWeb.Api.Rest.Dtos.Data using System.Text; using System.Text.Json.Serialization; using Zeiss.PiWeb.Api.Rest.Dtos.Converter; - using Zeiss.PiWeb.Api.Rest.Dtos.JsonConverters; #endregion @@ -32,8 +31,7 @@ namespace Zeiss.PiWeb.Api.Rest.Dtos.Data /// * A characteristic path element can have other characteristic elements as children /// * A characteristic path element can not have part elements as children /// - [Newtonsoft.Json.JsonConverter( typeof( PathInformationConverter ) )] - [JsonConverter( typeof( JsonPathInformationConverter ) )] + [JsonConverter( typeof( PathInformationConverter ) )] public sealed class PathInformationDto : IFormattable, IEnumerable { #region members diff --git a/src/Api.Rest.Dtos/Data/ServiceInformationDto.cs b/src/Api.Rest.Dtos/Data/ServiceInformationDto.cs index 41acffe6..8567c4c3 100644 --- a/src/Api.Rest.Dtos/Data/ServiceInformationDto.cs +++ b/src/Api.Rest.Dtos/Data/ServiceInformationDto.cs @@ -33,102 +33,87 @@ public class ServiceInformationDto /// /// Gets or sets the server name. /// - [Newtonsoft.Json.JsonProperty( "serverName" )] [JsonPropertyName( "serverName" )] public string ServerName { get; set; } /// /// Gets or sets the server version. /// - [Newtonsoft.Json.JsonProperty( "version" )] [JsonPropertyName( "version" )] public string Version { get; set; } /// /// Gets or sets whether the server has security enabled. /// - [Newtonsoft.Json.JsonProperty( "securityEnabled" )] [JsonPropertyName( "securityEnabled" )] public bool SecurityEnabled { get; set; } /// /// Gets or sets the servers edition. /// - [Newtonsoft.Json.JsonProperty( "edition" )] [JsonPropertyName( "edition" )] public string Edition { get; set; } /// /// Gets or sets the number of parts that currently exist in the server. This number is just an approximation. /// - [Newtonsoft.Json.JsonProperty( "partCount" )] [JsonPropertyName( "partCount" )] public int PartCount { get; set; } /// /// Gets or sets the number of characteristics that currently exist in the server. This number is just an approximation. /// - [Newtonsoft.Json.JsonProperty( "characteristicCount" )] [JsonPropertyName( "characteristicCount" )] public int CharacteristicCount { get; set; } /// /// Gets or sets the number of measurements that currently exist in the server. This number is just an approximation. /// - [Newtonsoft.Json.JsonProperty( "measurementCount" )] [JsonPropertyName( "measurementCount" )] public int MeasurementCount { get; set; } /// /// Gets or sets the number of values that currently exist in the server. This number is just an approximation. /// - [Newtonsoft.Json.JsonProperty( "valueCount" )] [JsonPropertyName( "valueCount" )] public int ValueCount { get; set; } /// /// Gets or sets a list of features that are supported by the server. /// - [Newtonsoft.Json.JsonProperty( "featureList" )] [JsonPropertyName( "featureList" )] public IReadOnlyCollection FeatureList { get; set; } /// /// Gets or sets the timestamp of the last inspection plan modification accross the whole server. /// - [Newtonsoft.Json.JsonProperty( "inspectionPlanTimestamp" )] [JsonPropertyName( "inspectionPlanTimestamp" )] public DateTime? InspectionPlanTimestamp { get; set; } /// /// Gets or sets the timestamp of the last structure modification accross the whole server. /// - [Newtonsoft.Json.JsonProperty( "structureTimestamp" )] [JsonPropertyName( "structureTimestamp" )] public DateTime? StructureTimestamp { get; set; } /// /// Gets or sets the timestamp of the last measurement modification accross the whole server. /// - [Newtonsoft.Json.JsonProperty( "measurementTimestamp" )] [JsonPropertyName( "measurementTimestamp" )] public DateTime? MeasurementTimestamp { get; set; } /// /// Gets or sets the timestamp for the last modification of the server configuration. /// - [Newtonsoft.Json.JsonProperty( "configurationTimestamp" )] [JsonPropertyName( "configurationTimestamp" )] public DateTime? ConfigurationTimestamp { get; set; } /// /// Gets or sets the timestamp for the last modification of the catalogs. /// - [Newtonsoft.Json.JsonProperty( "catalogTimestamp" )] [JsonPropertyName( "catalogTimestamp" )] public DateTime? CatalogTimestamp { get; set; } - [Newtonsoft.Json.JsonProperty( "requestHeaderSize" )] [JsonPropertyName( "requestHeaderSize" )] public int RequestHeaderSize { get; set; } diff --git a/src/Api.Rest.Dtos/Data/SimpleCatalogDto.cs b/src/Api.Rest.Dtos/Data/SimpleCatalogDto.cs index 25e02683..c65f9171 100644 --- a/src/Api.Rest.Dtos/Data/SimpleCatalogDto.cs +++ b/src/Api.Rest.Dtos/Data/SimpleCatalogDto.cs @@ -40,14 +40,12 @@ public SimpleCatalogDto() /// /// Gets or sets the uuid of this catalog. /// - [Newtonsoft.Json.JsonProperty( "uuid" )] [JsonPropertyName( "uuid" )] public Guid Uuid { get; set; } /// /// Gets or sets the name of the catalog. /// - [Newtonsoft.Json.JsonProperty( "name" )] [JsonPropertyName( "name" )] public string Name { get; set; } diff --git a/src/Api.Rest.Dtos/Data/SimpleMeasurementDto.cs b/src/Api.Rest.Dtos/Data/SimpleMeasurementDto.cs index ea96c8da..6dc83804 100644 --- a/src/Api.Rest.Dtos/Data/SimpleMeasurementDto.cs +++ b/src/Api.Rest.Dtos/Data/SimpleMeasurementDto.cs @@ -21,7 +21,6 @@ namespace Zeiss.PiWeb.Api.Rest.Dtos.Data using JetBrains.Annotations; using Zeiss.PiWeb.Api.Definitions; using Zeiss.PiWeb.Api.Rest.Dtos.Converter; - using Zeiss.PiWeb.Api.Rest.Dtos.JsonConverters; #endregion @@ -47,14 +46,12 @@ public class SimpleMeasurementDto : IAttributeItemDto /// /// Gets or sets the uuid of this measurement. /// - [Newtonsoft.Json.JsonProperty( "uuid" )] [JsonPropertyName( "uuid" )] public Guid Uuid { get; set; } /// /// Gets or sets the uuid the part this measurement belongs to. /// - [Newtonsoft.Json.JsonProperty( "partUuid" )] [JsonPropertyName( "partUuid" )] public Guid PartUuid { get; set; } @@ -63,14 +60,12 @@ public class SimpleMeasurementDto : IAttributeItemDto /// timestamp whenever an attribute of this measurement is changed or whenever measurement values /// of this measurement are updated, deleted and added. /// - [Newtonsoft.Json.JsonProperty( "lastModified" )] [JsonPropertyName( "lastModified" )] public DateTime LastModified { get; set; } /// /// Gets or sets the creation timestamp of this measurement. /// - [Newtonsoft.Json.JsonProperty( "created" )] [JsonPropertyName( "created" )] public DateTime Created { get; set; } @@ -78,7 +73,6 @@ public class SimpleMeasurementDto : IAttributeItemDto /// Gets or sets the status information for this measurement. This status information can be requested when /// performing a measurement search using one of the values from . /// - [Newtonsoft.Json.JsonProperty( "status" )] [JsonPropertyName( "status" )] public IReadOnlyList Status { get; set; } @@ -86,7 +80,6 @@ public class SimpleMeasurementDto : IAttributeItemDto /// Gets or sets the time of this measurement. If this measurement has no time attribute, then will /// be returned. /// - [Newtonsoft.Json.JsonIgnore] [JsonIgnore] public DateTime? Time { @@ -131,14 +124,12 @@ public DateTime? Time /// /// Returns the measurement time and in case of no time is specified, the minimum time allowed (). /// - [Newtonsoft.Json.JsonIgnore] [JsonIgnore] public DateTime TimeOrMinDate => Time ?? MinimumValidDatabaseDateTime; /// /// Returns the measurement time and in case of no time is specified, the creation date of the measurement. /// - [Newtonsoft.Json.JsonIgnore] [JsonIgnore] public DateTime TimeOrCreationDate => Time ?? Created; @@ -157,8 +148,7 @@ public override string ToString() #region interface IAttributeItemDto /// - [Newtonsoft.Json.JsonProperty( "attributes" ), Newtonsoft.Json.JsonConverter( typeof( AttributeArrayConverter ) )] - [JsonPropertyName( "attributes" ), JsonConverter( typeof( JsonAttributeArrayConverter ) )] + [JsonPropertyName( "attributes" ), JsonConverter( typeof( AttributeArrayConverter ) )] public IReadOnlyList Attributes { [NotNull] get => _Attributes; diff --git a/src/Api.Rest.Dtos/Data/SimpleMeasurementStatusDto.cs b/src/Api.Rest.Dtos/Data/SimpleMeasurementStatusDto.cs index 67074d08..51f112ff 100644 --- a/src/Api.Rest.Dtos/Data/SimpleMeasurementStatusDto.cs +++ b/src/Api.Rest.Dtos/Data/SimpleMeasurementStatusDto.cs @@ -32,14 +32,12 @@ public class SimpleMeasurementStatusDto /// Gets or sets the unique id of the status. Currently this can be one of the following: /// InTol, OutWarn and OutTol. /// - [Newtonsoft.Json.JsonProperty( "id" )] [JsonPropertyName( "id" )] public string Id { get; set; } /// /// Gets or sets the number of characteristics with this measurement status. /// - [Newtonsoft.Json.JsonProperty( "count" )] [JsonPropertyName( "count" )] public int Count { get; set; } @@ -47,7 +45,6 @@ public class SimpleMeasurementStatusDto /// Gets or sets the uuids of the characteristics that have this status. This property will only be populated /// when the detailed status is requested with . /// - [Newtonsoft.Json.JsonProperty( "uuid" )] [JsonPropertyName( "uuid" )] public IReadOnlyCollection Uuid { get; set; } diff --git a/src/Api.Rest.Dtos/Data/SimplePartDto.cs b/src/Api.Rest.Dtos/Data/SimplePartDto.cs index 1901a06e..97bb6a9c 100644 --- a/src/Api.Rest.Dtos/Data/SimplePartDto.cs +++ b/src/Api.Rest.Dtos/Data/SimplePartDto.cs @@ -30,7 +30,6 @@ public class SimplePartDto : InspectionPlanDtoBase /// Whenever a characteristic below that part (but not below sub parts) is changed, created or deleted, /// this timestamp will be updated by the server. /// - [Newtonsoft.Json.JsonProperty( "charChangeDate" )] [JsonPropertyName( "charChangeDate" )] public DateTime CharChangeDate { get; set; } diff --git a/src/Api.Rest.Dtos/Data/VersioningTypeDto.cs b/src/Api.Rest.Dtos/Data/VersioningTypeDto.cs index 21088f50..d0bfe17c 100644 --- a/src/Api.Rest.Dtos/Data/VersioningTypeDto.cs +++ b/src/Api.Rest.Dtos/Data/VersioningTypeDto.cs @@ -19,7 +19,6 @@ namespace Zeiss.PiWeb.Api.Rest.Dtos.Data /// /// This enumeration specifies how the server is performing inspection plan versioning. /// - [Newtonsoft.Json.JsonConverter( typeof( Newtonsoft.Json.Converters.StringEnumConverter ) )] [JsonConverter( typeof( JsonStringEnumConverter ) )] public enum VersioningTypeDto { diff --git a/src/Api.Rest.Dtos/InterfaceVersionRange.cs b/src/Api.Rest.Dtos/InterfaceVersionRange.cs index 88adcfaf..a9a05131 100644 --- a/src/Api.Rest.Dtos/InterfaceVersionRange.cs +++ b/src/Api.Rest.Dtos/InterfaceVersionRange.cs @@ -22,7 +22,6 @@ public class InterfaceVersionRange { #region properties - [Newtonsoft.Json.JsonProperty( "supportedVersions" )] [JsonPropertyName( "supportedVersions" )] public IEnumerable SupportedVersions { get; set; } diff --git a/src/Api.Rest.Dtos/JsonConverters/JsonAttributeArrayConverter.cs b/src/Api.Rest.Dtos/JsonConverters/JsonAttributeArrayConverter.cs deleted file mode 100644 index fa520b6a..00000000 --- a/src/Api.Rest.Dtos/JsonConverters/JsonAttributeArrayConverter.cs +++ /dev/null @@ -1,70 +0,0 @@ -#region copyright - -/* * * * * * * * * * * * * * * * * * * * * * * * * */ -/* Carl Zeiss IMT (IZfM Dresden) */ -/* Softwaresystem PiWeb */ -/* (c) Carl Zeiss 2022 */ -/* * * * * * * * * * * * * * * * * * * * * * * * * */ - -#endregion - -namespace Zeiss.PiWeb.Api.Rest.Dtos.JsonConverters -{ - #region usings - - using System; - using System.Collections.Generic; - using System.Text.Json; - using System.Text.Json.Serialization; - using Zeiss.PiWeb.Api.Rest.Dtos.Data; - - #endregion - - /// - /// Specialized for collections. - /// - public sealed class JsonAttributeArrayConverter : JsonConverter> - { - #region methods - - /// - public override IReadOnlyList Read( ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options ) - { - if( reader.TokenType != JsonTokenType.StartObject ) - return Array.Empty(); - - return ReadAttributes( ref reader ); - } - - internal static IReadOnlyList ReadAttributes( ref Utf8JsonReader reader ) - { - var result = new List(); - - while( reader.Read() && reader.TokenType == JsonTokenType.PropertyName ) - { - if( JsonAttributeConverter.TryReadFromProperty( ref reader, out var attribute ) ) - result.Add( attribute ); - } - - return result; - } - - /// - public override void Write( Utf8JsonWriter writer, IReadOnlyList value, JsonSerializerOptions options ) - { - writer.WriteStartObject(); - - WriteAttributes( writer, value, options ); - - writer.WriteEndObject(); - } - - internal static void WriteAttributes( Utf8JsonWriter writer, IEnumerable value, JsonSerializerOptions options ) - { - foreach( var attribute in value ) - JsonAttributeConverter.WriteAsProperty( writer, attribute, options ); - } - - #endregion - } -} diff --git a/src/Api.Rest.Dtos/JsonConverters/JsonAttributeConverter.cs b/src/Api.Rest.Dtos/JsonConverters/JsonAttributeConverter.cs deleted file mode 100644 index b46be135..00000000 --- a/src/Api.Rest.Dtos/JsonConverters/JsonAttributeConverter.cs +++ /dev/null @@ -1,100 +0,0 @@ -#region copyright - -/* * * * * * * * * * * * * * * * * * * * * * * * * */ -/* Carl Zeiss IMT (IZM Dresden) */ -/* Softwaresystem PiWeb */ -/* (c) Carl Zeiss 2016 */ -/* * * * * * * * * * * * * * * * * * * * * * * * * */ - -#endregion - -namespace Zeiss.PiWeb.Api.Rest.Dtos.JsonConverters -{ - #region usings - - using System; - using System.Buffers; - using System.Buffers.Text; - using System.Text; - using System.Text.Json; - using System.Text.Json.Serialization; - using Zeiss.PiWeb.Api.Rest.Dtos.Converter; - using Zeiss.PiWeb.Api.Rest.Dtos.Data; - - #endregion - - /// - /// Specialized for -objects. - /// - public sealed class JsonAttributeConverter : JsonConverter - { - #region methods - - /// - public override AttributeDto Read( ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options ) - { - AttributeDto result = default; - - while( reader.Read() && reader.TokenType == JsonTokenType.PropertyName ) - TryReadFromProperty( ref reader, out result ); - - return result; - } - - internal static bool TryReadFromProperty( ref Utf8JsonReader reader, out AttributeDto attribute ) - { - var keySpan = reader.HasValueSequence ? reader.ValueSequence.ToArray() : reader.ValueSpan; - - if( !Utf8Parser.TryParse( keySpan, out ushort key, out var bytesConsumed ) || keySpan.Length != bytesConsumed ) - throw new FormatException( $"Input span was not in a correct format, on converting to '{nameof( UInt16 )}'" ); - - reader.Read(); - - switch( reader.TokenType ) - { - case JsonTokenType.String: - attribute = new AttributeDto( key, reader.GetString() ); - return true; - - case JsonTokenType.Number: - var valueSpan = reader.HasValueSequence ? reader.ValueSequence.ToArray() : reader.ValueSpan; -#if NETSTANDARD - var value = Encoding.UTF8.GetString( valueSpan.ToArray() ); -#else - var value = Encoding.UTF8.GetString( valueSpan ); -#endif - attribute = new AttributeDto( key, value ); - return true; - } - - attribute = default; - - return false; - } - - /// - public override void Write( Utf8JsonWriter writer, AttributeDto value, JsonSerializerOptions options ) - { - writer.WriteStartObject(); - - WriteAsProperty( writer, value, options ); - - writer.WriteEndObject(); - } - - internal static void WriteAsProperty( Utf8JsonWriter writer, in AttributeDto value, JsonSerializerOptions options ) - { - var key = AttributeKeyCache.StringForKey( value.Key ); - - if( value.RawValue is not null ) - { - writer.WritePropertyName( key ); - JsonSerializer.Serialize( writer, value.RawValue, options ); - } - else - writer.WriteString( key, value.Value ); - } - - #endregion - } -} \ No newline at end of file diff --git a/src/Api.Rest.Dtos/JsonConverters/JsonAttributeDefinitionConverter.cs b/src/Api.Rest.Dtos/JsonConverters/JsonAttributeDefinitionConverter.cs deleted file mode 100644 index af13f862..00000000 --- a/src/Api.Rest.Dtos/JsonConverters/JsonAttributeDefinitionConverter.cs +++ /dev/null @@ -1,185 +0,0 @@ -#region copyright - -/* * * * * * * * * * * * * * * * * * * * * * * * * */ -/* Carl Zeiss IMT (IZfM Dresden) */ -/* Softwaresystem PiWeb */ -/* (c) Carl Zeiss 2015 */ -/* * * * * * * * * * * * * * * * * * * * * * * * * */ - -#endregion - -namespace Zeiss.PiWeb.Api.Rest.Dtos.JsonConverters -{ - #region usings - - using System; - using System.Text; - using System.Text.Json; - using System.Text.Json.Serialization; - using Zeiss.PiWeb.Api.Rest.Dtos.Data; - - #endregion - - /// - /// Specialized for -objects. - /// - public sealed class JsonAbstractAttributeDefinitionConverter : JsonConverter - { - #region members - - private static readonly byte[] KeyPropertyName = Encoding.UTF8.GetBytes( "key" ); - private static readonly byte[] QueryEfficientPropertyName = Encoding.UTF8.GetBytes( "queryEfficient" ); - private static readonly byte[] DescriptionPropertyName = Encoding.UTF8.GetBytes( "description" ); - private static readonly byte[] LengthPropertyName = Encoding.UTF8.GetBytes( "length" ); - private static readonly byte[] TypePropertyName = Encoding.UTF8.GetBytes( "type" ); - private static readonly byte[] CatalogPropertyName = Encoding.UTF8.GetBytes( "catalog" ); - private static readonly byte[] DefinitionTypePropertyName = Encoding.UTF8.GetBytes( "definitionType" ); - - private static readonly byte[] AttributeDefinitionTypeId = Encoding.UTF8.GetBytes( "AttributeDefinition" ); - private static readonly byte[] CatalogAttributeDefinitionTypeId = Encoding.UTF8.GetBytes( "CatalogAttributeDefinition" ); - - #endregion - - #region methods - - /// - public override bool CanConvert( Type typeToConvert ) - { - return typeof( AbstractAttributeDefinitionDto ).IsAssignableFrom( typeToConvert ); - } - - /// - public override AbstractAttributeDefinitionDto Read( ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options ) - { - return ReadFromObject( ref reader, options ); - } - - internal static AbstractAttributeDefinitionDto ReadFromObject( ref Utf8JsonReader reader, JsonSerializerOptions options ) - { - var key = default( ushort ); - var length = default( ushort? ); - var queryEfficient = default( bool ); - var description = default( string ); - var attributeDefinitionType = default( ReadOnlySpan ); - var type = default( AttributeTypeDto ); - var catalogUuid = default( Guid ); - - while( reader.Read() && reader.TokenType == JsonTokenType.PropertyName ) - { - if( reader.ValueTextEquals( KeyPropertyName ) ) - { - reader.Read(); - key = reader.GetUInt16(); - } - else if( reader.ValueTextEquals( QueryEfficientPropertyName ) ) - { - reader.Read(); - queryEfficient = reader.GetBoolean(); - } - else if( reader.ValueTextEquals( DescriptionPropertyName ) ) - { - reader.Read(); - description = reader.GetString(); - } - else if( reader.ValueTextEquals( LengthPropertyName ) ) - { - reader.Read(); - length = reader.GetUInt16(); - } - else if( reader.ValueTextEquals( TypePropertyName ) ) - { - reader.Read(); - type = JsonSerializer.Deserialize( ref reader, options ); - } - else if( reader.ValueTextEquals( CatalogPropertyName ) ) - { - reader.Read(); - catalogUuid = reader.GetGuid(); - } - else if( reader.ValueTextEquals( DefinitionTypePropertyName ) ) - { - reader.Read(); - attributeDefinitionType = reader.ValueSpan; - } - } - - if( attributeDefinitionType.SequenceEqual( AttributeDefinitionTypeId ) ) - return new AttributeDefinitionDto { Description = description, Key = key, Length = length, QueryEfficient = queryEfficient, Type = type }; - else if( attributeDefinitionType.SequenceEqual( CatalogAttributeDefinitionTypeId ) ) - return new CatalogAttributeDefinitionDto { Description = description, Key = key, QueryEfficient = queryEfficient, Catalog = catalogUuid }; - - return null; - } - - /// - public override void Write( Utf8JsonWriter writer, AbstractAttributeDefinitionDto value, JsonSerializerOptions options ) - { - WriteAsObject( writer, value, options ); - } - - internal static void WriteAsObject( Utf8JsonWriter writer, AbstractAttributeDefinitionDto value, JsonSerializerOptions options ) - { - writer.WriteStartObject(); - - writer.WriteNumber( KeyPropertyName, value.Key ); - writer.WriteString( DescriptionPropertyName, value.Description ); - - if( value is AttributeDefinitionDto attributeDef ) - { - if( attributeDef.Length.HasValue ) - writer.WriteNumber( LengthPropertyName, attributeDef.Length.Value ); - - writer.WritePropertyName( TypePropertyName ); - JsonSerializer.Serialize( writer, attributeDef.Type, options ); - - writer.WriteString( DefinitionTypePropertyName, AttributeDefinitionTypeId ); - } - - if( value is CatalogAttributeDefinitionDto catalogDef ) - { - writer.WriteString( CatalogPropertyName, catalogDef.Catalog ); - writer.WriteString( DefinitionTypePropertyName, CatalogAttributeDefinitionTypeId ); - } - - writer.WriteEndObject(); - } - - #endregion - } - - /// - /// Specialized for -objects. - /// - public sealed class JsonAttributeDefinitionConverter : JsonConverter - { - /// - public override AttributeDefinitionDto Read( ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options ) - { - return (AttributeDefinitionDto)JsonAbstractAttributeDefinitionConverter.ReadFromObject( ref reader, options ); - } - - /// - public override void Write( Utf8JsonWriter writer, AttributeDefinitionDto value, JsonSerializerOptions options ) - { - JsonAbstractAttributeDefinitionConverter.WriteAsObject( writer, value, options ); - } - } - - /// - /// Specialized for -objects. - /// - public sealed class JsonCatalogAttributeDefinitionConverter : JsonConverter - { - /// - public override CatalogAttributeDefinitionDto Read( ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options ) - { - return (CatalogAttributeDefinitionDto)JsonAbstractAttributeDefinitionConverter.ReadFromObject( ref reader, options ); - } - - /// - public override void Write( Utf8JsonWriter writer, CatalogAttributeDefinitionDto value, JsonSerializerOptions options ) - { - JsonAbstractAttributeDefinitionConverter.WriteAsObject( writer, value, options ); - } - } -} \ No newline at end of file diff --git a/src/Api.Rest.Dtos/JsonConverters/JsonDataValueConverter.cs b/src/Api.Rest.Dtos/JsonConverters/JsonDataValueConverter.cs deleted file mode 100644 index 9a0a6224..00000000 --- a/src/Api.Rest.Dtos/JsonConverters/JsonDataValueConverter.cs +++ /dev/null @@ -1,45 +0,0 @@ -#region copyright - -/* * * * * * * * * * * * * * * * * * * * * * * * * */ -/* Carl Zeiss IMT (IZM Dresden) */ -/* Softwaresystem PiWeb */ -/* (c) Carl Zeiss 2022 */ -/* * * * * * * * * * * * * * * * * * * * * * * * * */ - -#endregion - -namespace Zeiss.PiWeb.Api.Rest.Dtos.JsonConverters -{ - #region usings - - using System; - using System.Text.Json; - using System.Text.Json.Serialization; - using Zeiss.PiWeb.Api.Rest.Dtos.Data; - - #endregion - - /// - /// Specialized for -objects. - /// - public sealed class JsonDataValueConverter : JsonConverter - { - #region methods - - /// - public override DataValueDto Read( ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options ) - { - return new DataValueDto( JsonAttributeArrayConverter.ReadAttributes( ref reader ) ); - } - - /// - public override void Write( Utf8JsonWriter writer, DataValueDto value, JsonSerializerOptions options ) - { - writer.WriteStartObject(); - JsonAttributeArrayConverter.WriteAttributes( writer, value.Attributes, options ); - writer.WriteEndObject(); - } - - #endregion - } -} \ No newline at end of file diff --git a/src/Api.Rest.Dtos/JsonConverters/JsonInspectionPlanDtoBaseConverter.cs b/src/Api.Rest.Dtos/JsonConverters/JsonInspectionPlanDtoBaseConverter.cs deleted file mode 100644 index 75ae8448..00000000 --- a/src/Api.Rest.Dtos/JsonConverters/JsonInspectionPlanDtoBaseConverter.cs +++ /dev/null @@ -1,118 +0,0 @@ -#region copyright - -/* * * * * * * * * * * * * * * * * * * * * * * * * */ -/* Carl Zeiss IMT (IZfM Dresden) */ -/* Softwaresystem PiWeb */ -/* (c) Carl Zeiss 2022 */ -/* * * * * * * * * * * * * * * * * * * * * * * * * */ - -#endregion - -namespace Zeiss.PiWeb.Api.Rest.Dtos.JsonConverters -{ - #region usings - - using System; - using System.Collections.Generic; - using System.Linq; - using System.Text.Json; - using System.Text.Json.Serialization; - using Zeiss.PiWeb.Api.Rest.Dtos.Data; - - #endregion - - /// - /// Specialized for -objects. - /// - public sealed class JsonInspectionPlanDtoBaseConverter : JsonConverter - { - #region methods - - /// - public override void Write( Utf8JsonWriter writer, InspectionPlanDtoBase value, JsonSerializerOptions options ) - { - switch( value ) - { - case null: - writer.WriteNullValue(); - break; - - case InspectionPlanPartDto inspectionPlanPart: - JsonSerializer.Serialize( writer, inspectionPlanPart, options ); - break; - - case SimplePartDto simplePart: - JsonSerializer.Serialize( writer, simplePart, options ); - break; - - case InspectionPlanCharacteristicDto inspectionPlanCharacteristic: - JsonSerializer.Serialize( writer, inspectionPlanCharacteristic, options ); - break; - - default: - throw new NotImplementedException( $"{value.GetType().Name}" ); - } - } - - /// - public override InspectionPlanDtoBase Read( ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options ) - { - var type = GetType( ref reader ); - - return type switch - { - InspectionPlanItemType.InspectionPlanPartDto => JsonSerializer.Deserialize( ref reader, options ), - - InspectionPlanItemType.SimplePartDto => JsonSerializer.Deserialize( ref reader, options ), - - InspectionPlanItemType.InspectionPlanCharacteristicDto => JsonSerializer.Deserialize( ref reader, options ), - - _ => throw new NotImplementedException($"{type}") - }; - } - - private static InspectionPlanItemType GetType( ref Utf8JsonReader reader ) - { - var propertyNames = CollectPropertyNames( reader ); - - if( propertyNames.Any( propertyName => propertyName.Equals( nameof( InspectionPlanPartDto.History ), StringComparison.OrdinalIgnoreCase ) ) && - propertyNames.Any( propertyName => propertyName.Equals( nameof( InspectionPlanPartDto.CharChangeDate ), StringComparison.OrdinalIgnoreCase ) ) ) - return InspectionPlanItemType.InspectionPlanPartDto; - - if( propertyNames.Any( propertyName => propertyName.Equals( nameof( SimplePartDto.CharChangeDate ), StringComparison.OrdinalIgnoreCase ) ) ) - return InspectionPlanItemType.SimplePartDto; - - return InspectionPlanItemType.InspectionPlanCharacteristicDto; - } - - private static IReadOnlyList CollectPropertyNames( Utf8JsonReader reader ) - { - var propertyNames = new List(); - - var startDepth = reader.CurrentDepth; - - while( reader.Read() && ( reader.TokenType != JsonTokenType.EndObject || reader.CurrentDepth != startDepth ) ) - { - if( reader.TokenType == JsonTokenType.PropertyName && reader.CurrentDepth == startDepth + 1 ) - propertyNames.Add( reader.GetString() ); - else - reader.TrySkip(); - } - - return propertyNames; - } - - #endregion - - #region InspectionPlanItemType - - private enum InspectionPlanItemType - { - InspectionPlanPartDto, - SimplePartDto, - InspectionPlanCharacteristicDto - } - - #endregion - } -} \ No newline at end of file diff --git a/src/Api.Rest.Dtos/JsonConverters/JsonPathInformationConverter.cs b/src/Api.Rest.Dtos/JsonConverters/JsonPathInformationConverter.cs deleted file mode 100644 index 153719ec..00000000 --- a/src/Api.Rest.Dtos/JsonConverters/JsonPathInformationConverter.cs +++ /dev/null @@ -1,47 +0,0 @@ -#region copyright - -/* * * * * * * * * * * * * * * * * * * * * * * * * */ -/* Carl Zeiss IMT (IZfM Dresden) */ -/* Softwaresystem PiWeb */ -/* (c) Carl Zeiss 2015 */ -/* * * * * * * * * * * * * * * * * * * * * * * * * */ - -#endregion - -namespace Zeiss.PiWeb.Api.Rest.Dtos.JsonConverters -{ - #region usings - - using System; - using System.Text.Json; - using System.Text.Json.Serialization; - using Zeiss.PiWeb.Api.Rest.Dtos.Data; - - #endregion - - /// - /// Specialized for -objects. - /// - public sealed class JsonPathInformationConverter : JsonConverter - { - #region methods - - /// - public override PathInformationDto Read( ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options ) - { - if( reader.TokenType != JsonTokenType.String ) - return null; - - return PathHelper.RoundtripString2PathInformation( reader.GetString() ); - - } - - /// - public override void Write( Utf8JsonWriter writer, PathInformationDto value, JsonSerializerOptions options ) - { - writer.WriteStringValue( PathHelper.PathInformation2RoundtripString( value ) ); - } - - #endregion - } -} \ No newline at end of file diff --git a/src/Api.Rest.Dtos/RawData/RawDataArchiveBulkQueryDto.cs b/src/Api.Rest.Dtos/RawData/RawDataArchiveBulkQueryDto.cs index 84427986..61461556 100644 --- a/src/Api.Rest.Dtos/RawData/RawDataArchiveBulkQueryDto.cs +++ b/src/Api.Rest.Dtos/RawData/RawDataArchiveBulkQueryDto.cs @@ -47,7 +47,6 @@ public RawDataArchiveBulkQueryDto() { } /// /// Selectors containing information about target, key and requested files of specified archives. /// - [Newtonsoft.Json.JsonProperty( "selectors" )] [JsonPropertyName( "selectors" )] public RawDataArchiveSelectorDto[] Selectors { get; set; } = { }; diff --git a/src/Api.Rest.Dtos/RawData/RawDataArchiveContentDto.cs b/src/Api.Rest.Dtos/RawData/RawDataArchiveContentDto.cs index 480ef863..fb0ae6c7 100644 --- a/src/Api.Rest.Dtos/RawData/RawDataArchiveContentDto.cs +++ b/src/Api.Rest.Dtos/RawData/RawDataArchiveContentDto.cs @@ -37,35 +37,30 @@ public RawDataArchiveContentDto() { } /// /// Full name of the file. /// - [Newtonsoft.Json.JsonProperty( "fileName" )] [JsonPropertyName( "fileName" )] public string FileName { get; set; } /// /// Length of data. /// - [Newtonsoft.Json.JsonProperty( "size" )] [JsonPropertyName( "size" )] public int Size { get; set; } /// /// Actual data representing the file. /// - [Newtonsoft.Json.JsonProperty( "data" )] [JsonPropertyName( "data" )] public byte[] Data { get; set; } /// /// MD5 checksum of data. /// - [Newtonsoft.Json.JsonProperty( "md5" )] [JsonPropertyName( "md5" )] public Guid MD5 { get; set; } /// /// of original archive. /// - [Newtonsoft.Json.JsonProperty( "archiveInfo" )] [JsonPropertyName( "archiveInfo" )] public RawDataInformationDto ArchiveInfo { get; set; } diff --git a/src/Api.Rest.Dtos/RawData/RawDataArchiveEntriesDto.cs b/src/Api.Rest.Dtos/RawData/RawDataArchiveEntriesDto.cs index 2e1bd1ba..a07a7b62 100644 --- a/src/Api.Rest.Dtos/RawData/RawDataArchiveEntriesDto.cs +++ b/src/Api.Rest.Dtos/RawData/RawDataArchiveEntriesDto.cs @@ -38,14 +38,12 @@ public RawDataArchiveEntriesDto() { } /// /// of original archive. /// - [Newtonsoft.Json.JsonProperty( "archiveInfo" )] [JsonPropertyName( "archiveInfo" )] public RawDataInformationDto ArchiveInfo { get; set; } /// /// List of files in specified archive. /// - [Newtonsoft.Json.JsonProperty( "entries" )] [JsonPropertyName( "entries" )] public string[] Entries { get; set; } diff --git a/src/Api.Rest.Dtos/RawData/RawDataArchiveSelectorDto.cs b/src/Api.Rest.Dtos/RawData/RawDataArchiveSelectorDto.cs index 0e8bb372..e3b2725a 100644 --- a/src/Api.Rest.Dtos/RawData/RawDataArchiveSelectorDto.cs +++ b/src/Api.Rest.Dtos/RawData/RawDataArchiveSelectorDto.cs @@ -47,21 +47,18 @@ public RawDataArchiveSelectorDto( int key, [NotNull] RawDataTargetEntityDto targ /// /// of raw data. /// - [Newtonsoft.Json.JsonProperty( "target" )] [JsonPropertyName( "target" )] public RawDataTargetEntityDto Target { get; set; } /// /// Key to specify raw data of target entity. /// - [Newtonsoft.Json.JsonProperty( "key" )] [JsonPropertyName( "key" )] public int Key { get; set; } /// /// List of requested files in specified archive. /// - [Newtonsoft.Json.JsonProperty( "entries" )] [JsonPropertyName( "entries" )] public string[] Entries { get; set; } diff --git a/src/Api.Rest.Dtos/RawData/RawDataBulkQueryDto.cs b/src/Api.Rest.Dtos/RawData/RawDataBulkQueryDto.cs index d69f36b6..b31b3efe 100644 --- a/src/Api.Rest.Dtos/RawData/RawDataBulkQueryDto.cs +++ b/src/Api.Rest.Dtos/RawData/RawDataBulkQueryDto.cs @@ -48,7 +48,6 @@ public RawDataBulkQueryDto( [NotNull] RawDataSelectorDto[] selectors ) /// /// Selectors containing information about target and key of requested archives. /// - [Newtonsoft.Json.JsonProperty( "selectors" )] [JsonPropertyName( "selectors" )] public RawDataSelectorDto[] Selectors { get; set; } = { }; diff --git a/src/Api.Rest.Dtos/RawData/RawDataEntityDto.cs b/src/Api.Rest.Dtos/RawData/RawDataEntityDto.cs index e3a029d4..6c99a049 100644 --- a/src/Api.Rest.Dtos/RawData/RawDataEntityDto.cs +++ b/src/Api.Rest.Dtos/RawData/RawDataEntityDto.cs @@ -19,7 +19,6 @@ namespace Zeiss.PiWeb.Api.Rest.Dtos.RawData /// /// Enumeration that specifies the entity to which a raw data object is attached to. /// - [Newtonsoft.Json.JsonConverter( typeof( Newtonsoft.Json.Converters.StringEnumConverter ) )] [JsonConverter( typeof( JsonStringEnumConverter ) )] public enum RawDataEntityDto { diff --git a/src/Api.Rest.Dtos/RawData/RawDataInformationDto.cs b/src/Api.Rest.Dtos/RawData/RawDataInformationDto.cs index c3d0237f..f9405f3a 100644 --- a/src/Api.Rest.Dtos/RawData/RawDataInformationDto.cs +++ b/src/Api.Rest.Dtos/RawData/RawDataInformationDto.cs @@ -72,7 +72,6 @@ public RawDataInformationDto( [NotNull] RawDataInformationDto data ) /// /// Gets or sets the target object this raw data object belongs to. /// - [Newtonsoft.Json.JsonProperty( "target" )] [JsonPropertyName( "target" )] public RawDataTargetEntityDto Target { get; set; } @@ -80,7 +79,6 @@ public RawDataInformationDto( [NotNull] RawDataInformationDto data ) /// This is a unique key that identifies this specific raw data object for a corresponding entity. An entity (Part, Characteristic, Measurement, Value) /// can have multiple raw data object that are distinct by this key. /// - [Newtonsoft.Json.JsonProperty( "key" )] [JsonPropertyName( "key" )] public int? Key { get; set; } @@ -90,14 +88,12 @@ public RawDataInformationDto( [NotNull] RawDataInformationDto data ) /// /// Please note that this filename is not unique (unlike filenames in traditional file systems). /// - [Newtonsoft.Json.JsonProperty( "fileName" )] [JsonPropertyName( "fileName" )] public string FileName { get; set; } /// /// Gets or sets the mime type of the raw data object. /// - [Newtonsoft.Json.JsonProperty( "mimeType" )] [JsonPropertyName( "mimeType" )] public string MimeType { get; set; } @@ -108,7 +104,6 @@ public RawDataInformationDto( [NotNull] RawDataInformationDto data ) /// The attribute LastModified will be set by the Rawdata-Service. /// A user value will be ignored. /// - [Newtonsoft.Json.JsonProperty( "lastModified" )] [JsonPropertyName( "lastModified" )] public DateTime LastModified { get; set; } @@ -119,21 +114,18 @@ public RawDataInformationDto( [NotNull] RawDataInformationDto data ) /// The attribute Created will be set by the Rawdata-Service. /// A user value will be ignored. /// - [Newtonsoft.Json.JsonProperty( "created" )] [JsonPropertyName( "created" )] public DateTime Created { get; set; } /// /// Gets or sets the size of the raw data object in bytes. /// - [Newtonsoft.Json.JsonProperty( "size" )] [JsonPropertyName( "size" )] public int Size { get; set; } /// /// Gets or sets the MD5-Hash of the raw data object. /// - [Newtonsoft.Json.JsonProperty( "md5" )] [JsonPropertyName( "md5" )] public Guid MD5 { get; set; } @@ -143,7 +135,6 @@ public RawDataInformationDto( [NotNull] RawDataInformationDto data ) /// /// This property exists for serialization compatibility reasons only. This will be removed in a future version of this interface. /// - [Newtonsoft.Json.JsonIgnore] [JsonIgnore] public string MD5String { diff --git a/src/Api.Rest.Dtos/RawData/RawDataSelectorDto.cs b/src/Api.Rest.Dtos/RawData/RawDataSelectorDto.cs index 6ae9e051..1773beda 100644 --- a/src/Api.Rest.Dtos/RawData/RawDataSelectorDto.cs +++ b/src/Api.Rest.Dtos/RawData/RawDataSelectorDto.cs @@ -48,14 +48,12 @@ public RawDataSelectorDto( int key, [NotNull] RawDataTargetEntityDto target ) /// /// of raw data. /// - [Newtonsoft.Json.JsonProperty( "target" )] [JsonPropertyName( "target" )] public RawDataTargetEntityDto Target { get; set; } /// /// Key to specify raw data of target entity. /// - [Newtonsoft.Json.JsonProperty( "key" )] [JsonPropertyName( "key" )] public int Key { get; set; } diff --git a/src/Api.Rest.Dtos/RawData/RawDataTargetEntityDto.cs b/src/Api.Rest.Dtos/RawData/RawDataTargetEntityDto.cs index 6e7163dd..bc801fb3 100644 --- a/src/Api.Rest.Dtos/RawData/RawDataTargetEntityDto.cs +++ b/src/Api.Rest.Dtos/RawData/RawDataTargetEntityDto.cs @@ -58,14 +58,12 @@ public RawDataTargetEntityDto( RawDataEntityDto entity, string uuid ) /// /// Gets or sets the entity to which this raw data object belongs to. /// - [Newtonsoft.Json.JsonProperty( "entity" )] [JsonPropertyName( "entity" )] public RawDataEntityDto Entity { get; set; } /// /// Gets or sets the uuid of the entity. /// - [Newtonsoft.Json.JsonProperty( "uuid" )] [JsonPropertyName( "uuid" )] public string Uuid { get; set; } diff --git a/src/Api.Rest.Dtos/RawData/ServiceInformationDto.cs b/src/Api.Rest.Dtos/RawData/ServiceInformationDto.cs index 8f5dcdf4..8ff368b8 100644 --- a/src/Api.Rest.Dtos/RawData/ServiceInformationDto.cs +++ b/src/Api.Rest.Dtos/RawData/ServiceInformationDto.cs @@ -26,11 +26,9 @@ public class ServiceInformationDto /// /// Gets or sets the version of the server backend. /// - [Newtonsoft.Json.JsonProperty( "version" )] [JsonPropertyName( "version" )] public string Version { get; set; } - [Newtonsoft.Json.JsonProperty( "requestHeaderSize" )] [JsonPropertyName( "requestHeaderSize" )] public int RequestHeaderSize { get; set; } diff --git a/src/Api.Rest.Tests/Api.Rest.Tests.csproj b/src/Api.Rest.Tests/Api.Rest.Tests.csproj index 42806c94..d6b00e6d 100644 --- a/src/Api.Rest.Tests/Api.Rest.Tests.csproj +++ b/src/Api.Rest.Tests/Api.Rest.Tests.csproj @@ -13,7 +13,6 @@ - all diff --git a/src/Api.Rest.Tests/HttpClient/Data/DataServiceRestClientTest.cs b/src/Api.Rest.Tests/HttpClient/Data/DataServiceRestClientTest.cs index 06a10699..54ae6d75 100644 --- a/src/Api.Rest.Tests/HttpClient/Data/DataServiceRestClientTest.cs +++ b/src/Api.Rest.Tests/HttpClient/Data/DataServiceRestClientTest.cs @@ -13,10 +13,9 @@ namespace Zeiss.PiWeb.Api.Rest.Tests.HttpClient.Data #region usings using System; - using System.Linq; + using System.Text.Json; using System.Threading.Tasks; using FluentAssertions; - using Newtonsoft.Json; using NUnit.Framework; using Zeiss.PiWeb.Api.Rest.Dtos.Data; using Zeiss.PiWeb.Api.Rest.HttpClient.Data; @@ -68,8 +67,8 @@ public async Task RequestSplit_OrderSpecified_OrderIsCorrect() { Attributes = new[] { new AttributeDto( 5, 3 ), new AttributeDto( 55, 20 ), new AttributeDto( 999, 3 ) } } }; - server.RegisterResponse( "/DataServiceRest/measurements?partUuids=%7B11111111-1111-1111-1111-111111111111%7D&order=5%20Asc%2C55%20Asc", JsonConvert.SerializeObject( firstMeasurementSet ) ); - server.RegisterResponse( "/DataServiceRest/measurements?partUuids=%7B22222222-2222-2222-2222-222222222222%7D&order=5%20Asc%2C55%20Asc", JsonConvert.SerializeObject( secondMeasurementSet ) ); + server.RegisterResponse( "/DataServiceRest/measurements?partUuids=%7B11111111-1111-1111-1111-111111111111%7D&order=5%20Asc%2C55%20Asc", JsonSerializer.Serialize( firstMeasurementSet ) ); + server.RegisterResponse( "/DataServiceRest/measurements?partUuids=%7B22222222-2222-2222-2222-222222222222%7D&order=5%20Asc%2C55%20Asc", JsonSerializer.Serialize( secondMeasurementSet ) ); var result = await client.GetMeasurements( filter: new MeasurementFilterAttributesDto { @@ -97,8 +96,8 @@ public async Task RequestSplit_LimitResultSpecified_LimitCorrect() var secondMeasurementSet = new[] { new SimpleMeasurementDto(), new SimpleMeasurementDto(), new SimpleMeasurementDto() }; - server.RegisterResponse( "/DataServiceRest/measurements?partUuids=%7B11111111-1111-1111-1111-111111111111%7D&limitResult=5&order=4%20Desc", JsonConvert.SerializeObject( firstMeasurementSet ) ); - server.RegisterResponse( "/DataServiceRest/measurements?partUuids=%7B22222222-2222-2222-2222-222222222222%7D&limitResult=5&order=4%20Desc", JsonConvert.SerializeObject( secondMeasurementSet ) ); + server.RegisterResponse( "/DataServiceRest/measurements?partUuids=%7B11111111-1111-1111-1111-111111111111%7D&limitResult=5&order=4%20Desc", JsonSerializer.Serialize( firstMeasurementSet ) ); + server.RegisterResponse( "/DataServiceRest/measurements?partUuids=%7B22222222-2222-2222-2222-222222222222%7D&limitResult=5&order=4%20Desc", JsonSerializer.Serialize( secondMeasurementSet ) ); var result = await client.GetMeasurements( filter: new MeasurementFilterAttributesDto { diff --git a/src/Api.Rest.Tests/HttpClient/RawData/RawDataServiceRestClientTest.cs b/src/Api.Rest.Tests/HttpClient/RawData/RawDataServiceRestClientTest.cs index e55ef9ca..6430ce05 100644 --- a/src/Api.Rest.Tests/HttpClient/RawData/RawDataServiceRestClientTest.cs +++ b/src/Api.Rest.Tests/HttpClient/RawData/RawDataServiceRestClientTest.cs @@ -14,9 +14,8 @@ namespace Zeiss.PiWeb.Api.Rest.Tests.HttpClient.RawData using System; using System.Text; + using System.Text.Json; using System.Threading.Tasks; - using Newtonsoft.Json; - using Newtonsoft.Json.Converters; using NUnit.Framework; using Zeiss.PiWeb.Api.Rest.Dtos; using Zeiss.PiWeb.Api.Rest.Dtos.RawData; @@ -107,21 +106,21 @@ public async Task CreateRawData_NotSupportsResult_ReturnsResultWithKey() private static void RegisterRawDataServiceVersionResponse( WebServer webServer, string version ) { var interfaceVersionRange = new InterfaceVersionRange { SupportedVersions = new[] { new Version( version ) } }; - var responseJson = JsonConvert.SerializeObject( interfaceVersionRange, new VersionConverter() ); + var responseJson = JsonSerializer.Serialize( interfaceVersionRange ); webServer.RegisterResponse( "/RawDataServiceRest/", responseJson ); } private static void RegisterCreateRawDataResponse( WebServer webServer, Guid partUuid, RawDataInformationDto responseObject ) { var url = $"/RawDataServiceRest/rawData/Part/{partUuid}"; - var responseJson = JsonConvert.SerializeObject( responseObject ); + var responseJson = JsonSerializer.Serialize( responseObject ); webServer.RegisterResponse( url, responseJson ); } private static void RegisterListRawDataResponse( WebServer webServer, Guid partUuid, RawDataInformationDto[] responseObject ) { var url = $"/RawDataServiceRest/rawData/Part?uuids=%7B{partUuid}%7D"; - var responseJson = JsonConvert.SerializeObject( responseObject ); + var responseJson = JsonSerializer.Serialize( responseObject ); webServer.RegisterResponse( url, responseJson ); } diff --git a/src/Api.Rest.Tests/SimpleRequestTest.cs b/src/Api.Rest.Tests/SimpleRequestTest.cs index 6f8b3485..60e64d61 100644 --- a/src/Api.Rest.Tests/SimpleRequestTest.cs +++ b/src/Api.Rest.Tests/SimpleRequestTest.cs @@ -13,9 +13,9 @@ namespace Zeiss.PiWeb.Api.Rest.Tests #region usings using System; + using System.Text.Json; using System.Threading.Tasks; using AutoFixture; - using Newtonsoft.Json; using NUnit.Framework; using Zeiss.PiWeb.Api.Rest.Dtos.Data; using Zeiss.PiWeb.Api.Rest.HttpClient.Data; @@ -58,13 +58,13 @@ public async Task RequestConfiguration() var config = Fixture.Create(); - server.RegisterResponse( "/DataServiceRest/configuration", JsonConvert.SerializeObject( config ) ); + server.RegisterResponse( "/DataServiceRest/configuration", JsonSerializer.Serialize( config ) ); // when var result = await client.GetConfiguration(); // then - Assert.That( JsonConvert.SerializeObject( result ), Is.EqualTo( JsonConvert.SerializeObject( config ) ) ); + Assert.That( JsonSerializer.Serialize( result ), Is.EqualTo( JsonSerializer.Serialize( config ) ) ); } #endregion diff --git a/src/Api.Rest/Common/Client/ObjectSerializer.cs b/src/Api.Rest/Common/Client/ObjectSerializer.cs index 9c5f9f53..2e586934 100644 --- a/src/Api.Rest/Common/Client/ObjectSerializer.cs +++ b/src/Api.Rest/Common/Client/ObjectSerializer.cs @@ -10,16 +10,19 @@ namespace Zeiss.PiWeb.Api.Rest.Common.Client { + #region usings + using System; using System.Collections.Generic; using System.IO; using System.Runtime.CompilerServices; - using System.Text; + using System.Text.Json; + using System.Text.Json.Serialization; using System.Threading; using System.Threading.Tasks; - using JetBrains.Annotations; using Zeiss.PiWeb.Api.Rest.Dtos.Converter; - using Zeiss.PiWeb.Api.Rest.Dtos.JsonConverters; + + #endregion /// /// Provides a set of static extensions to . @@ -28,140 +31,34 @@ public static class ObjectSerializer { #region members - /// - /// Newtonsoft.Json de-/serialization - /// - public static readonly IObjectSerializer NewtonsoftJson = new NewtonsoftJsonSerializer(); - - /// - /// System.Text.Json de-/serialization - /// - public static readonly IObjectSerializer SystemTextJson = new SystemTextJsonSerializer(); - /// /// Default de-/serialization /// - public static readonly IObjectSerializer Default = NewtonsoftJson; - - #endregion - - #region NewtonsoftJsonSerializer - - private sealed class NewtonsoftJsonSerializer : IObjectSerializer - { - #region methods - - private static Newtonsoft.Json.JsonSerializer CreateJsonSerializer() - { - return new Newtonsoft.Json.JsonSerializer - { - Formatting = Newtonsoft.Json.Formatting.None, - - DateFormatHandling = Newtonsoft.Json.DateFormatHandling.IsoDateFormat, - NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore, - - Converters = - { - new Newtonsoft.Json.Converters.VersionConverter(), - new InspectionPlanDtoBaseConverter() - } - }; - } - - #endregion - - #region Methods - - private static T Deserialize( Stream stream ) - { - try - { - using var reader = new Newtonsoft.Json.JsonTextReader( new StreamReader( stream, Encoding.UTF8, true, 4096, true ) ) { CloseInput = false }; - - var jsonSerializer = CreateJsonSerializer(); - - return jsonSerializer.Deserialize( reader ); - } - catch( Newtonsoft.Json.JsonException exception ) - { - throw new ObjectSerializerException( $"Deserializing {typeof( T ).Name}", exception ); - } - } - - #endregion - - #region interface ISerializer - - Task IObjectSerializer.SerializeAsync( Stream stream, T value, CancellationToken cancellationToken ) - { - if( stream == null ) throw new ArgumentNullException( nameof( stream ) ); - - try - { - using var streamWriter = new StreamWriter( stream, Encoding.UTF8, 64 * 1024, false ); - - var jsonSerializer = CreateJsonSerializer(); - - jsonSerializer.Serialize( streamWriter, value ); - - return Task.CompletedTask; - } - catch( Newtonsoft.Json.JsonException exception ) - { - throw new ObjectSerializerException( $"Serializing {typeof( T ).Name}", exception ); - } - } - - Task IObjectSerializer.DeserializeAsync( Stream stream, CancellationToken cancellationToken ) - { - if( stream == null ) throw new ArgumentNullException( nameof( stream ) ); - - return Task.FromResult( Deserialize( stream ) ); - } - - IAsyncEnumerable IObjectSerializer.DeserializeAsyncEnumerable( Stream stream, CancellationToken cancellationToken ) - { - if( stream == null ) throw new ArgumentNullException( nameof( stream ) ); - - async IAsyncEnumerable DeserializeAsyncEnumerable() - { - var items = Deserialize>( stream ); - - if( items == null ) yield break; - - foreach( var item in items ) - yield return await Task.FromResult( item ).ConfigureAwait( false ); - } - - return DeserializeAsyncEnumerable(); - } - - #endregion - } + public static readonly IObjectSerializer Default = new SystemTextJsonSerializer(); #endregion - #region SystemTextJsonSerializer + #region class SystemTextJsonSerializer private sealed class SystemTextJsonSerializer : IObjectSerializer { #region members - private static readonly System.Text.Json.JsonSerializerOptions Options = new() + private static readonly JsonSerializerOptions Options = new() { - DefaultIgnoreCondition = System.Text.Json.Serialization.JsonIgnoreCondition.WhenWritingNull, + DefaultIgnoreCondition = JsonIgnoreCondition.WhenWritingNull, WriteIndented = false, Converters = { - new JsonInspectionPlanDtoBaseConverter() + new InspectionPlanDtoBaseConverter() } }; #endregion - #region interface ISerializer + #region interface IObjectSerializer Task IObjectSerializer.SerializeAsync( Stream stream, T value, CancellationToken cancellationToken ) { @@ -171,9 +68,9 @@ async Task SerializeAsync() { try { - await System.Text.Json.JsonSerializer.SerializeAsync( stream, value, Options, cancellationToken ).ConfigureAwait( false ); + await JsonSerializer.SerializeAsync( stream, value, Options, cancellationToken ).ConfigureAwait( false ); } - catch( System.Text.Json.JsonException exception ) + catch( JsonException exception ) { throw new ObjectSerializerException( $"Serializing {typeof( T ).Name}", exception ); } @@ -194,9 +91,9 @@ async Task DeserializeAsync() { try { - return await System.Text.Json.JsonSerializer.DeserializeAsync( stream, Options, cancellationToken ).ConfigureAwait( false ); + return await JsonSerializer.DeserializeAsync( stream, Options, cancellationToken ).ConfigureAwait( false ); } - catch( System.Text.Json.JsonException exception ) + catch( JsonException exception ) { throw new ObjectSerializerException( $"Deserializing {typeof( T ).Name}", exception ); } @@ -211,7 +108,7 @@ IAsyncEnumerable IObjectSerializer.DeserializeAsyncEnumerable( Stream stre async IAsyncEnumerable DeserializeAsyncEnumerable( [EnumeratorCancellation] CancellationToken cancellationToken ) { - var values = System.Text.Json.JsonSerializer.DeserializeAsyncEnumerable( stream, Options, cancellationToken ); + var values = JsonSerializer.DeserializeAsyncEnumerable( stream, Options, cancellationToken ); var enumerator = values.GetAsyncEnumerator( cancellationToken ); @@ -223,7 +120,7 @@ async IAsyncEnumerable DeserializeAsyncEnumerable( [EnumeratorCancellation] C { moveNext = await enumerator.MoveNextAsync().ConfigureAwait( false ); } - catch( System.Text.Json.JsonException exception ) + catch( JsonException exception ) { throw new ObjectSerializerException( $"Deserializing enumerable of {typeof( T ).Name}", exception ); } diff --git a/src/Api.Rest/Common/Data/Converter/StreamingReaderConverter.cs b/src/Api.Rest/Common/Data/Converter/StreamingReaderConverter.cs deleted file mode 100644 index b31b3cb9..00000000 --- a/src/Api.Rest/Common/Data/Converter/StreamingReaderConverter.cs +++ /dev/null @@ -1,77 +0,0 @@ -#region copyright - -/* * * * * * * * * * * * * * * * * * * * * * * * * */ -/* Carl Zeiss IMT (IZfM Dresden) */ -/* Softwaresystem PiWeb */ -/* (c) Carl Zeiss 2015 */ -/* * * * * * * * * * * * * * * * * * * * * * * * * */ - -#endregion - -namespace Zeiss.PiWeb.Api.Rest.Common.Data.Converter -{ - #region usings - - using System; - using System.Collections.Generic; - using System.Linq; - using Newtonsoft.Json; - - #endregion - - /// - /// Specialized for streaming a list or an array. - /// - public class StreamingReaderConverter : JsonConverter - { - #region properties - - /// - /// Returns false. No write support. - /// - public override bool CanWrite => false; - - #endregion - - #region methods - - /// - public override bool CanConvert( Type objectType ) - { - return typeof( T[] ) == objectType || - typeof( List ) == objectType || - typeof( IEnumerable ) == objectType; - } - - /// - /// Not supported right now. - public override object ReadJson( JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer ) - { - if( typeof( T[] ) == objectType ) - return StreamedReadJson( reader, serializer ).ToArray(); - if( typeof( List ) == objectType ) - return StreamedReadJson( reader, serializer ).ToList(); - return StreamedReadJson( reader, serializer ); - } - - private static IEnumerable StreamedReadJson( JsonReader reader, JsonSerializer serializer ) - { - if( reader.TokenType == JsonToken.StartArray ) - { - while( reader.Read() && reader.TokenType == JsonToken.StartObject ) - { - yield return serializer.Deserialize( reader ); - } - } - } - - /// - /// Not supported right now. - public override void WriteJson( JsonWriter writer, object value, JsonSerializer serializer ) - { - throw new NotImplementedException( "This converter does not support reading." ); - } - - #endregion - } -} \ No newline at end of file diff --git a/src/Api.Rest/Common/Data/Converter/StreamingWriterConverter.cs b/src/Api.Rest/Common/Data/Converter/StreamingWriterConverter.cs deleted file mode 100644 index de2a19c4..00000000 --- a/src/Api.Rest/Common/Data/Converter/StreamingWriterConverter.cs +++ /dev/null @@ -1,66 +0,0 @@ -#region copyright - -/* * * * * * * * * * * * * * * * * * * * * * * * * */ -/* Carl Zeiss IMT (IZfM Dresden) */ -/* Softwaresystem PiWeb */ -/* (c) Carl Zeiss 2015 */ -/* * * * * * * * * * * * * * * * * * * * * * * * * */ - -#endregion - -namespace Zeiss.PiWeb.Api.Rest.Common.Data.Converter -{ - #region usings - - using System; - using System.Collections.Generic; - using Newtonsoft.Json; - - #endregion - - /// - /// Specialized for streamed writing a list or an array. - /// - public class StreamingWriterConverter : JsonConverter - { - #region properties - - /// - /// Returns false. No read support. - /// - public override bool CanRead => false; - - #endregion - - #region methods - - /// - public override bool CanConvert( Type objectType ) - { - return typeof( IEnumerable ).IsAssignableFrom( objectType ); - } - - /// - /// Not supported right now. - public override object ReadJson( JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer ) - { - throw new NotImplementedException( "This converter does not support reading." ); - } - - /// - public override void WriteJson( JsonWriter writer, object value, JsonSerializer serializer ) - { - var items = (IEnumerable)value; - - writer.WriteStartArray(); - foreach( var item in items ) - { - serializer.Serialize( writer, item ); - } - - writer.WriteEndArray(); - } - - #endregion - } -} \ No newline at end of file diff --git a/src/Api.Rest/HttpClient/Data/DataServiceRestClient.cs b/src/Api.Rest/HttpClient/Data/DataServiceRestClient.cs index 0f3d0570..5e32c313 100644 --- a/src/Api.Rest/HttpClient/Data/DataServiceRestClient.cs +++ b/src/Api.Rest/HttpClient/Data/DataServiceRestClient.cs @@ -55,7 +55,7 @@ public class DataServiceRestClient : CommonRestClientBase, IDataServiceRestClien /// The uri length limit /// Custom implementation of RestClient public DataServiceRestClient( [NotNull] Uri serverUri, int maxUriLength = RestClientBase.DefaultMaxUriLength, RestClientBase restClient = null ) - : base( restClient ?? new RestClient( serverUri, EndpointName, maxUriLength: maxUriLength, serializer: ObjectSerializer.SystemTextJson ) ) + : base( restClient ?? new RestClient( serverUri, EndpointName, maxUriLength: maxUriLength, serializer: ObjectSerializer.Default ) ) { } #endregion diff --git a/src/Api.Rest/HttpClient/Data/VersioningInformation.cs b/src/Api.Rest/HttpClient/Data/VersioningInformation.cs index 53d378a5..f36f69c8 100644 --- a/src/Api.Rest/HttpClient/Data/VersioningInformation.cs +++ b/src/Api.Rest/HttpClient/Data/VersioningInformation.cs @@ -25,35 +25,30 @@ public class VersioningInformation /// /// Gets or sets the id of this version entry. /// - [Newtonsoft.Json.JsonProperty( "id" )] [JsonPropertyName( "id" )] public int ID { get; set; } /// /// Gets or sets the versioning comment. /// - [Newtonsoft.Json.JsonProperty( "comment" )] [JsonPropertyName( "comment" )] public string Comment { get; set; } /// /// Gets or sets the comment of this inspection plan entity. /// - [Newtonsoft.Json.JsonProperty( "user" )] [JsonPropertyName( "user" )] public string User { get; set; } /// /// Gets or sets the number of changed inspection plan items that where change. /// - [Newtonsoft.Json.JsonProperty( "changeCount" )] [JsonPropertyName( "changeCount" )] public int ChangeCount { get; set; } /// /// Contains the date and time of the versioning change. /// - [Newtonsoft.Json.JsonProperty( "dateCreated" )] [JsonPropertyName( "dateCreated" )] public DateTime DateCreated { get; set; } diff --git a/src/Api.Rest/HttpClient/OAuth/OAuthServiceRestClient.cs b/src/Api.Rest/HttpClient/OAuth/OAuthServiceRestClient.cs index b0994bb8..b5b71700 100644 --- a/src/Api.Rest/HttpClient/OAuth/OAuthServiceRestClient.cs +++ b/src/Api.Rest/HttpClient/OAuth/OAuthServiceRestClient.cs @@ -35,7 +35,7 @@ public class OAuthServiceRestClient : CommonRestClientBase, IOAuthServiceRestCli /// /// is . public OAuthServiceRestClient( [NotNull] Uri serverUri ) - : base( new RestClient( serverUri, "OAuthServiceRest/", serializer: ObjectSerializer.SystemTextJson ) ) + : base( new RestClient( serverUri, "OAuthServiceRest/", serializer: ObjectSerializer.Default ) ) { } #endregion diff --git a/src/Api.Rest/HttpClient/OAuth/OAuthTokenInformation.cs b/src/Api.Rest/HttpClient/OAuth/OAuthTokenInformation.cs index ec7f5957..85bc7be5 100644 --- a/src/Api.Rest/HttpClient/OAuth/OAuthTokenInformation.cs +++ b/src/Api.Rest/HttpClient/OAuth/OAuthTokenInformation.cs @@ -26,7 +26,6 @@ public class OAuthTokenInformation /// /// The URL of the trusted OpenID Connect authority for this service. /// - [Newtonsoft.Json.JsonProperty( "openIdAuthority" )] [JsonPropertyName( "openIdAuthority" )] public string OpenIdAuthority { get; set; } diff --git a/src/Api.Rest/HttpClient/RawData/RawDataServiceRestClient.cs b/src/Api.Rest/HttpClient/RawData/RawDataServiceRestClient.cs index 1a128bb7..48d42cc7 100644 --- a/src/Api.Rest/HttpClient/RawData/RawDataServiceRestClient.cs +++ b/src/Api.Rest/HttpClient/RawData/RawDataServiceRestClient.cs @@ -58,7 +58,7 @@ public class RawDataServiceRestClient : CommonRestClientBase, IRawDataServiceRes /// The uri length limit /// Custom implementation of RestClient public RawDataServiceRestClient( [NotNull] Uri serverUri, int maxUriLength = RestClientBase.DefaultMaxUriLength, RestClientBase restClient = null ) - : base( restClient ?? new RestClient( serverUri, EndpointName, maxUriLength: maxUriLength, serializer: ObjectSerializer.SystemTextJson ) ) + : base( restClient ?? new RestClient( serverUri, EndpointName, maxUriLength: maxUriLength, serializer: ObjectSerializer.Default ) ) { } #endregion