Closed darbio closed 4 years ago
Agreed, seems like a good addition!
Hi @andrewlock, I am up for implementing this, but I need your opinion. I think it's good idea to enable to pick which serializer you want to use, and have support for both System.Text.Json
and Newtonsoft.Json
.
This requires changes in StronglyTypedIdAttribute
parameters. My proposition is to add new enum parameter jsonProvider
(which would default to StronglyTypedIdJsonProvider.NewtonsoftJson
):
// no provider needed
[StronglyTypedId(generateJsonConverter: false, backingType: StronglyTypedIdBackingType.Int)]
// old behavior, generates converter for Newtonsoft.Json
[StronglyTypedId(backingType: StronglyTypedIdBackingType.Int)]
// one specific
[StronglyTypedId(jsonConverter: StronglyTypedIdJsonProvider.NewtonsoftJson, backingType: StronglyTypedIdBackingType.Int)]
[StronglyTypedId(jsonConverter: StronglyTypedIdJsonProvider.SystemTextJson, backingType: StronglyTypedIdBackingType.Int)]
// both of them, because why not?
[StronglyTypedId(jsonConverter: StronglyTypedIdJsonProvider.NewtonsoftJson | StronglyTypedIdJsonProvider.SystemTextJson, backingType: StronglyTypedIdBackingType.Int)]
Are you okay with that approach?
Sounds good to me, thanks! 🙂
Thanks to @vebbo2 for implementing this in https://github.com/andrewlock/StronglyTypedId/pull/11, I'll push out a release to NuGet shortly
ASP.Net Core 3.1 uses System.Text.Json to serialize objects. It would be good to support this new method of serialization.
I currently use the following (obviously it would need adapting to support the relevant use cases in this package).
This issue depends upon #5