users@jaxb.java.net

Re: Encoding Problem With Marshaller?

From: Kohsuke Kawaguchi <Kohsuke.Kawaguchi_at_Sun.COM>
Date: Wed, 20 Oct 2004 13:54:38 -0700

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