thrift-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Simon Falsig <si...@newtec.dk>
Subject Thrift C++ library generating locale-specific JSON
Date Tue, 02 Dec 2014 09:47:03 GMT
Hi,

I'm using Thrift for serializing objects (in C++) into JSON strings, which
I then store as files. This usually works fine, but I just discovered that
if the locale of my system is set to a locale where the decimal separator
is ',' instead of '.' (for instance in Denmark), then the TJSONProtocol
(specifically the writeJSONDouble function that does the double to string
conversion through a boost::lexical_cast) will also use this separator
when serializing doubles. This kinda plays havoc with the JSON
specification, which does not allow for localized formatting, and depends
on always using '.' as a decimal separator. I could imagine that there may
be other more subtle places where the local can have an effect, but this
is currently the only place I've been having trouble with.

I can see that the same problem has been fixed for C# (commit
3da317bda100130b2f615034c46b0944888f0f14 / THRIFT-1245 C# JSON Protocol
uses culture-dependant decimal separator for double) but it doesn't seem
as if there's a similarly easy way to fix boost::lexical_cast...
In any case, I'm not too strong with respect to all this locale stuff, so
if anyone has a quick way to fix this, I'd be very interested.

Note that I'm using Thrift 0.9.0, but as far as I can see there hasn't
been any relevant changes to TJSONProtocol.cpp since that.

Thanks in advance,
 - Simon

Mime
View raw message