msgraph-sdk-java icon indicating copy to clipboard operation
msgraph-sdk-java copied to clipboard

Java sdk is giving null value in get cell action

Open ashish777gupta opened this issue 1 year ago • 4 comments

When trying to fetch cell values via the Java SDK, we're encountering an unexpected problem: the value returned is null. Strangely, in Postman and Graph Explorer, the values display correctly.

Our goal was to smoothly retrieve the cell value using the Java SDK, but it's not working. Please assist, with the mentioned issue.

Postman screenshot: image

Java sdk screenshot: image

ashish777gupta avatar May 03 '24 06:05 ashish777gupta

Kindly assist with the above comment. Thanks!

ashish777gupta avatar May 09 '24 13:05 ashish777gupta

Pleases assist us. Thanks!

ashish777gupta avatar May 21 '24 04:05 ashish777gupta

OK I did confirm with @Ndiritu that it should work, given the support in Kiota for microsoft.graph.Json was added recently. So, we need to look into the issue. Also see the question asked here: https://stackoverflow.com/questions/78457958/get-cell-value-using-graph-api-v6-x-is-not-displaying-the-value-in-java-sdk

PR was merged: https://github.com/microsoft/kiota-java/pull/1070

CC @sebastienlevert

petrhollayms avatar May 30 '24 06:05 petrhollayms

Thanks for the response @petrhollayms . Can you please let me know that, is this issue new and if it's new then what is the expected time it would take to fix it. And also if fixed then how to consume the fixed version?

ashish777gupta avatar May 30 '24 07:05 ashish777gupta

@ashish777gupta the value is not null. The actual value is nested under some abstractions. The challenge is that the API returns JSON for this property & we don't want to tie our generated code to any JSON lib dependency.

To get a JSON string of the actual value which you can parse with your JSON lib of choice


String jsonString = KiotaJsonSerialization.serializeAsString(workbookRange.getValues());

Otherwise the value is nested under a bunch of abstractions


if (workbookRange.getValues() != null) {
    UntypedArray untypedValues = (UntypedArray) workbookRange.getValues();
    java.util.List<UntypedNode> cellValuesList = (java.util.List<UntypedNode>) untypedValues.getValue();
    UntypedArray untypedFirstCellValue = (UntypedArray) cellValuesList.get(0);
    java.util.List<UntypedNode> cellValues = (java.util.List<UntypedNode>) untypedFirstCellValue.getValue();
    Double cellValue = ((UntypedDouble) cellValues.get(0)).getValue();
}

You can use these as references:

  • https://learn.microsoft.com/en-us/openapi/kiota/serialization?tabs=java#serialization-helpers
  • https://learn.microsoft.com/en-us/openapi/kiota/serialization?tabs=java#untyped-node

Please let me know if this works.

Ndiritu avatar Aug 16 '24 09:08 Ndiritu

Thanks for the response @Ndiritu

ashish777gupta avatar Aug 20 '24 07:08 ashish777gupta