thrift-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Jens Geyer" <>
Subject Re: Thrift custom types
Date Sat, 07 Nov 2015 13:01:07 GMT

Seems that Java does not even allow for extension methods. Too bad:

-----Urspr√ľngliche Nachricht----- 
From: Jens Geyer
Sent: Saturday, November 7, 2015 1:56 PM
Subject: Re: Thrift custom types


For some languages Thrift generates partial classes, e.g. for C#. Those can
be easily extended, but not all languages (Embarcadero, I'm looking at you)
and not all language bindings support this, unfortunately.

Have fun,

-----Urspr√ľngliche Nachricht----- 
From: BCG
Sent: Saturday, November 7, 2015 3:01 AM
Subject: Re: Thrift custom types

On 11/6/2015 at 6:01 PM, "J" <> wrote:

>Say I want to add methods to the generated Java object such as
>"get10XData1()" that just returns 10x data1. Is there some way to
>do that
>or do I have to hack the thrift compiler and libraries?
>Similarly, say I want to have a custom type with custom
>serialization/deserialization. Is there any way to do that without

If you're using Java, easier than hacking the compiler and libraries would
be to use Facebook's Swift:

That allows you define your structs as annotated Java classes, and you can
add whatever utility methods you like.  Also you can define "builders" that
could be useful to customize serialization and deserialization.

If you want to be able to annotate interfaces and abstract classes instead
of just concrete classes, you might try my fork of that tool (I sent a pull
request to upstream for that feature but they don't seem interested):

If you don't want to use a tool like that and instead hack on the compiler -
for the utility methods you could probably have the Java generator recognize
an annotation that causes the generated struct to extend from some abstract
base class, or if you are on Java 8 it could be an interface with default
methods.  To do custom serialization would be trickier but not impossible I



View raw message