Skip to content

chore: Add AOT support Parameters utility #882

New issue

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

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

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 19, 2025
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
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,31 @@ namespace AWS.Lambda.Powertools.Parameters.Internal.Transform;
/// </summary>
internal class JsonTransformer : ITransformer
{
private readonly JsonSerializerOptions _options;

/// <summary>
/// Initializes a new instance of the <see cref="JsonTransformer"/> class.
/// </summary>
public JsonTransformer()
{
_options = new JsonSerializerOptions
{
PropertyNameCaseInsensitive = true
};
}

/// <summary>
/// Deserialize a JSON value from a JSON string.
/// </summary>
/// <param name="value">JSON string.</param>
/// <typeparam name="T">JSON value type.</typeparam>
/// <returns>JSON value.</returns>
#if NET6_0_OR_GREATER
[System.Diagnostics.CodeAnalysis.UnconditionalSuppressMessage("AOT", "IL3050:RequiresDynamicCode",
Justification = "Types are expected to be known at compile time")]
[System.Diagnostics.CodeAnalysis.UnconditionalSuppressMessage("Trimming", "IL2026:RequiresUnreferencedCode",
Justification = "Types are expected to be preserved")]
#endif
public T? Transform<T>(string value)
{
if (typeof(T) == typeof(string))
Expand All @@ -37,6 +56,6 @@ internal class JsonTransformer : ITransformer
if (string.IsNullOrWhiteSpace(value))
return default;

return JsonSerializer.Deserialize<T>(value);
return JsonSerializer.Deserialize<T>(value, _options);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
* permissions and limitations under the License.
*/

using System.Diagnostics.CodeAnalysis;
using System.Text;
using System.Text.Json;
using System.Text.Json.Nodes;
Expand All @@ -32,6 +33,7 @@

namespace AWS.Lambda.Powertools.Parameters.Tests.AppConfig;

[SuppressMessage("Usage", "xUnit1030:Do not call ConfigureAwait(false) in test method")]
public class AppConfigProviderTest
{
[Fact]
Expand Down
Loading