0

I am having probles with sending messages including special characters (such as 'łżźć') to FCM. When I send them through developer console - mobile apps display them correctly. But when I send them from our server they are replaced by '?????'.

I have below how I send the message itself to FCM server:

@Async
CompletableFuture<String> send(HttpEntity<String> entity, String accessToken) throws HttpClientErrorException {
    RestTemplate restTemplate = new RestTemplate();

    ArrayList<ClientHttpRequestInterceptor> interceptors = new ArrayList<>();
    interceptors.add(new HeaderRequestInterceptor("Authorization", "Bearer " + accessToken));
    interceptors.add(new HeaderRequestInterceptor("Content-Type", "application/json;charset=UTF-8"));
    restTemplate.setInterceptors(interceptors);

    String firebaseResponse = restTemplate.postForObject(FCM_API, entity, String.class);
    return CompletableFuture.completedFuture(firebaseResponse);
}

I'd like to aviod converting message to e.g. base64 string if possible (this was one of the replies in other questions).

Jakub Wisniewski
  • 2,189
  • 4
  • 20
  • 34
  • 1
    Have you tried adding a UTF-8 String message converter as per [this question](https://stackoverflow.com/questions/29392422/how-can-i-tell-resttemplate-to-post-with-utf-8-encoding)? – Karol Dowbecki Mar 21 '19 at 13:51
  • @KarolDowbecki .... I feel so stupid right now - that's perfect answer! Did not think about that (I was tring with encoding the string itself to no result) – Jakub Wisniewski Mar 21 '19 at 13:57
  • 1
    Don't encode payloads when working with Spring libraries, that's a job for `ConversionService` – Karol Dowbecki Mar 21 '19 at 14:02

0 Answers0