add application and service principal owner with msgraph-sdk-java

Michael 0 Reputation points

Following the documentation, I tried to add an owner for an application and a service principal as follows:

val referenceCreate= ReferenceCreate()
referenceCreate.odataId = "$owner"


This code leads to an Exception like: An unexpected 'EndOfInput' node was found when reading from the JSON reader. A 'StartObject' node was expected.



I can avoid this problem by creating two instances of ReferenceCreate:

val applicationOwnerReference = ReferenceCreate()
val servicePrincipalOwnerReference = ReferenceCreate()

applicationOwnerReference.odataId = "$owner"
servicePrincipalOwnerReference.odataId = "$owner"


Can someone explain why this is happening? Is this behavior intended?

Regards, Michael

Microsoft Graph
Microsoft Graph
A Microsoft programmability model that exposes REST APIs and client libraries to access data on Microsoft 365 services.
10,524 questions
{count} votes

2 answers

Sort by: Most helpful
  1. Azar 18,295 Reputation points

    Hey there Michael

    Thats a good question and thanks for using QandA platform.

    So when you initially create a ReferenceCreate object and set its odataId, the object holds a reference to that URL. bt, when you reuse the same ReferenceCreate object for both application and service principal owners, it seems that there might be some internal state management issue with the SDK causing unexpected behavior. (I guess)

    For a workaround create a separate instances of ReferenceCreate for each operation. Each instance maintains its own state and doesn't interfere with the other, hope that removves the issue you are facing.

    And regarding whether this is intended or not, without knowning the specifics of the Microsoft Graph SDK for Java, it's difficult to say definitively. but, based on the observed behavior and your workaround, it seems like reusing the same instance of ReferenceCreate for multiple operations might not be properly handled by the SDK, leading to unexpected errors.

    If this helps kindly accept the answer thanks much.

  2. Ramses Sanchez Hernandez 0 Reputation points Microsoft Employee

    This behavior is due to the backing store. Basically, after the object is sent the first time the backing store kicks in and tracks whether any values have been changed, since the value for OdataID remains the same, the value is not parsed for the second request and we get a JSON value of {}. The behavior is partially explained here. In order to avoid this, as we see above is to create two reference objects, an alternative is to add the following between the two post requests:

    0 comments No comments