1

there is a way to generate thrift description file for existing java classes using refletion? Avro has that feature, but i need to use thrift and i have a lot of existing business class in java that i need to serialize in c++ and java.

BenMorel
  • 34,448
  • 50
  • 182
  • 322
Claudio Bisegni
  • 103
  • 2
  • 9

2 Answers2

1

Enter Swift: https://github.com/facebook/swift/

git clone https://github.com/facebook/swift
cd swift ; mvn package

In particular swift2thrift. Markup your classes as here: https://github.com/facebook/swift/

and run:

MY_CLASSES=$HOME/ExampleService/target/ExampleService-1.0-SNAPSHOT.jar  # just an example
cd ~/ExampleService ; mvn compile package && java -cp ~/swift/target/swift2thrift-generator-cli-0.15.0-SNAPSHOT-standalone.jar:$MY_CLASSEScom.facebook.swift.generator.swift2thrift.Main -package net.mycompany ExampleService -map ExampleService path/to/base.thrift -namespace py mycompany.thrift -namespace java net.mycompany.thrift -namespace cpp mycompany

outputs Thrift .idls for existsing Java classes.

Also see: Can generate .thrift files from existing java/scala interfaces and data types?

Community
  • 1
  • 1
user48956
  • 14,850
  • 19
  • 93
  • 154
0

Not from the library directly; thrift generates it's own classes and some validation code so that both "ends" (client/server) can inter-operate without error. You should write code to map your business objects to thrift objects.

Phillip B Oldham
  • 18,807
  • 20
  • 94
  • 134
  • Thank for the answer i have seen that. I think that into thrift library there will be some utility code to facilitate this, because in many enterprise java project, already exist some business class. Anyway thanks again for replay – Claudio Bisegni Jan 28 '11 at 08:50