spring boot

JSON parse error: Cannot deserialize value of type `java.util.ArrayList<>` from Object value (token `JsonToken.START_OBJECT`);

원코드 2024. 7. 10. 11:51

에러 전문은 아래와 같다.

JSON parse error: Cannot deserialize value of type `java.util.ArrayList<com.example.demo.dto.MeetingSetting>` from Object value (token `JsonToken.START_OBJECT`); nested exception is com.fasterxml.jackson.databind.exc.MismatchedInputException: Cannot deserialize value of type `java.util.ArrayList<com.example.demo.dto.MeetingSetting>` from Object value (token `JsonToken.START_OBJECT`)<EOL> at [Source: (org.springframework.util.StreamUtils$NonClosingInputStream); line: 4, column: 15] (through reference chain: com.example.demo.dto.MeetingDto["settings"])]

전달되는 값("settings")는 object 타입인데 dto에 settings를 List로 선언해서 생긴 문제.

아래는 문제의 dto

@NoArgsConstructor
@Getter
@ToString
public class MeetingDto {

	private Long id;
	private String topic;
	private int type;
	private boolean default_password;
	private int duration;
	private String password;
	private List<MeetingSetting> settings;
	private Date start_time;
    
    //생략

 

그리고 전달받는 값의 예시. 보다시피 settings가 리스트로 오지는 않는다. email이 리스트로 오는데 작업하면서 햇갈린듯.

{
  "duration": 60,
  "password": "123456",
  "settings": {
    "audio": "telephony",
    "auto_recording": "cloud",
    "host_video": true,
    "mute_upon_entry": false,
    "meeting_invitees": [
      {
        "email": "jchil@example.com"
      }
    ],
    "participant_video": false,
    "waiting_room": false
  },
  "start_time": "2022-03-25T07:29:29Z",
  "timezone": "America/Los_Angeles",
  "topic": "My Meeting",
  "type": 2
}

 

settings의 타입을 List<MeetingSetting>에서 MeetingSetting로 수정하니 해결됨.

아래는 수정한 dto

@NoArgsConstructor
@Getter
@ToString
public class MeetingDto {

	private Long id;
	private String topic;
	private int type;
	private boolean default_password;
	private int duration;
	private String password;
	private MeetingSetting settings; //수정
	private Date start_time;
    
    //생략

 

참고 블로그 : 

https://gogo-jjm.tistory.com/6

 

JSON parse error : Cannot deserialize instance of 'java.util.ArrayList' out of START_OBJECT token

| MismatchedInputException: Cannot deserialize instance of 'java.util.ArrayList' out of START_OBJECT token curl 명령어를 날렸는데 Jackson MismatchedInputException 에러가 떨어졌다 converting 에러인 것 같아서 확인해보았다 넣으

gogo-jjm.tistory.com