簡體   English   中英

Spring 開機 JSON 解析錯誤:無法反序列化值

[英]Spring boot JSON parse error : Cannot deserialize value

我在提交表格時遇到問題。 在 RoominfoController 中,我進行了更改以使其接受 arrays,但問題仍然存在。


Cannot deserialize value of type `com.example.pgfinder.models.RoomInfo` from Array value (token `JsonToken.START_ARRAY`); nested exception is com.fasterxml.jackson.databind.exc.MismatchedInputException: Cannot deserialize value of type `com.example.pgfinder.models.RoomInfo` from Array value (token `JsonToken.START_ARRAY`)<EOL> at [Source: (org.springframework.util.StreamUtils$NonClosingInputStream); line: 1, column: 1]]

這是我用來發送數據的表格。

  1. RoomInfo.js 文件
  2. RoomInfoController.java
  3. Model Class:RoomInfo.java
  4. RoomInfoService.js (這里我指定了方法createRoomInfo)

我在這個網站上參考了一些類似的答案,但它對我不起作用。 嘗試輸入值時,錯誤仍顯示在 eclipse 控制台中。
我正在嘗試通過此表單發送 roominfos 數組。
 { "pg_name": "Devanshi Hostel", "pg_address": "Vastrapur behind Gurudwara", "phone_no": "9912343234", "notice_period": 21, "gender": "Girls", "country": "India", "state": "Gujarat", "city": "Dwarka", "deposit_amt": 5000, "food_avail": "Yes", "wifi_avail": "No", "request_status": "Pending", "roominfos": [ { "id": 1, "shared_no": 1, "no_of_rooms": 1, "total_capacity": 1, "vacancy": 1, "rent_per_month": 1000 }, { "id": 2, "shared_no": 3, "no_of_rooms": 1, "total_capacity": 3, "vacancy": 2, "rent_per_month": 1000 } ], "id": 18 }

謝謝你。

對我來說,將默認構造函數添加到 model class 解決了這個問題。 還有一件事 - 請使用 DTO 進行此類操作,使用實體不是一個好習慣。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM