Is anyone knows why some of the currency symbols are not rendered properly in JSON response?

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

Is anyone knows why some of the currency symbols are not rendered properly in JSON response?

ankit8051
Hi,

In my application, some of the currency symbols are not properly rendered.

Currency symbols:: €, £, ¥ and ₩

Output:: "€", "£","¥" and "₩"

I have used a JSON serializer for rendering.

public class SpecialCharacterSerializer extends JsonSerializer<String> {

        @Override
        public void serialize(String value, JsonGenerator gen,
                        SerializerProvider serializers) throws IOException,
                        JsonProcessingException {
                gen.writeUTF8String(value.getBytes(), 0, value.length());
        }

}

This code is rendering symbols perfectly in windows machine but while on Linux machine will return with some extra character as mentioned above.

Reply | Threaded
Open this post in threaded view
|

Re: Is anyone knows why some of the currency symbols are not rendered properly in JSON response?

danhyun
I have a feeling your source files are encoded under Windows encoding (windows-1252).

Playing around between Windows and Linux I've found if I create file in Windows with €, it gets mangled in Linux.

If I set fileencoding=utf-8 in vi for the file it renders properly.

[email protected]:/tmp# file -bi test.txt
text/plain; charset=utf-8
[email protected]:/tmp# cat test.txt
€
[email protected]:/tmp# xxd test.txt
0000000: efbb bfe2 82ac 0a                        .......

If you're using an IDE like IntelliJ you can set default encoding to be UTF-8 for all files.
Reply | Threaded
Open this post in threaded view
|

Re: Is anyone knows why some of the currency symbols are not rendered properly in JSON response?

ankit8051
Actually, when I create a war file and deploy it on Linux server at that time currency symbols are not rendered properly.

On Windows machine all symbols are rendered properly.
Reply | Threaded
Open this post in threaded view
|

Re: Is anyone knows why some of the currency symbols are not rendered properly in JSON response?

danhyun
Even if you're generating the war on a Linux server, the source files are still encoded with however Windows created the file. You'll need to reencode source files in UTF-8.