users@jaxb.java.net

RE: Re: Encoding Problem With Marshaller?

From: Jason Weis <jweis_at_apelon.com>
Date: Thu, 21 Oct 2004 07:52:02 -0400

Thanks. Using the Reader worked. Also, I was using com.sun.xml.bind.StringInputStream.

-----Original Message-----
From: Kohsuke Kawaguchi [mailto:Kohsuke.Kawaguchi_at_Sun.COM]
Sent: Wednesday, October 20, 2004 4:55 PM
To: users_at_jaxb.dev.java.net
Subject: Re: Encoding Problem With Marshaller?

Jason Weis wrote:
> I am trying to marshall and unmarshall the Ó character which appears to have the
> hex value F3. The following code fragment throws an exception (listed below)
> after the second attempt to Unmarshall. To be clear, the first unmarshall works,
> but after calling marshall and writing to a String, unmarshalling that same
> string fails. Am I doing wrong or is something broken?

The following line looks wrong to me:

        Object o = un.unmarshal(new StringInputStream(s));

I'm not sure what "StringInputStream" you are using. If you are using
com.sun.xml.bind.StringInputStream, then you shouldn't be using an RI
internal implementation class.

In any case, you are parsing String into InputStream, and therefore you
are losing the encoding information right there, and unless you do that
conversion correctly, you'll get an error like this.

If you have a String, char[] or any input that has encoding information,
wrap that into Reader like this:

        new StringReader(s);

This should make it work.

-- 
Kohsuke Kawaguchi
Sun Microsystems                   kohsuke.kawaguchi_at_sun.com
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe_at_jaxb.dev.java.net
For additional commands, e-mail: users-help_at_jaxb.dev.java.net
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe_at_jaxb.dev.java.net
For additional commands, e-mail: users-help_at_jaxb.dev.java.net