Facing special characters on datasource node rendering in place of "-" | Community
Skip to main content
keshava219
Level 3
Jul 8, 2022 4:42 PM UTC
Solved

Facing special characters on datasource node rendering in place of "-"

 

 

In above image its rending data from thirdparty api calls by name . in place of   "-"  its coming. 

 

but from api i can see value 

"Welcome to Progress – Image Film".
 

 

 

This post is no longer active and is closed to new replies. Need help? Start a new post to ask your question.
BrianKasingli
BrianKasingliAccepted solution
New Participant
Jul 11, 2022 2:27 AM UTC

Making sure you are encoding your strings as UTF-8 in Java should solve the trick. 

 

Encoding With Commons-Codec

 

<dependency>
    <groupId>commons-codec</groupId>
    <artifactId>commons-codec</artifactId>
    <version>1.14</version>
</dependency>

String rawString = "Welcome to Progress - Image Film"; 
byte[] bytes = StringUtils.getBytesUtf8(rawString);
 
String utf8EncodedString = StringUtils.newStringUtf8(bytes);


What is UTF-8?

 

UTF-8 is a variable-width character encoding used for electronic communication. Defined by the Unicode Standard, the name is derived from Unicode Transformation Format – 8-bit. UTF-8 is capable of encoding all 1,112,064 valid character code points in Unicode using one to four one-byte code units.

7 replies

BrianKasingli
BrianKasingliAccepted solution
New Participant
Jul 11, 2022 2:27 AM UTC

Making sure you are encoding your strings as UTF-8 in Java should solve the trick. 

 

Encoding With Commons-Codec

 

<dependency>
    <groupId>commons-codec</groupId>
    <artifactId>commons-codec</artifactId>
    <version>1.14</version>
</dependency>

String rawString = "Welcome to Progress - Image Film"; 
byte[] bytes = StringUtils.getBytesUtf8(rawString);
 
String utf8EncodedString = StringUtils.newStringUtf8(bytes);


What is UTF-8?

 

UTF-8 is a variable-width character encoding used for electronic communication. Defined by the Unicode Standard, the name is derived from Unicode Transformation Format – 8-bit. UTF-8 is capable of encoding all 1,112,064 valid character code points in Unicode using one to four one-byte code units.

Translate
ShaileshBassi
New Participant
Jul 8, 2022 7:17 PM UTC

@keshava219 Please try out with the below properties in the servlet, while making the request to the api to return the response.

    HttpURLConnection con = (HttpURLConnection) obj.openConnection();
    con.setRequestMethod("GET");
    con.setRequestProperty("accept-charset", "UTF-8");
    con.setRequestProperty("content-type", "application/x-www-form-urlencoded; charset=utf-8");

 Hope this helps!

Thanks

Translate
Manu_Mathew_
New Participant
Jul 8, 2022 6:26 PM UTC

@keshava219  What is your content type? is it "application/x-www-form-urlencoded"?

Translate
Aditya_Chabuku
New Participant
Jul 8, 2022 5:01 PM UTC

Hi @keshava219 , This is because of characters encoding/decoding in a API response( as a matter of. fact, any string-based response).

I saw your response is coming from BufferedReader, so now convert BR to String & then pass into below method to get properly decoded values.

please use following code after you receive response & pass each string here to get proper values.

~Aditya.Ch

import java.net.*;
private String allowSplChars(String incomingString) {
        String encodedValue = null;
        try {
        encodedValue= URLEncoder.encode(incomingString.trim(), "UTF-8");
        } catch (UnsupportedEncodingException uee) { 
        	log.error("UnsupportedEncodingException", uee);

        }
         return encodedValue;
	}

 

Translate
Thanks,Aditya Chabuku
keshava219
Level 3
Jul 8, 2022 5:23 PM UTC

hi @aditya_chabuku ,

 

 Thanks for the reply, 

 

 

after trying that above method  spaces and also decoder no change previous still same thing coming .

Translate
milind_bachani
Employee
Jul 8, 2022 4:46 PM UTC

Hi @keshava219 ,

 

Is character encoding enabled for the third party api response ?

Thanks,

Milind

Translate
keshava219
Level 3
Jul 8, 2022 5:03 PM UTC

Hi @milind_bachani ,

 

                              Im not using response to get api details , Directly from getInputStream

here is the snippet im using :

conn.setRequestProperty("Content-Type", "application/json");
conn.setRequestMethod(ABBConstants.GET_REQUEST);

BufferedReader in = new BufferedReader(new InputStreamReader(conn.getInputStream()));

getting output of json ,

im passing to datasource.

Translate