This week's book giveaway is in the OCAJP 8 forum. We're giving away four copies of OCA Java SE 8 Programmer I Study Guide and have Edward Finegan & Robert Liguori on-line! See this thread for details.
Streams do not have an encoding - they're simply a sequence of bytes. The XMLSerializer object had better be smart enough to discover the encoding of the XML in the stream (XML has a mechanism for specifying the encoding).
I think the problem is more likely to originate while displaying those characters - how and where are you doing that?
toJson the method returns an object of type JSONObject.
When the xml that is returned by the server has an encoding ISO.8859-1, the client does not correctly display accented letters and special characters.
Otherwise, if the XML encoding UTF-8, everything goes well.
Joined: Mar 22, 2005
From the code snippets you posted it's not clear where the problem could arise. For example, what is the XMLSerializer class? It's not the Xerces class, as that has no readFromStream method. And how does the "json" object become a "baos" object? That process must involve specifying an encoding.
Is the client capable of displaying ISO-8859-1 correctly? How are you telling the client that ISO-8859-1 is being used?