Class TSerializer

java.lang.Object
org.apache.thrift.TSerializer

public class TSerializer extends Object
Generic utility for easily serializing objects into a byte array or Java String.
  • Constructor Details

    • TSerializer

      public TSerializer() throws TTransportException
      Create a new TSerializer that uses the TBinaryProtocol by default.
      Throws:
      TTransportException - if there an error initializing the underlying transport.
    • TSerializer

      public TSerializer(TProtocolFactory protocolFactory) throws TTransportException
      Create a new TSerializer. It will use the TProtocol specified by the factory that is passed in.
      Parameters:
      protocolFactory - Factory to create a protocol
      Throws:
      TTransportException - if there is an error initializing the underlying transport.
  • Method Details

    • serialize

      public byte[] serialize(TBase<?,?> base) throws TException
      Serialize the Thrift object into a byte array. The process is simple, just clear the byte array output, write the object into it, and grab the raw bytes.
      Parameters:
      base - The object to serialize
      Returns:
      Serialized object in byte[] format
      Throws:
      TException - if an error is encountered during serialization.
    • toString

      public String toString(TBase<?,?> base) throws TException
      Serialize the Thrift object into a Java string, using the default JVM charset encoding.
      Parameters:
      base - The object to serialize
      Returns:
      Serialized object as a String
      Throws:
      TException - if an error is encountered during serialization.