Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/Fallout.Common/CI/GitHubActions/GitHubActions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -114,8 +114,10 @@ internal GitHubActions()

public JObject GitHubEvent => _eventContext.Value;
public bool IsPullRequest => EventName == "pull_request";
#pragma warning disable CS0618 // JObjectExtensions retires in v11; PullRequestNumber/Action follow when GitHubEvent migrates to JsonObject (API-break, separate PR).
public int? PullRequestNumber => GitHubEvent.GetPropertyValue<int>("number");
public string PullRequestAction => GitHubEvent.GetPropertyStringValue("action");
#pragma warning restore CS0618

public AbsolutePath StepSummaryFile => EnvironmentInfo.GetVariable("GITHUB_STEP_SUMMARY");

Expand Down
14 changes: 7 additions & 7 deletions src/Fallout.Common/Tools/SignPath/SignPathTasks.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@
using System.Net.Http;
using System.Net.Http.Headers;
using System.Text;
using System.Text.Json.Nodes;
using System.Threading.Tasks;
using Newtonsoft.Json.Linq;
using Fallout.Common.CI.AppVeyor;
using Fallout.Common.IO;
using Fallout.Common.Utilities;
Expand Down Expand Up @@ -71,7 +71,7 @@ public static async Task<string> GetSigningRequestUrlViaAppVeyor(
using var httpClient = CreateAuthorizedHttpClient(authToken, DefaultHttpClientTimeout);
var response = await httpClient.PostAsync(
GetSignPathAppVeyorIntegrationUrl(organizationId, projectSlug, signingPolicySlug),
new StringContent(content.ToJson(), Encoding.UTF8, contentType));
new StringContent(content.ToJson(JsonExtensions.DefaultSerializerOptions), Encoding.UTF8, contentType));
response.AssertStatusCode(HttpStatusCode.Created);

Log.Information("Signing request created: {Url}", response.Headers.Location.AbsoluteUri.Replace("api/v1", "Web"));
Expand Down Expand Up @@ -149,11 +149,11 @@ private static string GetSignedArtifactUrl(HttpClient httpClient, string signing
{
var response = SendGetRequestWithRetry(httpClient, signingRequestUrl);
var rawContent = response.Content.ReadAsStringAsync().GetAwaiter().GetResult();
var jsonContent = rawContent.GetJson();
signingRequestStatus = jsonContent["status"].NotNull().Value<string>();
var jsonContent = rawContent.GetJsonObject();
signingRequestStatus = jsonContent["status"].NotNull().GetValue<string>();
signedArtifactUrl = signingRequestStatus switch
{
SigningRequestStatus.Completed => jsonContent["signedArtifactLink"].NotNull().Value<string>(),
SigningRequestStatus.Completed => jsonContent["signedArtifactLink"].NotNull().GetValue<string>(),
SigningRequestStatus.Failed => null,
SigningRequestStatus.Denied => null,
SigningRequestStatus.Cancelled => null,
Expand Down Expand Up @@ -255,8 +255,8 @@ private static HttpResponseMessage AssertStatusCode(this HttpResponseMessage res
if (response.StatusCode != statusCode)
{
var content = response.Content.ReadAsStringAsync().GetAwaiter().GetResult();
var jobject = content.GetJson();
Assert.Fail($"[{response.StatusCode}] {jobject.GetChildren<JValue>("").Select(x => x.Value<string>()).JoinNewLine()}");
var jobject = content.GetJsonObject();
Assert.Fail($"[{response.StatusCode}] {jobject.GetChildren<JsonValue>("").Select(x => x.GetValue<string>()).JoinNewLine()}");
}

return response;
Expand Down
2 changes: 2 additions & 0 deletions src/Fallout.Tooling/ProcessExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,9 @@ public static string StdToText(this IEnumerable<Output> output)

public static T StdToJson<T>(this IEnumerable<Output> output)
{
#pragma warning disable CS0618 // GetJson<T>(Newtonsoft) retires in v11; this whole StdToJson surface is part of the Fallout.Tooling migration follow-up.
return output.StdToText().GetJson<T>();
#pragma warning restore CS0618
}

public static JObject StdToJson(this IEnumerable<Output> output)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ namespace Fallout.Common.Tooling;
/// <summary>
/// Treats all properties as writable.
/// </summary>
[Obsolete("Newtonsoft-specific contract resolver. System.Text.Json handles records and init-only properties natively, so this workaround is unnecessary on the STJ path. Scheduled for removal in v11 (#83).")]
internal class AllWritableContractResolver : DefaultContractResolver
{
protected override JsonProperty CreateProperty(MemberInfo member, MemberSerialization memberSerialization)
Expand Down
1 change: 1 addition & 0 deletions src/Fallout.Utilities.Text.Json/Base64JsonConverter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

namespace Fallout.Utilities.Text.Json;

[Obsolete("Newtonsoft-specific Base64 JSON type converter with zero internal callers. Scheduled for removal in v11 (#83); consumers needing this should pin Newtonsoft.Json directly.")]
public class Base64JsonConverter<T> : TypeConverter
{
public override object ConvertFrom(ITypeDescriptorContext context, CultureInfo culture, object value)
Expand Down
7 changes: 7 additions & 0 deletions src/Fallout.Utilities.Text.Json/JObject.GetChildren.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,27 @@
// Distributed under the MIT License.
// https://github.com/ChrisonSimtian/Fallout/blob/main/LICENSE

using System;
using Newtonsoft.Json.Linq;

namespace Fallout.Common.Utilities;

public static partial class JObjectExtensions
{
[Obsolete("Use the JsonObject overload in JsonNodeExtensions instead. Newtonsoft.Json surface is scheduled for removal in v11 (#83).")]
public static JEnumerable<T> GetChildren<T>(this JObject jobject, string name)
where T : JToken
{
#pragma warning disable CS0618 // Newtonsoft helpers retire together.
return jobject.GetPropertyValue<JArray>(name).Children<T>();
#pragma warning restore CS0618
}

[Obsolete("Use the JsonObject overload in JsonNodeExtensions instead. Newtonsoft.Json surface is scheduled for removal in v11 (#83).")]
public static JEnumerable<JObject> GetChildren(this JObject jobject, string name)
{
#pragma warning disable CS0618 // Newtonsoft helpers retire together.
return jobject.GetChildren<JObject>(name);
#pragma warning restore CS0618
}
}
8 changes: 8 additions & 0 deletions src/Fallout.Utilities.Text.Json/JObject.GetPropertyValue.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ namespace Fallout.Common.Utilities;

public static partial class JObjectExtensions
{
[Obsolete("Use the JsonObject overload in JsonNodeExtensions instead. Newtonsoft.Json surface is scheduled for removal in v11 (#83).")]
public static T GetPropertyValueOrNull<T>(this JObject jobject, string name)
{
var property = jobject.Property(name);
Expand All @@ -19,19 +20,26 @@ public static T GetPropertyValueOrNull<T>(this JObject jobject, string name)
: default;
}

[Obsolete("Use the JsonObject overload in JsonNodeExtensions instead. Newtonsoft.Json surface is scheduled for removal in v11 (#83).")]
public static T GetPropertyValue<T>(this JObject jobject, string name)
{
var property = jobject.Property(name).NotNull($"Property '{name}' not found");
return property.Value.Value<T>();
}

[Obsolete("Use the JsonObject overload in JsonNodeExtensions instead. Newtonsoft.Json surface is scheduled for removal in v11 (#83).")]
public static JObject GetPropertyValue(this JObject jobject, string name)
{
#pragma warning disable CS0618 // Newtonsoft helpers retire together.
return jobject.GetPropertyValue<JObject>(name);
#pragma warning restore CS0618
}

[Obsolete("Use the JsonObject overload in JsonNodeExtensions instead. Newtonsoft.Json surface is scheduled for removal in v11 (#83).")]
public static string GetPropertyStringValue(this JObject jobject, string name)
{
#pragma warning disable CS0618 // Newtonsoft helpers retire together.
return jobject.GetPropertyValue<string>(name);
#pragma warning restore CS0618
}
}
7 changes: 7 additions & 0 deletions src/Fallout.Utilities.Text.Json/JsonExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,16 @@ namespace Fallout.Common.Utilities;

public static class JsonExtensions
{
[Obsolete("Use DefaultSerializerOptions (JsonSerializerOptions) instead. Newtonsoft.Json surface is scheduled for removal in v11 (#83).")]
#pragma warning disable CS0618 // AllWritableContractResolver retires alongside.
public static JsonSerializerSettings DefaultSerializerSettings =
new()
{
NullValueHandling = NullValueHandling.Ignore,
DefaultValueHandling = DefaultValueHandling.Ignore,
ContractResolver = new AllWritableContractResolver()
};
#pragma warning restore CS0618

public static JsonSerializerOptions DefaultSerializerOptions { get; } =
new()
Expand All @@ -46,7 +49,9 @@ public static string ToJson<T>(
JsonSerializerSettings serializerSettings = null,
Formatting formatting = Formatting.Indented)
{
#pragma warning disable CS0618 // DefaultSerializerSettings retires alongside.
return JsonConvert.SerializeObject(obj, formatting, serializerSettings ?? DefaultSerializerSettings);
#pragma warning restore CS0618
}

/// <summary>
Expand All @@ -55,7 +60,9 @@ public static string ToJson<T>(
[Obsolete("Use the JsonSerializerOptions overload instead. Newtonsoft.Json surface is scheduled for removal in v11 as part of the System.Text.Json migration (#83).")]
public static T GetJson<T>(this string content, JsonSerializerSettings serializerSettings = null)
{
#pragma warning disable CS0618 // DefaultSerializerSettings retires alongside.
return JsonConvert.DeserializeObject<T>(content, serializerSettings ?? DefaultSerializerSettings);
#pragma warning restore CS0618
}

/// <summary>
Expand Down
1 change: 1 addition & 0 deletions src/Fallout.Utilities.Text.Json/Object.ToJObject.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ namespace Fallout.Common.Utilities;
// invisible to callers and a rename is the cleanest fix.
public static class JsonObjectExtensions
{
[Obsolete("Returns a Newtonsoft JObject. For new code, use System.Text.Json.Nodes.JsonNode.Parse(System.Text.Json.JsonSerializer.Serialize(obj)) or JsonSerializer.SerializeToNode(obj). Scheduled for removal in v11 (#83).")]
public static JObject ToJObject(this object obj, JsonSerializer serializer = null)
{
serializer ??= JsonSerializer.CreateDefault();
Expand Down
6 changes: 6 additions & 0 deletions src/Shims/Nuke.Common/Nuke.Common.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,12 @@
<!-- Disable XML doc generation here; Directory.Build.props turns it on for packable projects,
but the shim types' XML docs are intentionally minimal (point at the canonical type). -->
<GenerateDocumentationFile>false</GenerateDocumentationFile>
<!-- Suppress CS0618 on the generated shim source. The TransitionShimGenerator emits delegations
to canonical methods, and any canonical method marked [Obsolete] propagates the warning into
the auto-generated shim body. Consumers calling the canonical type directly still see the
[Obsolete] guidance; this NoWarn just keeps the shim project's build clean. Track propagating
[Obsolete] through the generator as a v11 follow-up. -->
<NoWarn>$(NoWarn);CS0618</NoWarn>
</PropertyGroup>

<ItemGroup>
Expand Down
2 changes: 2 additions & 0 deletions tests/Fallout.Common.Tests/SettingsTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,7 @@ public void TestDocker()
[Fact]
public Task TestDiscord()
{
#pragma warning disable CS0618 // Test pins Options.JsonSerializerSettings round-trip; STJ equivalents follow in Fallout.Tooling's #83 migration.
var result = new DiscordMessage()
.SetNonce("nonce")
.SetChannelId("channel-id")
Expand All @@ -181,6 +182,7 @@ public Task TestDiscord()
.SetAuthor(_ => _
.SetName("author-name")))
.ToJson(Options.JsonSerializerSettings);
#pragma warning restore CS0618

return Verifier.Verify(result);
}
Expand Down
2 changes: 2 additions & 0 deletions tests/Fallout.Tooling.Tests/OptionsTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,9 @@ public Task TestSerialization()
options.Set(() => LookupValue, new LookupTable<string, int> { ["key"] = new[] { 1, 2, 3 } });
options.Set(() => NestedValue, options);

#pragma warning disable CS0618 // Test pins Options.JsonSerializerSettings round-trip; STJ equivalents follow in Fallout.Tooling's #83 migration.
return Verifier.Verify(options.ToJson(Options.JsonSerializerSettings));
#pragma warning restore CS0618
}
}

Expand Down
2 changes: 2 additions & 0 deletions tests/Fallout.Tooling.Tests/ToolOptionsArgumentsTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,9 @@ private static T SetInternalOptions<T>(object obj)
where T : ToolOptions, new()
{
var options = new T();
#pragma warning disable CS0618 // ToJObject (Newtonsoft) retires in v11 alongside ToolOptions.InternalOptions which is itself JObject-typed.
options.InternalOptions = obj.ToJObject(Options.JsonSerializer);
#pragma warning restore CS0618
return options;
}
}
2 changes: 2 additions & 0 deletions tests/Fallout.Utilities.Tests/Text/SerializationTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,10 @@ public class SerializationTest
public void JsonTest()
{
var data = CreateData("Json");
#pragma warning disable CS0618 // Test pins Newtonsoft round-trip semantics; STJ equivalents will get their own test cases in v11.
var content = data.ToJson();
var copy = content.GetJson<Data>();
#pragma warning restore CS0618

copy.Should().BeEquivalentTo(data);
}
Expand Down
Loading