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

Kiota Ignores Repeated Serialization #1561

Closed
buchananwill opened this issue Sep 10, 2024 · 3 comments
Closed

Kiota Ignores Repeated Serialization #1561

buchananwill opened this issue Sep 10, 2024 · 3 comments
Labels
duplicate This issue or pull request already exists Needs: Attention 👋 type:bug A broken experience

Comments

@buchananwill
Copy link

buchananwill commented Sep 10, 2024

I am integrating Kiota/Graph with my existing application API, and while running various test cases to understand the Kiota serializer, I discovered that some of the nested properties weren't serializing. I stripped the test case back to this minimum, and having looked at other open issues (in particular #1131 ), I understand that this behaviour is intentional?

However, it is was extremely unexpected. I would expect serialization to be a side-effect free operation, especially if carried out via a static helper method. Are there optimization reasons that make this non-repeatability necessary? Or could the design be changed to always serialize a full object? Alternatively, could a second method be provided (and more explanation in the documentation) that gives the choice of changed/all properties? My default expectation would be the full object, with changed-only as a option.

package com.futuredyme.ServiceLayers.Utils.MicrosoftGraph;

import com.microsoft.graph.core.requests.BaseGraphRequestAdapter;
import com.microsoft.graph.models.*;
import com.microsoft.graph.serviceclient.GraphServiceClient;
import com.microsoft.kiota.authentication.AnonymousAuthenticationProvider;
import com.microsoft.kiota.serialization.KiotaJsonSerialization;
import org.jetbrains.annotations.NotNull;

import java.io.IOException;
import java.util.LinkedList;
import java.util.Optional;

public class KiotaSideEffectTest {

    public static final String END_TIME = "2017-04-15T14:00:00";
    public static final String START_TIME = "2017-04-15T12:00:00";
    private static final GraphServiceClient graphServiceClient = new GraphServiceClient(new BaseGraphRequestAdapter(new AnonymousAuthenticationProvider()));

    public static void main(String[] args) {
        Event event = createEvent();
        try {
            String string = KiotaJsonSerialization.serializeAsString(event);
            System.out.println(string);
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
        System.out.println(event);
        System.out.println(Optional.ofNullable(event.getAttendees()).map(list -> !list.isEmpty() ? list.get(0) : null).orElse(null));
        try {
            String string = KiotaJsonSerialization.serializeAsString(event);
            System.out.println(string);
        } catch (IOException e) {
            throw new RuntimeException(e);
        }


    }

    private static Event createEvent() {
        Event event = new Event();
        event.setSubject("Let's go for lunch");

        ItemBody body = getItemBody();
        event.setBody(body);

        DateTimeTimeZone start = getDateTimeTimeZone(START_TIME);
        event.setStart(start);

        DateTimeTimeZone end = getDateTimeTimeZone(END_TIME);
        event.setEnd(end);

        Location location = getLocation();
        event.setLocation(location);

        LinkedList<Attendee> attendees = new LinkedList<>();
        Attendee attendee = getAttendee();
        attendees.add(attendee);
        event.setAttendees(attendees);

        event.setAllowNewTimeProposals(true);
        event.setTransactionId("7E163156-7762-4BEB-A1C6-729EA81755A7");
        return event;
    }

    private static @NotNull ItemBody getItemBody() {
        ItemBody body = new ItemBody();
        body.setContentType(BodyType.Html);
        body.setContent("Does noon work for you?");
        return body;
    }

    private static @NotNull DateTimeTimeZone getDateTimeTimeZone(String time) {
        DateTimeTimeZone end = new DateTimeTimeZone();
        end.setDateTime(time);
        end.setTimeZone("Pacific Standard Time");
        return end;
    }

    private static @NotNull Location getLocation() {
        Location location = new Location();
        location.setDisplayName("Harry's Bar");
        return location;
    }

    private static @NotNull Attendee getAttendee() {
        Attendee attendee = new Attendee();
        EmailAddress emailAddress = new EmailAddress();
        emailAddress.setAddress("[email protected]");
        emailAddress.setName("Samantha Booth");
        attendee.setEmailAddress(emailAddress);
        attendee.setType(AttendeeType.Required);
        return attendee;
    }

}

Output:

{"@odata.type":"#microsoft.graph.event","allowNewTimeProposals":true,"attendees":[{"emailAddress":{"address":"[email protected]","name":"Samantha Booth"},"@odata.type":"#microsoft.graph.attendee","type":"required"}],"body":{"content":"Does noon work for you?","contentType":"html"},"end":{"dateTime":"2017-04-15T14:00:00","timeZone":"Pacific Standard Time"},"location":{"displayName":"Harry's Bar"},"start":{"dateTime":"2017-04-15T12:00:00","timeZone":"Pacific Standard Time"},"subject":"Let's go for lunch","transactionId":"7E163156-7762-4BEB-A1C6-729EA81755A7"}
com.microsoft.graph.models.Event@13bc8645
com.microsoft.graph.models.Attendee@93081b6
{}
@github-project-automation github-project-automation bot moved this to Needs Triage 🔍 in Kiota Sep 10, 2024
@Ndiritu Ndiritu moved this from Needs Triage 🔍 to Todo 📃 in Kiota Sep 10, 2024
@Ndiritu Ndiritu added the type:bug A broken experience label Sep 10, 2024
@baywet
Copy link
Member

baywet commented Sep 10, 2024

Hi @buchananwill ,
Thank you for using kiota and for reaching out.

While I appreciate the level of details that you provided, I'm not sure I understand why you created an additional issue here? Maybe I missed something but it seems to be the same request as the issue I originally had created?

@baywet baywet added duplicate This issue or pull request already exists status:waiting-for-author-feedback Issue that we've responded but needs author feedback to close labels Sep 10, 2024
@baywet baywet moved this from Todo 📃 to Waits for author 🔁 in Kiota Sep 10, 2024
@buchananwill
Copy link
Author

Thanks for clarifying. I think you're indeed right - I am more-or-less duplicating your post. Before writing, I read around a few of the related issues and some of them were more specific about serialization of collections, or the serializeAsStream() method. Having re-read the comments on your post, #1131, you have indeed covered the points I've made here. I guess I conflated/confused the different threads and wasn't satisfied that the behaviour was concisely documented in the way I understood it.

My key takeaway: any repeated serialization results in empty lists, or entirely ignored properties.

@microsoft-github-policy-service microsoft-github-policy-service bot added Needs: Attention 👋 and removed status:waiting-for-author-feedback Issue that we've responded but needs author feedback to close labels Sep 10, 2024
@baywet
Copy link
Member

baywet commented Sep 10, 2024

Thanks for confirming, closing as duplicate, feel free to add additional context to the original issue.

@baywet baywet closed this as not planned Won't fix, can't repro, duplicate, stale Sep 10, 2024
@github-project-automation github-project-automation bot moved this from Waits for author 🔁 to Done ✔️ in Kiota Sep 10, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
duplicate This issue or pull request already exists Needs: Attention 👋 type:bug A broken experience
Projects
Archived in project
Development

No branches or pull requests

3 participants