Afrozaar / wp-api-v2-client-java

WP-API v2 Java Client
Apache License 2.0
84 stars 53 forks source link

UTF8 characters - Latin Diacritics are not rendering properly #63

Open nithyasharabheshwara opened 3 years ago

nithyasharabheshwara commented 3 years ago

Hi,

I checked the output of the REST API call from the browser, it is showing Latin Diacritics properly, however, the string returned from com.afrozaar.wordpress.wpapi.v2.model.Post.getContent().getRendered() contains an invalid string with the special characters appearing as ?. It should be an easy fix for the author, I believe somewhere the conversion is not happening properly. I will try to fix it and submit a PR but please do check.

Update I was able to fix this. You need to slightly edit the file

com.afrozaar.wordpress.wpapi.v2.Client.java:127 Before

        restTemplate = new RestTemplate(messageConverters);

After

import java.nio.charset.StandardCharsets;
....
        restTemplate = new RestTemplate(messageConverters);
        restTemplate.getMessageConverters()
            .add(0, new StringHttpMessageConverter(StandardCharsets.UTF_8));

It is a very simple change, I have never submitted a PR actually, may be the authors can fix this on their own. If a PR is required let me know, I will submit one. For now, this solves my problem.

Thanks

nithyasharabheshwara commented 2 years ago

@michaelwiles @clintonbosch