Affects: Spring Boot 2.1.13
i have tryed to send same body with: curl, postman and rest template with java.
with rest template chars not show correctly
private CompletableFuture<String> sendToFCM(String entity, String firebaseServerKey) {
RestTemplate restTemplate = new RestTemplate();
HttpHeaders headers = new HttpHeaders();
headers.setContentType(MediaType.APPLICATION_JSON);
headers.set("Authorization", "key=" + firebaseServerKey);
HttpEntity<String> request = new HttpEntity<>(entity, headers);
restTemplate.getMessageConverters().add(0, new StringHttpMessageConverter(StandardCharsets.UTF_8));
String firebaseResponse = restTemplate.postForObject(FIREBASE_API_URL, request, String.class);
return CompletableFuture.completedFuture(firebaseResponse);
}
I attach
curl -X POST --header "Authorization: key=KEY IS HIDDEN" --Header "Content-Type: application/json;charset=ISO-8859-1" https://fcm.googleapis.com/fcm/send -d '{"to":"/topics/VgtARwhilq","notification":{"body":"\uD83D\uDD25","content_available":true,"priority":"high","title":"\uD83D\uDD25"},"data":{"click_action":"FLUTTER_NOTIFICATION_CLICK","body":"\uD83D\uDD25","title":"\uD83D\uDD25","content_available":true,"priority":"high"}}'
curl or postman result is right
Can you help me?
Best Regards
Comment From: encircled
Hi,
I can't reproduce your issue, StringHttpMessageConverter is sending unicode chars correctly.
sendToFCM method accepts already marshalled JSON string (String entity), I would guess that encoding problem is there.
Comment From: sante85
How is your solution?
Il Sab 11 Apr 2020, 12:03 Vladislav Kisel notifications@github.com ha scritto:
Hi, I can't reproduce your issue, StringHttpMessageConverter is sending unicode chars correctly.
sendToFCM method accepts already marshalled JSON string (String entity), I would guess that encoding problem is there.
— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/spring-projects/spring-framework/issues/24895#issuecomment-612383474, or unsubscribe https://github.com/notifications/unsubscribe-auth/ADLHTN6NOULKZREZ6A7KND3RMA56ZANCNFSM4MFQP45Q .
Comment From: encircled
Let spring do json serialization by adding MappingJackson2HttpMessageConverter converter to the RestTemplate. And pass a real entity object (not stringified one) to the HttpEntity
Comment From: sante85
@encircled in this mode? RestTemplate restTemplate = new RestTemplate();
HttpHeaders headers = new HttpHeaders();
headers.setContentType(MediaType.APPLICATION_JSON);
headers.set("Authorization", "key=" + firebaseServerKey);
HttpEntity<String> request = new HttpEntity<>(entity, headers);
restTemplate.getMessageConverters().add(0, new MappingJackson2HttpMessageConverter());
String firebaseResponse = restTemplate.postForObject(FIREBASE_API_URL, request, String.class);
return CompletableFuture.completedFuture(firebaseResponse);
Comment From: rstoyanchev
Thanks for getting in touch, but it feels like this is a question that would be better suited to Stack Overflow. As mentioned in the guidelines for contributing, we prefer to use the issue tracker only for bugs and enhancements. Feel free to update this issue with a link to the re-posted question (so that other people can find it) or add some more details if you feel this is a genuine bug.