Character encoding problem.

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

Character encoding problem.

Samuel Abreu de Paula
Hi guys, i wrote a program to serialize some objects with XStream, but i
have a little problem with different OS.
If i create the file in Windows XP, and try to get in a Linux system
doesn't work:
    ERROR: could not convert UTF-8 character 0x00ef to ISO8859-1
In bash, if i try:
iconv -f UTF-8 file.xml
it returns: iconv: illegal input sequence at position 173
but if i try:
iconv -f ISO-8859-1 file.xml it returns ok.

So i have tried put a header in xml like:
<?xml version="1.0" encoding="ISO-8859-1"?>
But doesn't affect XStream, cos the error is the same
I tried with different encoding
<?xml version="1.0" encoding="LATIN1"?>
<?xml version="1.0" encoding="UTF-8"?>
But always the same result.

So i ask, how can i use XStream to serialize objects that can be read by
any other OS!

Thanks.
Reply | Threaded
Open this post in threaded view
|

Re: Character encoding problem.

Justin T. Sampson-2
If you use the XStream.toXML(Object,Writer) method, you can set
the character encoding to whatever you want:

OutputStream outputStream = new FileOutputStream("file.xml");
Writer writer = new OutputStreamWriter(outputStream, "UTF-8");
xstream.toXML(object, writer);
writer.close();

Cheers,
Justin


Samuel Abreu de Paula wrote:

> Hi guys, i wrote a program to serialize some objects with
> XStream, but i have a little problem with different OS.
>
> If i create the file in Windows XP, and try to get in a Linux
> system doesn't work:
>
>     ERROR: could not convert UTF-8 character 0x00ef to ISO8859-1
>
> In bash, if i try:
>
> iconv -f UTF-8 file.xml
>
> it returns: iconv: illegal input sequence at position 173
>
> but if i try:
>
> iconv -f ISO-8859-1 file.xml it returns ok.
>
> So i have tried put a header in xml like:
>
> <?xml version="1.0" encoding="ISO-8859-1"?>
>
> But doesn't affect XStream, cos the error is the same
>
> I tried with different encoding
>
> <?xml version="1.0" encoding="LATIN1"?>
> <?xml version="1.0" encoding="UTF-8"?>
>
> But always the same result.
>
> So i ask, how can i use XStream to serialize objects that can be
> read by any other OS!
>
> Thanks.