Serialization methods overloads to disable the "only changed properties behaviour"
We recently got very similar questions: https://github.com/microsoftgraph/msgraph-sdk-java/issues/1886 https://github.com/microsoftgraph/msgraph-sdk-java/issues/1879
People generally want to:
- get something from the service
- serialize it to store it locally, in a document db, etc...
While our serialization helpers are helpful, they fall short of one aspect: they don't allow the caller to specify "serialize everything" (as opposed to serializing only the changed properties).
My suggestion here is to:
- add an overload that'd accept a boolean parameter "serializeOnlyCHangedValues" default false
- have the existing implementations call into that overload, with default false (the behaviour will change)
- add a routine that crawls the object tree whenever the value is false, and whenever it finds a backed model, flips the serialize only changed values from the backing store.
- once the serialization is done, crawl the tree again to restore things.
@sebastienlevert to provide input on this one before we start any work, and if we get an agreement here, I'll replicate the issue to the other repos.
Just so I understand. When serializing models (across languages) we only serialize what has changed when the backing store is enabled, right? If this is the case, I agree we should have options to "deep" serialize vs only what is in the backing store.
If it's the case without the backing store, then I think this is a bug, though...
this is only present with the backing store. And we don't want to give people the option, but rather have a consistent behaviour. When they change a collection (set the collection again), we should consider all items within the collection changed, regardless of where they came from. (this is broken) If they only insert/remove items to the collection, then only individual items should be considered changed. (that aspect works today)
Just to make it clear, can you provide a tiny example of before / after of a collection that needs to be serialized?
fixing the broken serialization of collections
var joeUser = client.users.byId("[email protected]").get();
var userResponse = client.users.get();
userResponse.SetValue(new User[] { joeUser });
KiotaJsonSerialization.serializeAsString(userReponse);
results in
{
"value": []
}
when it should result in
{
"value": [{"displayName": "Joe Smith", "email": "[email protected]"}]
}
(that illustrates the broken part)
Option to serialize everything when things didn't change
var userResponse = client.users.get();
KiotaJsonSerialization.serializeAsString(userReponse);
results in
{}
when it should result in
{
"value": [{"displayName": "Joe Smith", "email": "[email protected]"}]
}
For everyone's context, we recently went through this in dotnet and should replicate the changes here. https://github.com/microsoft/kiota-dotnet/pull/367 https://github.com/microsoft/kiota-dotnet/pull/311