Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use encoding for json as well #39

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open

Conversation

B3ret
Copy link

@B3ret B3ret commented May 12, 2020

I have to send UTF-8 strings via Json (e.g., for Umlauts) and need the encoding in the StringEntity!
(1) Maybe this also has to be applied to PutRequest
(2) Maybe the encoding should also be added to the header.

I have to send UTF-8 strings via Json (e.g., for Umlauts) and need the encoding in the StringEntity!
(1) Maybe this also has to be applied to PutRequest
(2) Maybe the encoding should also be added to the header.
@@ -71,7 +71,7 @@ public void addData(String key, String value)
public void addData(String json)
{
try{
stringEntity = new StringEntity(json);
stringEntity = new StringEntity(json, encoding);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this variable defined anywhere? Seems like it might be missing?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry for the late answer, I'm not much on github.
encoding is a class member variable and set in the constructor.
If one uses addData(String key, String value), then the added value will be encoded using this class member variable encoding during send() (in line 100). However, if one sets the json directly using addData(String json), the string will be added to the request without using encoding (line 117). In my own code, I therefore added the encoding directly when setting stringEntity. Otherwise, any UTF-8 characters (like umlauts) won't be sent correctly. Alternatively, you can apply the encoding in send() as well. Without this fix, the class advertises to use an encoding which is not actually used everywhere.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants