I have a controller:
@PostMapping
public ResponseEntity<BookingDto> saveBooking(@RequestBody BookingDto dto) {
...
}
And my structure is like:
@Data
@NoArgsConstructor
@AllArgsConstructor
public class BookingDto {
private String id;
private String guestId;
private String officeId;
private OfficeType officeType;
private String advertId;
private String guestCount;
private String[] guestInvites;
private Map<String, String> testMap;
And I am sending request from postman like :
{
"guestId" : "0ee9f345-4c2d-45a5-ad30-08fbcf10bb20",
"officeId" : "917dasd8fc0-643e-11ed-81ce-0242ac120002",
"officeType" : "1",
"advertId" : "157fasd43a4-1de6-4fe9-8c7a-ac2164cec6bc",
"guestCount" : "4",
"testMap" : ["keyoo : 1", "keyaa : AG"]
}
as you see in pic:
But It cannot deserialize Map<String,String> object
. How can I send and use a Map<String, String> object
?
CodePudding user response:
Map is a simple JSON object with keys and values
{
"guestId" : "0ee9f345-4c2d-45a5-ad30-08fbcf10bb20",
"officeId" : "917dasd8fc0-643e-11ed-81ce-0242ac120002",
"officeType" : "1",
"advertId" : "157fasd43a4-1de6-4fe9-8c7a-ac2164cec6bc",
"guestCount" : "4",
"testMap" : {"keyoo" : "1", "keyaa" : "AG"}
}