Skip to content

Instantly share code, notes, and snippets.

@ianoc
Created March 13, 2016 21:00
Show Gist options
  • Save ianoc/085bf341e9f80d5cf4e2 to your computer and use it in GitHub Desktop.
Save ianoc/085bf341e9f80d5cf4e2 to your computer and use it in GitHub Desktop.
thrift to json
import org.apache.thrift.transport.TIOStreamTransport
import org.apache.thrift.protocol.{TProtocol, TProtocolFactory, TSimpleJSONProtocol}
val protocolFactory = new TSimpleJSONProtocol.Factory
def toJson(t: MYTYPE): String = {
val buf = new java.io.ByteArrayOutputStream
val proto = protocolFactory.getProtocol(new TIOStreamTransport(buf))
MYTYPE.encode(t, proto)
val baseStr = new String(buf.toByteArray, "UTF-8")
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment