I have a Spring Boot with REST API:
@Operation(summary = "Update your user")
@PatchMapping(consumes = {MediaType.APPLICATION_JSON_VALUE})
@PreAuthorize("hasAuthority('MANAGE_MY_ACCOUNT')")
@ApiResponse(responseCode = "204", description = "Successfully updated user")
@ApiResponse(responseCode = "400", description = "Cannot update user",
content = @Content(schema = @Schema(implementation = ApiErrorResponse.class)))
@ApiResponse(responseCode = "404", description = "Unknown User Id",
content = @Content(schema = @Schema(implementation = ApiErrorResponse.class)))
ResponseEntity<Void> updateUser(@RequestBody UpdateUserRequest request);
Which accepts UpdateUserRequest as a POJO in the request body.
@Getter
@NoArgsConstructor
public class UpdateUserRequest {
@Length(max = 100)
private String name;
@Length(max = 100)
private String givenName;
@Length(max = 100)
private String familyName;
}
When I invoke the API with following request:
{
"name": "Rafał Laskowski",
"givenName": "Rafał",
"familyName": "Laskowski"
}
The name and givenName are not encoded properly. What I get is RafaÅ. When debugging the @RestController i noticed that these names are incorrectly transformed into a byte array which looks like this:
What I have tried so far:
- Set the
consumesargument of@PatchMappingtoMediaType.APPLICATION_JSON_VALUE - The above as a string adding
;charset=UTF-8 - Setting JVM -Dfile.encoding=UTF-8
- Setting -Dsun.jnu.encoding=UTF-8
- Setting
sping.mandatory-file-encoding: UTF-8in application.yml - Setting
server.servlet.encoding.charset: UTF-8in application.yml log.info(System.getProperty("file.encoding"));returned UTF-8
I thought it might be the Jackson's Object Mapper configuration but I read it's not the case as JSON only accepts UTF-x encodings.
I have no idea why the character ł is not properly read from the request.
