I use snake_case DB columns and camelCase DTO.
And our team want to use snake_case when we code React component.
Because of it, I added @JsonNaming on DTO. But it works when I send Json data, as you know.
Is there any annotation or setting similar to @JsonNaming?
Here is my postman data and sample codes.
Debug data: sampleName=name, sampleDesc=null.
// Controller
@RestController
@RequestMapping("/sample")
public class SampleController {
@Autowired
private SampleService sampleService;
@GetMapping
public Result getSampleList(SampleDTO param) throws Exception {
return sampleService.getFolderList(param);
}
@PostMapping
public Result insertSample(@RequestBody SampleDTO param) throws Exception {
// this method works well with @JsonNaming
return sampleService.insertFolder(param);
}
}
// DTO
@Setter
@Getter
@NoArgsConstructor
@JsonNaming(PropertyNamingStrategies.SnakeCaseStrategy.class)
@Alias("SampleDTO")
public class SampleDTO {
@NotNull
private Long sampleNo;
@NotBlank
private String sampleName;
private String sampleDesc;
@Builder
public SampleDTO(Long sampleNo, String sampleName, String sampleDesc) {
this.sampleNo = sampleNo;
this.sampleName = sampleName;
this.sampleDesc = sampleDesc;
}
}