tags:

views:

54

answers:

1

How can I marshal java string object that contain umlauts by using org.springframework.oxm.jaxb.Jaxb2Marshaller ? I have java string like Alizée. After marshalling with using Jaxb2Marshaller i get Alizée xml string.

+3  A: 

This can be right, but you are vieving the marshalled XML with the wrong charset (you view UTF-8 as ISO-8859-1/extended ASCII).

I would double-check character encodings and that you are viewing the marshalled XML with the correct encoding.

Example: é is in UTF-8 represented by two bytes: 0xC3 0xA9 http://www.fileformat.info/info/unicode/char/00e9/index.htm

These two bytes, represented in for example ISO-8859-1 will read:

If you create a text file containing é and save it as UTF-8. Re-open the file but choose encoding ISO-8859-1 and you will see the same.

belgarat
what you mean "double-check character encodings"?
Roman
If JAXB2 generates XML with UTF-8-enocded characters, you should make sure it is not viewed/treated as data with another encoding. That means that your terminal encoding should be UTF-8 (if you print the XML out to your terminal). The one who receive/parse the XML should also treat it as UTF-8. I suspect that if you make JAXB2 unmarshal the very same XML, everything will be Ok.
belgarat
:) no i do not view my xml in terminal. i view xml into browser with utf-8. I need to mask each of umlauts into xx; format before rendering/marshalling. This WORKS!
Roman
response.setCharacterEncoding("UTF-8"); - fixed my problem without any masking!
Roman