Spring Boot receive emoji rest

36 Views Asked by At

i have a angular client that send a emoji to Spring Boot Rest Client.

when I process the request I have dirty characters in the string field.

How i can get a emoji character?

This is the controller:

@UserAnnotation(value = UserType.A)
    @PutMapping("/modify")
    public ResponseEntity<ResponseController> modify(@Valid @RequestBody NovitaPojo novita) throws JsonProcessingException {
        service.edit(novita);
        return new ResponseEntity<>(ResponseController.buildOK(), HttpStatus.OK);
    }
3

There are 3 best solutions below

0
Aakash Sinha On

You can handle emoji with either by, update your application.yaml file as:

spring:
  http:
    encoding:
      charset: UTF-8
      enabled: true
      force: true

or by defining UTF-8 in controller as

HttpHeaders headers = new HttpHeaders();
headers.setContentType("application/json;charset=UTF-8");
0
Danilo Benda On

I have already try but nothing.

This in application:

spring.http.encoding.charset=UTF-8
spring.http.encoding.enabled=true
spring.http.encoding.force=true

and this in angular

headers: new HttpHeaders({ 'Content-Type': 'application/json; charset=utf-8' })
0
Danilo Benda On

Resolved!!

The problem was mysql.

alter table <some_table> convert to character set utf8mb4 collate utf8mb4_unicode_ci