microsoftgraph / microsoftgraph/msgraph-beta-sdk-java
Entity.createFromDiscriminatorValue incorrectly deserializes #microsoft.graph.user as com.microsoft.graph.beta.models.security.User
Nobody has claimed this yet.
- Dominant language
- Java
- Stars
- 32
- Forks
- 14
- Avg merge
- 1d 3h
- Merged PRs (30d)
- 6
Description
Describe the bug
In current beta version, when trying to deserialize a #microsoft.graph.user from JSON using KiotaJsonSerialization.deserialize(json, Entity::createFromDiscriminatorValue), it's returned as a com.microsoft.graph.beta.models.security.User instance.
This is because only one of com.microsoft.graph.beta.models.User and com.microsoft.graph.beta.models.security.User is imported the latter), and classes are referenced without fully qualified name.
See https://github.com/microsoftgraph/msgraph-beta-sdk-java/blob/3612a3a8958cc35b0be7626b966008ea99a031af/src/main/java/com/microsoft/graph/beta/generated/models/Entity.java#L2075 and https://github.com/microsoftgraph/msgraph-beta-sdk-java/blob/3612a3a8958cc35b0be7626b966008ea99a031af/src/main/java/com/microsoft/graph/beta/generated/models/Entity.java#L2326
There are probably other cases like this one.
Expected behavior
KiotaJsonSerialization.deserialize(json, Entity::createFromDiscriminatorValue) should return a com.microsoft.graph.beta.models.User instance for #microsoft.graph.user objects.
How to reproduce
This test
//passes
assertEquals(com.microsoft.graph.beta.models.User.class, KiotaJsonSerialization.deserialize("""
{
"@odata.type": "#microsoft.graph.user"
}
""", DirectoryObject::createFromDiscriminatorValue).getClass());
//KO
assertEquals(com.microsoft.graph.beta.models.User.class, KiotaJsonSerialization.deserialize("""
{
"@odata.type": "#microsoft.graph.user"
}
""", Entity::createFromDiscriminatorValue).getClass());
will fail with
org.opentest4j.AssertionFailedError:
Expected :class com.microsoft.graph.beta.models.User
Actual :class com.microsoft.graph.beta.models.security.User
SDK Version
6.51.0
Latest version known to work for scenario above?
No response
Known Workarounds
Pass a more precise ParsableFactory, like DirectoryObject::createFromDiscriminatorValue, like in the reproduction test.
Debug output
Configuration
No response
Other information
I found an old bug in Kiota that might be related (it was marked as fixed though): https://github.com/microsoft/kiota/issues/1801
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the generated models/Entity.java discriminator factory at the referenced lines and compare its imports and type mappings with DirectoryObject::createFromDiscriminatorValue. Run the provided KiotaJsonSerialization reproduction, then add regression coverage for #microsoft.graph.user and check whether other discriminator mappings have the same ambiguity.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- java
- Domain
- api
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 45/100