-
Notifications
You must be signed in to change notification settings - Fork 33
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
Idea: Use Kiota generated models for serialization #310
Comments
This should work using var jsonSerializerWriter = new JsonSerializationWriter();
jsonSerializerWriter.WriteObjectValue(string.Empty, user);
var serializedStream = jsonSerializerWriter.GetSerializedContent();
using var reader = new StreamReader(serializedStream, Encoding.UTF8);
var serializedJsonString = reader.ReadToEnd(); There is also |
@MartinM85 thanks for the quick reply. That seems not to work. the object is still empty, I want it to work because that would be awesome. And I wonder why deserializing to a stream is not async with this helper. |
Hi everyone, I think the request here is effectively the same as this one. Could you confirm please? |
I guess it's related to a fact that |
@baywet as that is a different language, it's not the same, but definitely related. And apart from that, an extension method for IParseable in the JSON serializer namespace, that hides all the mandatory initializing would be great. And then maybe also the counterpart where you can say, I have this json stream, parse it as T This would really help everyone that is saving returned objects to do some sort of desired state using files in git This code seems to work for the serializing part: public static Stream? SerializeAsJsonStream<T>(this T? input) where T : IParsable
{
if (input == null) return null;
var writer = new Microsoft.Kiota.Serialization.Json.JsonSerializationWriter(new Microsoft.Kiota.Serialization.Json.KiotaJsonSerializationContext());
writer.WriteObjectValue(null, input);
return writer.GetSerializedContent();
} Diving deeper into this, I noticed that all the json serializing is done synchronously, what is the reason for that? Seems like it might have some room for speed improvements? |
I went ahead and added:
|
Aysnc API
I'm guessing you're referring to these calls: This would "force us" to have the whole ISerializationWriter interface to be async (all the methods in there) which would be a source breaking change at this point.
Likewise it'd contaminate the API surface A couple of thoughts here:
solutionI've provided additional context to why this method works on the PR. coordinationWe'll want to coordinate that change across languages that have these helper methods to avoid differences in experiences (only CSharp/Java/TypeScript/Go at the moment) Hopefully all of that helps make progress here. |
I was wondering if I could use the models together with the used
JsonSerializerOptions
to read/write json.The use case is that I would want to save some results of the Graph API, to a folder. Talking conditional access policies here, but any model will do. And I don't want to do any customizations, just save the object exactly as it would be transferred to and from the api.
pseudo code
Discussion
This is not really an issue, but this repo doesn't have discussions enabled.
The text was updated successfully, but these errors were encountered: