microsoftgraph / microsoftgraph/msgraph-sdk-java
"Empty Payload. JSON content expected." when posting a comment with SDK v6
還沒有人認領這個 Issue。
- 主要語言
- Java
- 星號
- 444
- 分支
- 154
- 平均合併
- 18 小時 28 分鐘
- 30 天內合併 PR
- 4
描述
Describe the bug
"Empty Payload. JSON content expected." error is thrown when trying to add a comment on an Alert v2.
com.microsoft.graph.models.odataerrors.ODataError: Empty Payload. JSON content expected.
at com.microsoft.graph.models.odataerrors.ODataError.createFromDiscriminatorValue(ODataError.java:36)
at com.microsoft.kiota.serialization.JsonParseNode.getObjectValue(JsonParseNode.java:212)
at com.microsoft.kiota.http.OkHttpRequestAdapter.lambda$throwIfFailedResponse$0(OkHttpRequestAdapter.java:674)
at com.microsoft.kiota.ApiExceptionBuilder.<init>(ApiExceptionBuilder.java:26)
at com.microsoft.kiota.http.OkHttpRequestAdapter.throwIfFailedResponse(OkHttpRequestAdapter.java:673)
at com.microsoft.kiota.http.OkHttpRequestAdapter.sendCollection(OkHttpRequestAdapter.java:200)
at com.microsoft.graph.security.alerts_v2.item.comments.CommentsRequestBuilder.post(CommentsRequestBuilder.java:72)
at com.microsoft.graph.security.alerts_v2.item.comments.CommentsRequestBuilder.post(CommentsRequestBuilder.java:56)
HTTP response status code is 400 "bad request".
Expected behavior
A comment is created on the alert, without any error.
For instance, posting the same request with Curl works perfectly:
curl -X POST \
-H "Authorization: Bearer YOUR_ACCESS_TOKEN" \
-H "Content-Type: application/json" \
-d '{
"@odata.type": "microsoft.graph.security.alertComment",
"comment": "Your comment here"
}' \
"https://graph.microsoft.com/v1.0/security/alerts_v2/{alertId}/comments"
How to reproduce
I followed the instructions from the documentation (https://learn.microsoft.com/en-us/graph/api/security-alert-post-comments?view=graph-rest-1.0&tabs=java):
GraphServiceClient graphClient = new GraphServiceClient(requestAdapter);
com.microsoft.graph.models.security.AlertComment alertComment = new com.microsoft.graph.models.security.AlertComment();
alertComment.setOdataType("microsoft.graph.security.alertComment");
alertComment.setComment("Demo for docs");
var result = graphClient.security().alertsV2().byAlertId("{alert-id}").comments().post(alertComment);
but converted that code into Kotlin.
The post() method, contrary to the documentation need a list of comments as input instead of a single comment.
val comment = AlertComment()
comment.odataType = "microsoft.graph.security.alertComment"
comment.comment = "my comment"
graphClient.security().alertsV2().byAlertId(alertId).comments().post(listOf(comment))
Debugging the request, I can see that the payload send by the SDK is [{"comment":"my comment","@odata.type":"microsoft.graph.security.alertComment"}] instead of {"comment":"my comment","@odata.type":"microsoft.graph.security.alertComment"} as it should be.
SDK Version
6.13.0
Latest version known to work for scenario above?
unknown
Known Workarounds
No response
Debug output
Click to expand log
```</details>
### Configuration
_No response_
### Other information
_No response_
貢獻指南
從這裡開始
- 先讀完整個 Issue,再讀專案的貢獻指南。
- 在 Issue 下留言說明你要接手 —— 這能避免兩個人做同樣的事。
- Fork 儲存庫,在一個分支上完成修改。
- 送出 Pull Request,並在描述裡引用這個 Issue 編號。
研究方向
從 security/alerts_v2 item comments CommentsRequestBuilder.post 開始,使用堆疊追蹤和 AlertComment 的重現步驟追蹤請求序列化。比較 SDK body 與 curl payload;完成的標準是張貼一個 AlertComment 時傳送 JSON 物件,而不是包含一個元素的陣列,並成功建立留言。
由索引模型根據 Issue 內容生成。
評估
- 技術堆疊
- java
- 領域
- api
- Issue 類型
- 缺陷
- 難度
- 3/5
- 預估耗時
- 1-2 天
- 活躍度
- 停滯
- 描述清晰度
- 基本清楚
- 新手友好度
- 45/100