Notice
Recent Posts
Recent Comments
Link
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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 |
Tags
- String
- SpringBoot
- CloutNative
- 우분투에war배포
- Java
- MySQL
- SQL
- frontend
- restful api
- MySQL시작하기
- DB생성
- Lombok
- K8S
- intellij
- windows10
- 스프링에러
- NullPointerException
- wappalyzer
- Seek_Keyset
- MYSQL에러
- minikube
- offset
- VUE
- 이클립스
- gradle
- appleM1
- pagination
- springMVC
- Postman
- spring
Archives
- Today
- Total
미운 오리 새끼의 우아한 개발자되기
[Spring Boot] snake_case를 camelCase 로 바꾸기 본문
Spring & Spring Boot/Spring Boot
[Spring Boot] snake_case를 camelCase 로 바꾸기
Serina_Heo 2021. 7. 10. 22:57현재사이드프로젝트로 Spring Boot 프레임워크를 사용해서 Rest API를 구축하고 있다.
아래와 같이 ReqeustBody로 signInForm이라는 class로 통째로 받으려고 하는데
Body로 보내주는 json은 camelCase이고
signInForm은 snakeCase로 되어있어서 body를 보내줘도 mapping을 못해서 null로 들어오는 상황이 발생했다.
UserContoller.java
@ApiOperation(value = "sign in with Apple", notes = "Apple Id로 회원가입", produces = "application/json;charset=UTF8")
@ApiResponses(value = {
@ApiResponse(code = 200, message = "Success", response = User.class),
@ApiResponse(code = 401, message = "Unauthorized"),
@ApiResponse(code = 403, message = "Forbidden"),
@ApiResponse(code = 404, message = "Not Found"),
@ApiResponse(code = 500, message = "Failure")})
@PostMapping(value = "/users/apple", produces = "application/json;charset=UTF8", consumes="application/json;charset=UTF8")
public Map<String, Object> signInWithApple(
@RequestBody SignInForm signInForm){
User userIn = new User();
userIn.setAuthToken(signInForm.getAccessToken());
userIn.setEmail(signInForm.getEmail());
userIn.setName(signInForm.getName());
return userService.readAndCreateUser(userIn);
}
signInForm.java
package com.haiku.model;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
@Data
@AllArgsConstructor
@NoArgsConstructor
public class SignInForm {
String accessToken;
String email;
String name;
}
spring boot의 경우에는 application.properties에서
아래 한줄만 추가해주면 RequestBody를 snake_case로 보내도 camelCase로 선언된 변수로 mapping이 된다.
'Spring & Spring Boot > Spring Boot' 카테고리의 다른 글
[Spring Boot] Cloud Native Java - Test (1) 모의 기법 활용 (0) | 2022.09.27 |
---|---|
[Spring Boot] 스프링부트 설정 정보 우선순위 (0) | 2022.09.26 |
[Spring Boot] Test code 작성 @Mock vs. @MockBean (0) | 2022.08.03 |
[Spring Boot]스프링 부트 테스트 코드 어노테이션(Spring Boot Test Code Annotation) (0) | 2020.09.23 |
[Spring Boot]Pagination- Offset vs. Seek/Keyset (0) | 2020.09.16 |