microsoftgraph / microsoftgraph/msgraph-beta-sdk-java

Entity.createFromDiscriminatorValue incorrectly deserializes #microsoft.graph.user as com.microsoft.graph.beta.models.security.User

未關閉
#1,264 0 則留言 0 個 reaction 已指派 0 人 在 GitHub 檢視

還沒有人認領這個 Issue。

type:bug
主要語言
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

貢獻指南

開啟貢獻指南

從這裡開始

  1. 先讀完整個 Issue,再讀專案的貢獻指南。
  2. 在 Issue 下留言說明你要接手 —— 這能避免兩個人做同樣的事。
  3. Fork 儲存庫,在一個分支上完成修改。
  4. 送出 Pull Request,並在描述裡引用這個 Issue 編號。

研究方向

從所引用行中的產生模型 models/Entity.java 判別器工廠開始,並將其 imports 和型別對應與 DirectoryObject::createFromDiscriminatorValue 進行比較。執行提供的 KiotaJsonSerialization 重現,接著為 #microsoft.graph.user 新增回歸涵蓋範圍,並檢查其他判別器對應是否存在相同的歧義。

由索引模型根據 Issue 內容生成。

評估

技術堆疊
java
領域
api
Issue 類型
缺陷
難度
3/5
預估耗時
1-2 天
活躍度
停滯
描述清晰度
描述清楚
新手友好度
45/100

把新 issue 寄到你的電子郵件信箱

精選適合新手參與的 GitHub issue 摘要。