users@jaxb.java.net

Re: character encoding conversion for marshall/unmarshall?

From: Wolfgang Laun <wolfgang.laun_at_gmail.com>
Date: Thu, 15 Apr 2010 08:53:46 +0200

Your problem consists of two parts:
- how to convert a Java String between Java's standard encoding and
ISO-8859-1 (or some other -x)
- how to plug this conversion into JAXB's marshalling and unmarshalling.

I trust that you can manage the first part by referring to JDK Javadoc
java.nio.charset.Encoder and ...Decoder.

For the second, see the JAXB tutorial:
https://jaxb.dev.java.net/tutorial/section_5_6_1-Overriding-the-Datatype.html

You go from String to String, doing the encoding conversion by calling
encode and decode in the parseUTF2ISO and printISO2UTF methods your
CharsetConverter class has to implement. The bindings file has to be
included in the xjc call (option -b *pathname*).

If this isn't sufficiently clear, come back with your questions.
-W


On Wed, Apr 14, 2010 at 10:13 PM, gigi2 <ggtech888_at_gmail.com> wrote:

> Hello, JAXB gurus,
>
> I am wondering if there is an easy/plugin-able way to do character encoding
> conversion transparently in the process of marshall/unmarshall.
>
> Basically, my input/output will always be these UTF-8 XMLs. As the backend
> database is ISO encoded, I hope the result of unmarshall will give me ISO
> strings. And when it comes to marshall, the ISO strings can be transparently
> turned to UTF-8 XML response. Right now I'm using JAXB's annotations to
> parse XML into objects.
>
> I understand there will be chars in the input file not able to get
> converted, if so, I'd be be expecting an error/exception that flags the
> failure
>
> Hope I sound clear. This has been a headache for a while. Really hope
> someone may help out a bit. Thanks a million in advance
> ------------------------------
> View this message in context: character encoding conversion for
> marshall/unmarshall?<http://old.nabble.com/character-encoding-conversion-for-marshall-unmarshall--tp28247643p28247643.html>
> Sent from the java.net - jaxb users mailing list archive<http://old.nabble.com/java.net---jaxb-users-f13500.html>at Nabble.com.
>