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

Extension methods for make serializing easier #338

Closed
svrooij opened this issue Aug 19, 2024 · 5 comments
Closed

Extension methods for make serializing easier #338

svrooij opened this issue Aug 19, 2024 · 5 comments
Labels
enhancement New feature or request help wanted Standard GitHub label Status: No Recent Activity status:waiting-for-author-feedback Issue that we've responded but needs author feedback to close type:enhancement Enhancement request targeting an existing experience

Comments

@svrooij
Copy link
Contributor

svrooij commented Aug 19, 2024

Create extension methods to make serializing easier discoverable, as suggested by @baywet

They have been removed from the PR, in this commit. Feel free to re-use svrooij@a4a03d8

Originally posted by @baywet in #311 (comment)

@github-project-automation github-project-automation bot moved this to Needs Triage 🔍 in Kiota Aug 19, 2024
@baywet
Copy link
Member

baywet commented Aug 21, 2024

Hi @svrooij
Thanks for creating this issue. Let's talk about the experience first so we can later on decide on solutions.

I'm guessing we'd want the following:

IParsable myModel = new();
await myModel.SerializeAsync("mediaType", stream);
var result = await myModel.SerializeAsStringAsync("mediaType");

await myModel.SerializeToJsonAsync(stream);
var result = await myModel.SerializeToJsonAsStringAsync();

This should work for Parsable[] and IEnumerable<IParsable> as well.

To avoid any confusion, it should be in a sub-namespace.

In terms of parameters, here is what the method with the most parameters would look like, everything else will be a subset.

public static async Task SerializeAsync<T>(this T parsable, string meditaType, Stream targetStream, bool serializeOnlyChangedValues = false, CancellationToken cancellationToken = default) where T : IParsable {
//
}

Did I miss anything? Also CC @andrueastman

@svrooij
Copy link
Contributor Author

svrooij commented Aug 21, 2024

I'm not sure about the other namespace, putting it in another namespace will make discovery harder.
Why not put them in the namespace of the respected project. So the JSON namespace for those extensions and the abstractions.serializer for the generic extensions with the media type parameter.

@svrooij
Copy link
Contributor Author

svrooij commented Sep 24, 2024

@baywet to allow discoverability I'm suggesting the following, what do you think:

  • Add those extension methods to the same namespace as the IParsable, this will help with discoverability (which is what we all want I guess)
  • Add them to a different namespace, and maybe point them to it with xml docs on the IParsable

But I would suggest to add the extension methods to the dedicated project. That means you won't have a SerializeToJsonAsStringAsync if you did not include the json package. And I guess everybody is using the json package, but we are not using the forms stuff so those are removed when we generate the kiota client. Then having a SerializeToFormUrlEncoded would be weird to have in Abstractions

@baywet
Copy link
Member

baywet commented Sep 24, 2024

Something like this?

method name package namespace
SerializeAsStringAsync abstractions Microsoft.Kiota.Serialization
SerializeToJsonAsStringAsync serialization json Microsoft.Kiota.Serialization.Json

???

@baywet baywet added enhancement New feature or request status:waiting-for-author-feedback Issue that we've responded but needs author feedback to close type:enhancement Enhancement request targeting an existing experience help wanted Standard GitHub label labels Sep 24, 2024
@baywet baywet moved this from Needs Triage 🔍 to Waits for author 🔁 in Kiota Sep 24, 2024
svrooij added a commit to svrooij/ms-kiota-dotnet that referenced this issue Sep 24, 2024
Fixed Extension methods for make serializing easier microsoft#338

This issue has been automatically marked as stale because it has been marked as requiring author feedback but has not had any activity for 4 days. It will be closed if no further activity occurs within 3 days of this comment.

@github-project-automation github-project-automation bot moved this from Waits for author 🔁 to Done ✔️ in Kiota Oct 3, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request help wanted Standard GitHub label Status: No Recent Activity status:waiting-for-author-feedback Issue that we've responded but needs author feedback to close type:enhancement Enhancement request targeting an existing experience
Projects
Archived in project
Development

No branches or pull requests

2 participants