In above image its rending data from thirdparty api calls by name . in place of "-" its coming.
but from api i can see value
Solved! Go to Solution.
Views
Replies
Total Likes
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.
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.
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; }
hi @Aditya_Chabuku ,
Thanks for the reply,
after trying that above method spaces and also decoder no change previous still same thing coming .
@keshava219 What is your content type? is it "application/x-www-form-urlencoded"?
@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
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.