Skip to content
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

Improve usability of the Vogen Json Converter #736

Open
bnaya-corp opened this issue Jan 1, 2025 · 1 comment
Open

Improve usability of the Vogen Json Converter #736

bnaya-corp opened this issue Jan 1, 2025 · 1 comment
Labels
enhancement New feature or request

Comments

@bnaya-corp
Copy link

Describe the feature

Please add a static property for each converter.
It will keep the code cleaner when using it:

For this one:

[ValueObject<string>(Conversions.SystemTextJson | Conversions.TypeConverter)] 
public readonly partial record struct Email
{
}
  • Current
var serilizationOptions = new JsonSerializerOptions();
serilizationOptions.Converters.Add(
            new Email.EmailSystemTextJsonConverter());
  • Desired
var serilizationOptions = new JsonSerializerOptions();
serilizationOptions.Converters.Add(
            Email.EmailSystemTextJsonConverter);

i.e. having a static property of a singleton converter

@bnaya-corp bnaya-corp added the enhancement New feature or request label Jan 1, 2025
@SteveDunn
Copy link
Owner

Thanks for the feedback @bnaya-payoneer .

Did you know that Vogen generates a VogenTypesFactory that you can provide to STJ to resolve the converters?

Also, it is planned to generate these converter classes outside of the type itself. They still need direct access to the private _value field, but Vogen, in other converters, uses System.Runtime.CompilerServices.UnsafeAccessor to access this so as to avoid reflection.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants