3 pièce(s) jointe(s)
Encoding: Changement des caractères entre le controller et ce qui est dans le JSON
Bonjour,
J'ai un problème qui me fait tourner en bourrique, sur lequel j'ai essayé pleins de chose et à chaque fois, c'est l'échec critique.
Je pense que la question a été posée à de maintes reprises, mais là, ça fait 1,5 jours que je suis sur ce problème.
Je cherche une solution simple et viable.
J'ai un projet Spring Boot (en l'occurence celui-ci: https://www.developpez.net/forums/d2...spring-2023-a/ ).
Il a un client en Vue JS.
Je package le tout dans un war car je suis contraint par un existant.
J'ai un problème d'encoding.
J'ai une DTO:
Code:
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 29 30 31 32
|
package fr.cisirh.explorateur.dto;
public class DomaineDTO {
private Long id;
private String label;
public Long getId() {
return id;
}
public void setId(Long id) {
this.id = id;
}
public String getLabel() {
return label;
}
public void setLabel(String label) {
this.label = label;
}
@Override
public String toString() {
return "DomaineDTO [id=" + id + ", label=" + label + "]";
}
} |
Cette DTO est listé grâce au service REST suivant:
Code:
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 29 30 31 32 33 34 35 36 37 38 39 40 41 42
|
package fr.cisirh.explorateur.controller;
import java.util.List;
import java.util.stream.Collectors;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.http.HttpStatus;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import fr.cisirh.explorateur.anotations.InjectUser;
import fr.cisirh.explorateur.dto.DomaineDTO;
import fr.cisirh.explorateur.dto.UserDTO;
import fr.cisirh.explorateur.service.DomaineService;
@RestController
@RequestMapping("/domaine")
public class DomaineController {
private static final Logger LOG = LoggerFactory.getLogger(DomaineController.class);
private final DomaineService domaineService;
public DomaineController(DomaineService domaineService) {
this.domaineService = domaineService;
}
@GetMapping(produces = MediaType.APPLICATION_JSON_VALUE)
public ResponseEntity<List<DomaineDTO>> getDomaines(@InjectUser UserDTO user){
if(user == null) {
return ResponseEntity.status(HttpStatus.UNAUTHORIZED).build();
}
List<DomaineDTO> toto = domaineService.getDomainesByRoles(user.getRoles().stream().map(r -> r.getRolMod()).collect(Collectors.toList()));
LOG.info("MIAOU = "+toto.toString());
return ResponseEntity.ok(domaineService.getDomainesByRoles(user.getRoles().stream().map(r -> r.getRolMod()).collect(Collectors.toList())));
}
} |
Mon problème est en "pré-prod" (le contexte où je travail est un peu particulier).
Une des ligne dans la base de données (ici Oracle) a un "é".
Côté log dans le service REST:
Pièce jointe 636627
Mais dans le dialog, j'ai un affichage détestatble.
Pièce jointe 636628
En accord avec le JSON envoyé.
Pièce jointe 636629
Cordialement.