JSON parse error: Cannot deserialize instance of java.lang.Long out of START ARRAY token

JSON parse error: Cannot deserialize instance of java.lang.Long out of START ARRAY token

我一直在研究这个问题,但找不到适合我的案例的解决方案...

我尝试发送一个 JSON 数组,但我收到了这个错误,我已经调查了这个问题,但我 100% 不理解这个问题,因此我不知道从哪里攻击它。

详细错误

{
  "type" : "https://www.jhipster.tech/problem/problem-with-message"

  "title" : "Bad Request",

  "status" : 400,

  "detail" : "JSON parse error: Cannot deserialize instance of `java.lang.Long` out of START_ARRAY token; 
nested exception is com.fasterxml.jackson.databind.exc.MismatchedInputException: Cannot deserialize instance of `java.lang.Long` out of START_ARRAY token\n at [Source: (PushbackInputStream); line: 1, column: 74] (through reference chain: com.curtipieles.app.service.dto.LeatherDTO[\"usageId\"])",
  "path" : "/api/leathers",
  "message" : "error.http.400"

}

PD:后端在 JHIPSTER

中生成

这是我的 DTO:

private Long usageId;
private Long colorId;
public Long getColorId() {
    return colorId;
}

public void setColorId(Long colorId) {
    this.colorId = colorId;
}

public String getColorName() {
    return colorName;
}

public void setColorName(String colorName) {
    this.colorName = colorName;
}


public Long getUsageId() {
    return usageId;
}

public void setUsageId(Long usageId) {
    this.usageId = usageId;
}

public String getUsageUsage() {
    return usageUsage;
}

public void setUsageUsage(String usageUsage) {
    this.usageUsage = usageUsage;
}

JSON array I am trying to send

您正在为 usageId 字段传递一个数字数组,而它被定义为 Long。您必须选择谁是正确的:JSON 有效负载(前端)或 java 代码(后端)。 colorId.

相同

如果前端是正确的,那么在java后端更改你的字段声明:

private List<Long> colorId;

如果后端正确,请更改您的前端代码,以便它发送此 JSON 有效负载:

"colorId": 1234,