I have no idea why you should write your own HTTP protocol code. This is very similar to writing your own XML parser: no matter how good you are as a programmer, you must make mistakes.
In any case, as indicated in the DataOutputStream documentation, executing writeBytes on a String will simply override its eight bits. So you get ... something, but not UTF8. What you need to do:
String jsonString = new Gson().toJson(objectToEncode); byte[] utf8JsonString = jsonString.getBytes("UTF8"); responseToClient.write(utf8JsonString, 0, utf8JsonString.Length);
Jan Doerrenhaus
source share