pulumi / pulumi-dotnet

.NET support for Pulumi
Apache License 2.0
27 stars 25 forks source link

Allow customization of JsonSerializationOptions #370

Open rosieks opened 3 weeks ago

rosieks commented 3 weeks ago

Hello!

Issue details

Right now to deserialize configuration Pulumi use default settings for JsonSerializer. That means that if someone wants to use to use different configuration then it's forced to use eg JsonPropertyName and others tools on each class which makes code harder to read. It would be great if there was an option to override it and provide custom JsonSerializerOptions.

Affected area/feature

justinvp commented 3 weeks ago

Make sense, thanks! There's already precedent for exposing System.Text.Json.JsonSerializerOptions from an API in our SDK: https://github.com/pulumi/pulumi-dotnet/blob/b03530027118e9305c2b69be37f88a70ceb81900/sdk/Pulumi/Core/Output.cs#L318

For now, another alternative workaround would be to get the config as a string value and the deserialize the JSON yourself using whatever deserializer/options you'd like.

rosieks commented 3 weeks ago

Easy to implement that is just add new constructor that allows you to provide options. If that's acceptable way I can provide PR.

justinvp commented 3 weeks ago

I don't think it'd be a new constructor. I think it'd be new overloads on the Get*Object/Require*Object methods:

public T GetObject<T>(string key); // Existing
public T GetObject<T>(string key, System.Text.Json.JsonSerializerOptions options); // New

public Output<T>? GetSecretObject<T>(string key); // Existing
public Output<T>? GetSecretObject<T>(string key, System.Text.Json.JsonSerializerOptions options); // New

public T RequireObject<T>(string key); // Existing
public T RequireObject<T>(string key, System.Text.Json.JsonSerializerOptions options); // New

public Output<T> RequireSecretObject<T>(string key); // Existing
public Output<T> RequireSecretObject<T>(string key, System.Text.Json.JsonSerializerOptions options); // New

I can provide PR

That'd be great, thanks! But let me discuss the proposal with the team first in our design meeting early next week.

justinvp commented 2 weeks ago

@rosieks, if you're still interested, we discussed the APIs I outlined above and are good add those, if you'd like to provide a PR. Please include tests. Thank you!