Untitled

JSONSimple 사용방법

<aside> 💡 다른분들이 하신거 확인해보니 자동으로 JSON으로 Pasing해준다. 구지 JSONSimple을 사용할 필요가 없다 ㅎㅎ

</aside>

API명세

HTTP Method > GET HTTP Path > /api/v1/calc 쿼리 파라미터 > int num1, int num2 반환 타입 > JSON

코드

응답결과

Untitled

<aside> 💡 처음에는 JSONSimple 추가하고 Controller 단에서 값을 받아서 처리를 하였다. 다른 분들이 한 것을 한번 봤는데 아차 싶었다. 문제는 간단하였지만 생각 없이 Controller 단에서 처리를 한 것이었다. 단순히 답만 도출 한 것이었다. 염치없지만 다른 분들 거를 많이 참고하여 체계적인 설계에 대해 다시 생각해 보게 되었다.

</aside>


Untitled

API명세

HTTP Method > GET HTTP Path > /api/v1/day-of-the-week 쿼리 파라미터 > date=yyyy-dd-mm 반환 결과 > JSON "dayOfTheWeek" : "요일"

코드

오류

2024-02-20 11:01:26.054  WARN 14356 --- [nio-8080-exec-6] .w.s.m.s.DefaultHandlerExceptionResolver : Resolved [org.springframework.web.method.annotation.ModelAttributeMethodProcessor$1: org.springframework.validation.BeanPropertyBindingResult: 1 errors<EOL>Field error in object 'dayofTheWeekRequest' on field 'date': rejected value [2024-02-20]; codes [typeMismatch.dayofTheWeekRequest.date,typeMismatch.date,typeMismatch.java.time.LocalDate,typeMismatch]; arguments [org.springframework.context.support.DefaultMessageSourceResolvable: codes [dayofTheWeekRequest.date,date]; arguments []; default message [date]]; default message [Failed to convert value of type 'java.lang.String' to required type 'java.time.LocalDate'; nested exception is org.springframework.core.convert.ConversionFailedException: Failed to convert from type [java.lang.String] to type [java.time.LocalDate] for value '2024-02-20'; nested exception is java.lang.IllegalArgumentException: Parse attempt failed for value [2024-02-20]]]