microsoftgraph / msgraph-sdk-java

Microsoft Graph SDK for Java
https://docs.microsoft.com/en-us/graph/sdks/sdks-overview
MIT License
403 stars 134 forks source link

Java Graph API 6.6.0 - reading Sharepoint sites produces error: java.time.format.DateTimeParseException: Text '2024-04-26T09:06:55' could not be parsed at index 19 #1968

Closed klehmann closed 6 months ago

klehmann commented 7 months ago

Expected behavior

Sites can be loaded without errors.

Actual behavior

Using Graph API 6.6.0 from Maven Central with Java 17, I get this error:

java.time.format.DateTimeParseException: Text '2024-04-26T09:06:55' could not be parsed at index 19
    at java.base/java.time.format.DateTimeFormatter.parseResolved0(DateTimeFormatter.java:2052)
    at java.base/java.time.format.DateTimeFormatter.parse(DateTimeFormatter.java:1954)
    at java.base/java.time.OffsetDateTime.parse(OffsetDateTime.java:404)
    at java.base/java.time.OffsetDateTime.parse(OffsetDateTime.java:389)
    at com.microsoft.kiota.serialization.JsonParseNode.getOffsetDateTimeValue(JsonParseNode.java:98)
    at com.microsoft.graph.models.odataerrors.InnerError.lambda$getFieldDeserializers$1(InnerError.java:83)
    at com.microsoft.kiota.serialization.JsonParseNode.assignFieldValues(JsonParseNode.java:247)
    at com.microsoft.kiota.serialization.JsonParseNode.getObjectValue(JsonParseNode.java:198)
    at com.microsoft.graph.models.odataerrors.MainError.lambda$getFieldDeserializers$2(MainError.java:83)
    at com.microsoft.kiota.serialization.JsonParseNode.assignFieldValues(JsonParseNode.java:247)
    at com.microsoft.kiota.serialization.JsonParseNode.getObjectValue(JsonParseNode.java:198)
    at com.microsoft.graph.models.odataerrors.ODataError.lambda$getFieldDeserializers$0(ODataError.java:74)
    at com.microsoft.kiota.serialization.JsonParseNode.assignFieldValues(JsonParseNode.java:247)
    at com.microsoft.kiota.serialization.JsonParseNode.getObjectValue(JsonParseNode.java:198)
    at com.microsoft.kiota.http.OkHttpRequestAdapter.lambda$throwIfFailedResponse$0(OkHttpRequestAdapter.java:672)
    at com.microsoft.kiota.ApiExceptionBuilder.<init>(ApiExceptionBuilder.java:26)
    at com.microsoft.kiota.http.OkHttpRequestAdapter.throwIfFailedResponse(OkHttpRequestAdapter.java:671)
    at com.microsoft.kiota.http.OkHttpRequestAdapter.send(OkHttpRequestAdapter.java:279)
    at com.microsoft.graph.sites.SitesRequestBuilder.get(SitesRequestBuilder.java:119)
    at com.mindoo.domino.test.Graph.getSharepointSites(Graph.java:68)

which seems to be identical to #1785 which got fixed in 6.2.1. Maybe this is a regression.

Steps to reproduce the behavior

Just playing around with the sample code and read the SiteCollectionResponse.

    public static SiteCollectionResponse getSharepointSites() throws Exception {
         // Ensure client isn't null
        if (_appClient == null) {
            throw new Exception("Graph has not been initialized for app-only auth");
        }

        return _appClient.sites().get(requestConfiguration -> {
            requestConfiguration.queryParameters.select = new String []{"siteCollection", "webUrl"};
            requestConfiguration.queryParameters.filter = "siteCollection/root ne null";
        });

    }

    SiteCollectionResponse sites = Graph.getSharepointSites();

    for (Site site : sites.getValue() ) {
                    writer.println("Site: " + site.getDisplayName());
                    writer.println("  Weburl: " + site.getWebUrl());
    }

    final Boolean moreSitesAvailable = sites.getOdataNextLink() != null;
    writer.println("\nMore sites available? " + moreSitesAvailable);
klehmann commented 7 months ago

I downgraded to 6.2.1 as this version is mentioned in #1785 for a fix and also got the date/time issue. Has this ever been fixed?

klehmann commented 7 months ago

Is there a way to set the HTTP header "Prefer: outlook.timezone" with the Java Graph API as a workaround to specify the timezone to use on server side?

ccea-dev-team commented 7 months ago

private static final String OUTLOOK_TIMEZONE = "outlook.timezone=\"Europe\London\"";

Then use requestconfiguration headers in the call like below -

return graphClient.users().byUserId(meetingOwnerEmail).events().post(event, requestConfiguration -> { requestConfiguration.headers.add("Prefer", OUTLOOK_TIMEZONE); });

klehmann commented 7 months ago

Does not help, I am still getting this wrong date/time format and conversion error. That's really weird. The Graph API Explorer returns datetime values ending with "Z", but the Java Graph AI gets a value without timezone.

Ndiritu commented 7 months ago

@klehmann thanks for trying out this SDK. Might you be taking a direct dependency on microsoft-graph-core or any microsoft-kiota package as well?

From my tests the error deserialization works as expected.

klehmann commented 7 months ago

@Ndiritu My dependencies look like this:


    <dependencies>
        <dependency>
            <groupId>com.microsoft.graph</groupId>
            <artifactId>microsoft-graph</artifactId>
            <version>6.7.0</version>
        </dependency>
        <dependency>
            <groupId>com.azure</groupId>
            <artifactId>azure-identity</artifactId>
            <version>1.12.0</version>
        </dependency>
        <dependency>
            <groupId>com.microsoft.kiota</groupId>
            <artifactId>microsoft-kiota-abstractions</artifactId>
            <version>1.0.0</version>
        </dependency>
        <dependency>
            <groupId>com.microsoft.kiota</groupId>
            <artifactId>microsoft-kiota-authentication-azure</artifactId>
            <version>1.0.0</version>
        </dependency>
        <dependency>
            <groupId>com.microsoft.kiota</groupId>
            <artifactId>microsoft-kiota-http-okHttp</artifactId>
            <version>1.0.0</version>
        </dependency>
        <dependency>
            <groupId>com.microsoft.kiota</groupId>
            <artifactId>microsoft-kiota-serialization-json</artifactId>
            <version>1.0.0</version>
        </dependency>
        <dependency>
            <groupId>com.microsoft.kiota</groupId>
            <artifactId>microsoft-kiota-serialization-text</artifactId>
            <version>1.0.0</version>
        </dependency>
        <dependency>
            <groupId>com.microsoft.kiota</groupId>
            <artifactId>microsoft-kiota-serialization-form</artifactId>
            <version>1.0.0</version>
        </dependency>
        <dependency>
            <groupId>com.microsoft.kiota</groupId>
            <artifactId>microsoft-kiota-serialization-multipart</artifactId>
            <version>1.0.0</version>
        </dependency>       
    </dependencies>

What should I use instead?

Ndiritu commented 7 months ago

@klehmann Keeping microsoft-graph and azure-identity is enough, so that you get the Kiota patch updates by default as you upgrade microsoft-graph.

microsoft-github-policy-service[bot] commented 6 months ago

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.