[英]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]]
這是我用來發送數據的表格。
{ "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.