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

KiotaJsonSerialization.serializeAsString should have some mechanism to override backing store functionality #1417

Closed
jasonjoh opened this issue Jun 28, 2024 · 2 comments
Assignees
Labels
enhancement New feature or request type:enhancement Enhancement request targeting an existing experience

Comments

@jasonjoh
Copy link
Member

Copied from microsoftgraph/msgraph-sdk-java#2064. There should be some mechanism in KiotaJsonSerialization.serializeAsString to override backing store so that all fields get serialized without requiring a developer to manually muck with the backing store.

Describe the bug

final Subscription subscription = graphClient.subscriptions().post(subscriptionRequest);
final var subscriptionJson = KiotaJsonSerialization.serializeAsString(subscription);

This results in subscriptionJson being {}. This was originally reported in #1879.

The suggested fix to call subscription.getBackingStore().setReturnOnlyChangedValues(false); did not change the result. It should be noted that subscription.getBackingStore().getReturnOnlyChangedValues(); returned false before this anyway. On a whim, I tried calling subscription.getBackingStore().setReturnOnlyChangedValues(true); before serializing, and I got a partial result:

{"@odata.context":"https://graph.microsoft.com/v1.0/$metadata#subscriptions/$entity"}

Expected behavior

subscriptionJson should be a full JSON representation of the subscription object returned by the service.

How to reproduce

Code above.

Graph SDK Version

6.13.0

Latest version known to work for scenario above?

No response

Known Workarounds

This works but is way less convenient than using the static methods. It also requires an explicit reference to microsoft-kiota-serialization-json in your dependencies, which I suspect can cause problems down the line as the SDK bumps its versions.

final var writer = new JsonSerializationWriter();
writer.writeObjectValue(null, subscription);
final var bytes = writer.getSerializedContent().readAllBytes();
final var subscriptionJson = new String(bytes, "UTF-8");
writer.close();
@github-project-automation github-project-automation bot moved this to Needs Triage 🔍 in Kiota Jun 28, 2024
@baywet
Copy link
Member

baywet commented Jun 28, 2024

Thanks for the suggestion. The solution to that would be to:

  1. add a serializeOnlyChangedValues boolean parameter to this method
  2. in the body test if the parsable is a backed model, if so switch the flag. (recursively)
  3. serialize
  4. switch the flag back
  5. add an overload without the parameter, which passes false
  6. reflect all the overloads all the way up to the Json part

Orthogonally, we might have a bug with this flag we should investigate.

Prior work in the space microsoft/kiota-dotnet#95 to look at during the bug investigation.

Once this is done, we need to open similar issues for other languages.

@baywet baywet added enhancement New feature or request type:enhancement Enhancement request targeting an existing experience labels Jun 28, 2024
@baywet baywet moved this from Needs Triage 🔍 to Todo 📃 in Kiota Jun 28, 2024
@Ndiritu Ndiritu self-assigned this Sep 23, 2024
@Ndiritu
Copy link
Contributor

Ndiritu commented Sep 23, 2024

seems to be a duplicate of #1131

@Ndiritu Ndiritu closed this as completed Sep 23, 2024
@github-project-automation github-project-automation bot moved this from Todo 📃 to Done ✔️ in Kiota Sep 23, 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 type:enhancement Enhancement request targeting an existing experience
Projects
Archived in project
Development

No branches or pull requests

3 participants