thrift-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Samir Faci <sa...@esamir.com>
Subject Re: serializing thrift objects
Date Thu, 27 Mar 2014 00:43:52 GMT
Why don't you use the thrift based serialization that all TBase objects
already support?

I'm referencing thrift 0.6.1 since that's the version we're using, but
something along these lines should work.


TSerializer jsonSerializer = new TSerializer(new TJSONProtocol.Factory());
TDeserializer jsonDeserializer = new TDeserializer(new TJSONProtocol
.Factory());
String encoded = serializer.toString(tbase);  // tbase is an instance of
the thrift object.

naturally if you're using a binary format that you'll get a byte[] array
rather then a string.
//replace TJSONProtocol with any implementation of TProtocol. I think the
choices are JSON, Compact, Binary and maybe one more variation.

If you just want to serialize/deserialize the object, why not take
advantage of thrift existing encoding/decoding mechanism.

Just note, the encoding/decoding is not thread safe, so if you share the
serializer instance you'll have some issues.






On Wed, Mar 26, 2014 at 2:46 PM, Jens Geyer <jensgeyer@hotmail.com> wrote:

>
> The binary type should do.
>
>
> -----Urspr√ľngliche Nachricht----- From: Jules Cisek
> Sent: Wednesday, March 26, 2014 10:11 PM
> To: user@thrift.apache.org
> Subject: serializing thrift objects
>
>
> is there any clever way to control the serialVersionUID of thrift objects
> in Java?
>
> the output of the compiler doesn't specify a serialVersionUID and i end up
> with objects that when serialized in various ways are not compatible
> between builds, compilers, architecture, etc.
>
> in fact the compiler just tosses this into each class file:
> @SuppressWarnings("all")
>
> ouch...
>
> ~j
>
> --
> jules cisek | jules@luminate.com
>



-- 
Samir Faci
*insert title*
fortune | cowsay -f /usr/share/cows/tux.cow

Sent from my non-iphone laptop.

Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message