diff --git a/src/Microsoft.ComponentDetection.Contracts/BcdeModels/ContainerDetails.cs b/src/Microsoft.ComponentDetection.Contracts/BcdeModels/ContainerDetails.cs index ba914f94a..3c5707e51 100644 --- a/src/Microsoft.ComponentDetection.Contracts/BcdeModels/ContainerDetails.cs +++ b/src/Microsoft.ComponentDetection.Contracts/BcdeModels/ContainerDetails.cs @@ -4,12 +4,9 @@ namespace Microsoft.ComponentDetection.Contracts.BcdeModels; using System; using System.Collections.Generic; using System.Text.Json.Serialization; -using Newtonsoft.Json; -using Newtonsoft.Json.Serialization; // Summary: // Details for a docker container -[JsonObject(MemberSerialization.OptOut, NamingStrategyType = typeof(CamelCaseNamingStrategy))] public class ContainerDetails { // Summary: diff --git a/src/Microsoft.ComponentDetection.Contracts/BcdeModels/DefaultGraphScanResult.cs b/src/Microsoft.ComponentDetection.Contracts/BcdeModels/DefaultGraphScanResult.cs index 1de94cfa0..2afe1e9e0 100644 --- a/src/Microsoft.ComponentDetection.Contracts/BcdeModels/DefaultGraphScanResult.cs +++ b/src/Microsoft.ComponentDetection.Contracts/BcdeModels/DefaultGraphScanResult.cs @@ -2,10 +2,7 @@ namespace Microsoft.ComponentDetection.Contracts.BcdeModels; using System.Text.Json.Serialization; -using Newtonsoft.Json; -using Newtonsoft.Json.Serialization; -[JsonObject(MemberSerialization.OptOut, NamingStrategyType = typeof(CamelCaseNamingStrategy))] public class DefaultGraphScanResult : ScanResult { [JsonPropertyName("dependencyGraphs")] diff --git a/src/Microsoft.ComponentDetection.Contracts/BcdeModels/DependencyGraphWithMetadata.cs b/src/Microsoft.ComponentDetection.Contracts/BcdeModels/DependencyGraphWithMetadata.cs index 19df9830c..99b1c78bd 100644 --- a/src/Microsoft.ComponentDetection.Contracts/BcdeModels/DependencyGraphWithMetadata.cs +++ b/src/Microsoft.ComponentDetection.Contracts/BcdeModels/DependencyGraphWithMetadata.cs @@ -3,10 +3,7 @@ namespace Microsoft.ComponentDetection.Contracts.BcdeModels; using System.Collections.Generic; using System.Text.Json.Serialization; -using Newtonsoft.Json; -using Newtonsoft.Json.Serialization; -[JsonObject(MemberSerialization.OptOut, NamingStrategyType = typeof(CamelCaseNamingStrategy))] public class DependencyGraphWithMetadata { [JsonPropertyName("graph")] diff --git a/src/Microsoft.ComponentDetection.Contracts/BcdeModels/Detector.cs b/src/Microsoft.ComponentDetection.Contracts/BcdeModels/Detector.cs index 45642e157..4272c36da 100644 --- a/src/Microsoft.ComponentDetection.Contracts/BcdeModels/Detector.cs +++ b/src/Microsoft.ComponentDetection.Contracts/BcdeModels/Detector.cs @@ -4,11 +4,7 @@ namespace Microsoft.ComponentDetection.Contracts.BcdeModels; using System.Collections.Generic; using System.Text.Json.Serialization; using Microsoft.ComponentDetection.Contracts.TypedComponent; -using Newtonsoft.Json; -using Newtonsoft.Json.Converters; -using Newtonsoft.Json.Serialization; -[JsonObject(MemberSerialization.OptOut, NamingStrategyType = typeof(CamelCaseNamingStrategy))] public class Detector { [JsonPropertyName("detectorId")] @@ -20,7 +16,6 @@ public class Detector [JsonPropertyName("version")] public int Version { get; set; } - [JsonProperty(ItemConverterType = typeof(StringEnumConverter))] [JsonPropertyName("supportedComponentTypes")] public IEnumerable SupportedComponentTypes { get; set; } } diff --git a/src/Microsoft.ComponentDetection.Contracts/BcdeModels/ScanResult.cs b/src/Microsoft.ComponentDetection.Contracts/BcdeModels/ScanResult.cs index 2aec2d833..ad387976d 100644 --- a/src/Microsoft.ComponentDetection.Contracts/BcdeModels/ScanResult.cs +++ b/src/Microsoft.ComponentDetection.Contracts/BcdeModels/ScanResult.cs @@ -3,11 +3,7 @@ namespace Microsoft.ComponentDetection.Contracts.BcdeModels; using System.Collections.Generic; using System.Text.Json.Serialization; -using Newtonsoft.Json; -using Newtonsoft.Json.Converters; -using Newtonsoft.Json.Serialization; -[JsonObject(MemberSerialization.OptOut, NamingStrategyType = typeof(CamelCaseNamingStrategy))] public class ScanResult { [JsonPropertyName("componentsFound")] @@ -22,7 +18,7 @@ public class ScanResult [JsonPropertyName("containerDetailsMap")] public Dictionary ContainerDetailsMap { get; set; } - [Newtonsoft.Json.JsonConverter(typeof(StringEnumConverter))] + [JsonConverter(typeof(JsonStringEnumConverter))] [JsonPropertyName("resultCode")] public ProcessingResultCode ResultCode { get; set; } diff --git a/src/Microsoft.ComponentDetection.Contracts/BcdeModels/ScannedComponent.cs b/src/Microsoft.ComponentDetection.Contracts/BcdeModels/ScannedComponent.cs index 2534a6326..7844f51af 100644 --- a/src/Microsoft.ComponentDetection.Contracts/BcdeModels/ScannedComponent.cs +++ b/src/Microsoft.ComponentDetection.Contracts/BcdeModels/ScannedComponent.cs @@ -3,11 +3,7 @@ namespace Microsoft.ComponentDetection.Contracts.BcdeModels; using System.Collections.Generic; using System.Text.Json.Serialization; -using Newtonsoft.Json; -using Newtonsoft.Json.Converters; -using Newtonsoft.Json.Serialization; -[JsonObject(MemberSerialization.OptOut, NamingStrategyType = typeof(CamelCaseNamingStrategy))] public class ScannedComponent { [JsonPropertyName("locationsFoundAt")] @@ -22,7 +18,7 @@ public class ScannedComponent [JsonPropertyName("isDevelopmentDependency")] public bool? IsDevelopmentDependency { get; set; } - [Newtonsoft.Json.JsonConverter(typeof(StringEnumConverter))] + [JsonConverter(typeof(JsonStringEnumConverter))] [JsonPropertyName("dependencyScope")] public DependencyScope? DependencyScope { get; set; } diff --git a/src/Microsoft.ComponentDetection.Contracts/BcdeModels/TypedComponentConverter.cs b/src/Microsoft.ComponentDetection.Contracts/BcdeModels/TypedComponentConverter.cs deleted file mode 100644 index 2826059bd..000000000 --- a/src/Microsoft.ComponentDetection.Contracts/BcdeModels/TypedComponentConverter.cs +++ /dev/null @@ -1,65 +0,0 @@ -#nullable disable -namespace Microsoft.ComponentDetection.Contracts.BcdeModels; - -using System; -using System.Collections.Generic; -using Microsoft.ComponentDetection.Contracts.TypedComponent; -using Newtonsoft.Json; -using Newtonsoft.Json.Linq; - -public class TypedComponentConverter : JsonConverter -{ - private readonly Dictionary componentTypesToTypes = new Dictionary - { - { ComponentType.Other, typeof(OtherComponent) }, - { ComponentType.NuGet, typeof(NuGetComponent) }, - { ComponentType.Npm, typeof(NpmComponent) }, - { ComponentType.Maven, typeof(MavenComponent) }, - { ComponentType.Git, typeof(GitComponent) }, - { ComponentType.RubyGems, typeof(RubyGemsComponent) }, - { ComponentType.Cargo, typeof(CargoComponent) }, - { ComponentType.Conan, typeof(ConanComponent) }, - { ComponentType.Pip, typeof(PipComponent) }, - { ComponentType.Go, typeof(GoComponent) }, - { ComponentType.DockerImage, typeof(DockerImageComponent) }, - { ComponentType.Pod, typeof(PodComponent) }, - { ComponentType.Linux, typeof(LinuxComponent) }, - { ComponentType.Conda, typeof(CondaComponent) }, - { ComponentType.DockerReference, typeof(DockerReferenceComponent) }, - { ComponentType.Vcpkg, typeof(VcpkgComponent) }, - { ComponentType.Spdx, typeof(SpdxComponent) }, - { ComponentType.DotNet, typeof(DotNetComponent) }, - { ComponentType.CppSdk, typeof(CppSdkComponent) }, - }; - - public override bool CanWrite - { - get { return false; } - } - - public override bool CanConvert(Type objectType) - { - return objectType == typeof(TypedComponent); - } - - public override object ReadJson( - JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer) - { - var jo = JToken.Load(reader); - - var value = (ComponentType)Enum.Parse(typeof(ComponentType), (string)jo["type"]); - var targetType = this.componentTypesToTypes[value]; - var instanceOfTypedComponent = Activator.CreateInstance(targetType, true); - serializer.Populate(jo.CreateReader(), instanceOfTypedComponent); - - return instanceOfTypedComponent; - } - - public override void WriteJson( - JsonWriter writer, - object value, - JsonSerializer serializer) - { - throw new NotImplementedException(); - } -} diff --git a/src/Microsoft.ComponentDetection.Contracts/Microsoft.ComponentDetection.Contracts.csproj b/src/Microsoft.ComponentDetection.Contracts/Microsoft.ComponentDetection.Contracts.csproj index d7aab1c0a..b66542e7a 100644 --- a/src/Microsoft.ComponentDetection.Contracts/Microsoft.ComponentDetection.Contracts.csproj +++ b/src/Microsoft.ComponentDetection.Contracts/Microsoft.ComponentDetection.Contracts.csproj @@ -6,7 +6,6 @@ - diff --git a/src/Microsoft.ComponentDetection.Contracts/TypedComponent/TypedComponent.cs b/src/Microsoft.ComponentDetection.Contracts/TypedComponent/TypedComponent.cs index c29b3dd92..57eab3399 100644 --- a/src/Microsoft.ComponentDetection.Contracts/TypedComponent/TypedComponent.cs +++ b/src/Microsoft.ComponentDetection.Contracts/TypedComponent/TypedComponent.cs @@ -5,16 +5,8 @@ namespace Microsoft.ComponentDetection.Contracts.TypedComponent; using System.Collections.Generic; using System.Diagnostics; using System.Text.Json.Serialization; -using Microsoft.ComponentDetection.Contracts.BcdeModels; -using Newtonsoft.Json; -using Newtonsoft.Json.Converters; -using Newtonsoft.Json.Serialization; using PackageUrl; -using JsonConverterAttribute = Newtonsoft.Json.JsonConverterAttribute; -using JsonIgnoreAttribute = Newtonsoft.Json.JsonIgnoreAttribute; -[JsonObject(MemberSerialization.OptOut, NamingStrategyType = typeof(CamelCaseNamingStrategy))] -[JsonConverter(typeof(TypedComponentConverter))] [DebuggerDisplay("{DebuggerDisplay,nq}")] [JsonPolymorphic(TypeDiscriminatorPropertyName = "type")] [JsonDerivedType(typeof(CargoComponent), typeDiscriminator: nameof(ComponentType.Cargo))] @@ -39,8 +31,7 @@ namespace Microsoft.ComponentDetection.Contracts.TypedComponent; [JsonDerivedType(typeof(VcpkgComponent), typeDiscriminator: nameof(ComponentType.Vcpkg))] public abstract class TypedComponent { - [JsonIgnore] // Newtonsoft.Json - [System.Text.Json.Serialization.JsonIgnore] // System.Text.Json + [JsonIgnore] private string id; internal TypedComponent() @@ -49,21 +40,17 @@ internal TypedComponent() } /// Gets the type of the component, must be well known. - [JsonConverter(typeof(StringEnumConverter))] // Newtonsoft.Json - [JsonProperty("type", Order = int.MinValue)] // Newtonsoft.Json - [System.Text.Json.Serialization.JsonIgnore] // System.Text.Json - type is handled by [JsonPolymorphic] discriminator + [JsonIgnore] // type is handled by [JsonPolymorphic] discriminator public abstract ComponentType Type { get; } /// Gets the id of the component. - [JsonProperty("id")] // Newtonsoft.Json - [JsonPropertyName("id")] // System.Text.Json + [JsonPropertyName("id")] public string Id => this.id ??= this.ComputeId(); [JsonPropertyName("packageUrl")] public virtual PackageURL PackageUrl { get; } - [JsonIgnore] // Newtonsoft.Json - [System.Text.Json.Serialization.JsonIgnore] // System.Text.Json + [JsonIgnore] internal string DebuggerDisplay => $"{this.Id}"; protected string ValidateRequiredInput(string input, string fieldName, string componentType) diff --git a/src/Microsoft.ComponentDetection.Detectors/Microsoft.ComponentDetection.Detectors.csproj b/src/Microsoft.ComponentDetection.Detectors/Microsoft.ComponentDetection.Detectors.csproj index a0fb3f5e4..6e0f3e273 100644 --- a/src/Microsoft.ComponentDetection.Detectors/Microsoft.ComponentDetection.Detectors.csproj +++ b/src/Microsoft.ComponentDetection.Detectors/Microsoft.ComponentDetection.Detectors.csproj @@ -10,7 +10,6 @@ - diff --git a/src/Microsoft.ComponentDetection.Orchestrator/Microsoft.ComponentDetection.Orchestrator.csproj b/src/Microsoft.ComponentDetection.Orchestrator/Microsoft.ComponentDetection.Orchestrator.csproj index 81d898362..031946ccc 100644 --- a/src/Microsoft.ComponentDetection.Orchestrator/Microsoft.ComponentDetection.Orchestrator.csproj +++ b/src/Microsoft.ComponentDetection.Orchestrator/Microsoft.ComponentDetection.Orchestrator.csproj @@ -5,7 +5,6 @@ -