티스토리 뷰

com.fasterxml.jackson.databind.exc.MismatchedInputException: Cannot deserialize instance of `java.io.File` out of START_OBJECT token
 at [Source: (PushbackInputStream); line: 1, column: 1]
	at com.fasterxml.jackson.databind.exc.MismatchedInputException.from(MismatchedInputException.java:59) ~[jackson-databind-2.11.4.jar:2.11.4]
	at com.fasterxml.jackson.databind.DeserializationContext.reportInputMismatch(DeserializationContext.java:1468) ~[jackson-databind-2.11.4.jar:2.11.4]
	at com.fasterxml.jackson.databind.DeserializationContext.handleUnexpectedToken(DeserializationContext.java:1242) ~[jackson-databind-2.11.4.jar:2.11.4]
	at com.fasterxml.jackson.databind.DeserializationContext.handleUnexpectedToken(DeserializationContext.java:1148) ~[jackson-databind-2.11.4.jar:2.11.4]
	at com.fasterxml.jackson.databind.deser.std.FromStringDeserializer.deserialize(FromStringDeserializer.java:177) ~[jackson-databind-2.11.4.jar:2.11.4]
	at com.fasterxml.jackson.databind.ObjectMapper._readMapAndClose(ObjectMapper.java:4526) ~[jackson-databind-2.11.4.jar:2.11.4]
	at com.fasterxml.jackson.databind.ObjectMapper.readValue(ObjectMapper.java:3521) ~[jackson-databind-2.11.4.jar:2.11.4]

RestTemplate을 활용해서 parameter와 함께 요청을 보낼 때 위와 같은 오류가 발생하였다. 

ResponseEntity<File> response = restTemplate.postForEntity("http://localhost:8080/sendMessage",
    requestEntity, File.class);

이것은 수정 전 ResponseEntity를 정의한 모습이다. 여기서 <File> 이라고 정의한 부분에 문제가 있는것이다. 

 

requestEntity를 정의할때 <String, Object> 로 정의를 했는데 File을 넘겨서 문제가 생긴 것이다. 

 

ResponseEntity<String> response = restTemplate.postForEntity("http://localhost:8080/sendMessage",
    requestEntity, String.class);

위와 같이 ResponseEntity를 String으로 정의해주면 문제는 해결된다. 

 

끝!

댓글
최근에 올라온 글
최근에 달린 댓글
«   2024/05   »
1 2 3 4
5 6 7 8 9 10 11
12 13 14 15 16 17 18
19 20 21 22 23 24 25
26 27 28 29 30 31