microsoftgraph / microsoftgraph/msgraph-beta-sdk-java
Entity.createFromDiscriminatorValue incorrectly deserializes #microsoft.graph.user as com.microsoft.graph.beta.models.security.User
还没有人认领这个 Issue。
- 主要语言
- Java
- 星标
- 32
- 派生
- 14
- 平均合并
- 1 天 3 小时
- 30 天内合并 PR
- 6
描述
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
贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
调研方向
从所引用行中的生成模型 models/Entity.java 判别器工厂开始,并将其 imports 和类型映射与 DirectoryObject::createFromDiscriminatorValue 进行比较。运行提供的 KiotaJsonSerialization 复现,然后为 #microsoft.graph.user 添加回归覆盖,并检查其他判别器映射是否存在相同的歧义。
由索引模型根据 Issue 内容生成。
评估
- 技术栈
- java
- 领域
- api
- Issue 类型
- 缺陷
- 难度
- 3/5
- 预计耗时
- 1-2 天
- 活跃度
- 停滞
- 描述清晰度
- 描述清楚
- 新手友好度
- 45/100