History | Log In     View a printable version of the current page.  
Issue Details (XML | Word | Printable)

Key: XSTR-131
Type: Bug Bug
Status: Closed Closed
Resolution: Won't Fix
Assignee: Unassigned
Reporter: Daniel Frey
Votes: 0
Watchers: 0
Operations

If you were logged in you would be able to see more operations.
XStream

DomDriver UTF-8 not working

Created: 25/Sep/04 08:20 AM   Updated: 09/Nov/06 04:32 PM
Component/s: None
Affects Version/s: None
Fix Version/s: None

Issue Links:
Supercedes
 


 Description  « Hide
I am using XStream 1.0.2. The following two codes produce the same output:

--------------- Sample 1 --------------
final XStream x1 = new XStream(new DomDriver("UTF-8"));
x1.toXML(teststring, new FileWriter("test-encoding-1.xml"));

--------------- Sample 2 --------------
final XStream x2 = new XStream(new DomDriver());
x2.toXML(teststring, new FileWriter("test-encoding-2.xml"));

--------------- End Samples -----------

Given the teststring variable is "Ää Öö Üu", the output for both is identical:

00000000h: 3C 73 74 72 69 6E 67 3E ; <string>
00000008h: C4 E4 20 D6 F6 20 DC FC ; Ää Öö Üü
00000010h: 3C 2F 73 74 72 69 6E 67 ; </string
00000018h: 3E ; >

Obviously, the umlaut encoding does not take place in UTF-8, which (to my expectations) would look like this:

00000000h: 3C 73 74 72 69 6E 67 3E ; <string>
00000008h: C3 84 C3 A4 20 C3 96 C3 ; Ää Ã-Ã
00000010h: B6 20 C3 9C C3 BC 3C 2F ; ¶ Üü</
00000018h: 73 74 72 69 6E 67 3E ; string>

The encoding of the above code snippets rather take place in my Windows XPs default encoding schema ISO-8859-1.



 All   Comments   Change History      Sort Order: Ascending order - Click to sort in descending order
Matthias Wessendorf - 13/Jun/05 09:04 AM
I noticed the same behaivor and I am using xstream 1.1.2

Are there any updates on this issue ?

Regards,
Matthias


Matthias Wessendorf - 14/Jun/05 02:42 AM
Daniel, I fixed my issue by telling the reader (and writer also) to use UTF-8

<snip>
InputStream is = null;
InputStreamReader reader = null;
try { is = new BufferedInputStream(new FileInputStream(pathname)); reader = new InputStreamReader(is, "UTF-8"); } catch (FileNotFoundException e1) { e1.printStackTrace(); } catch (UnsupportedEncodingException uee) { uee.printStackTrace(); }

xstream.fromXML(reader);

</snip>

HTH,
Matthias


Joerg Schaible - 09/Nov/06 04:30 PM
As Matthias has pointed out, a JDK Writer will use a different encoding by default, but it should match the one of the driver. Write into a ByteArrayOutputStream to prevent further encoding.