microsoftgraph / microsoftgraph/msgraph-sdk-java
"Empty Payload. JSON content expected." when posting a comment with SDK v6
Dieses Issue hat noch niemand übernommen.
- Vorherrschende Sprache
- Java
- Sterne
- 444
- Forks
- 154
- Ø Merge
- 18 Std. 28 Min.
- Gemergte PRs (30 T.)
- 4
Beschreibung
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_
Beitragsleitfaden
Erste Schritte
- Lies das ganze Issue und danach den Beitragsleitfaden des Projekts.
- Schreib ins Issue, dass du es übernimmst — das erspart doppelte Arbeit.
- Forke das Repository und arbeite in einem Branch.
- Öffne einen Pull Request, der die Issue-Nummer nennt.
Rechercherichtung
Beginne bei security/alerts_v2 item comments CommentsRequestBuilder.post und verfolge mithilfe des Stacktraces und der Reproduktion von AlertComment die Serialisierung der Anfrage. Vergleiche den Body des SDK mit dem curl-Payload; abgeschlossen ist die Aufgabe, wenn das Posten eines einzelnen AlertComment ein JSON-Objekt statt eines Arrays mit einem Element sendet und den Kommentar erfolgreich erstellt.
Vom Indexierungsmodell aus dem Issue-Text verfasst.
Bewertung
- Tech-Stack
- java
- Bereich
- api
- Issue-Typ
- Bug
- Schwierigkeit
- 3/5
- Geschätzter Aufwand
- 1-2 Tage
- Aktivitätsstatus
- Veraltet
- Klarheit
- Größtenteils klar
- Anfängerfreundlichkeit
- 45/100