Example usage for org.apache.thrift.protocol TSimpleJSONProtocol TSimpleJSONProtocol

List of usage examples for org.apache.thrift.protocol TSimpleJSONProtocol TSimpleJSONProtocol

Introduction

In this page you can find the example usage for org.apache.thrift.protocol TSimpleJSONProtocol TSimpleJSONProtocol.

Prototype

public TSimpleJSONProtocol(TTransport trans) 

Source Link

Document

Constructor

Usage

From source file:com.kromatik.dasshy.server.thrift.JsonSerializer.java

License:Open Source License

@Override
public void write(final T t, final OutputStream outputStream) {
    byte[] bytesEntity;
    TMemoryBuffer memoryBuffer = null;/*from   w ww . j a  v a 2  s.co m*/
    try {
        memoryBuffer = new TMemoryBuffer(1);
        t.write(new TSimpleJSONProtocol(memoryBuffer));
        memoryBuffer.flush();

        bytesEntity = memoryBuffer.toString("UTF-8").getBytes("UTF-8");

        outputStream.write(bytesEntity);

    } catch (IOException e) {
        throw new SerializationException("Cannot write base entity", e);
    } catch (final Exception e) {
        throw new SerializationException(
                "Failed to serialise Thrift entity to Simple JSON format. Thrift entity toString(): '"
                        + ((t == null) ? "null" : t.toString()) + "'",
                e);
    } finally {
        if (memoryBuffer != null) {
            memoryBuffer.close();
        }
    }
}

From source file:org.apache.hadoop.hive.metastore.hbase.HBaseReadWrite.java

License:Apache License

private String dumpThriftObject(TBase obj) throws TException, UnsupportedEncodingException {
    TMemoryBuffer buf = new TMemoryBuffer(1000);
    TProtocol protocol = new TSimpleJSONProtocol(buf);
    obj.write(protocol);// ww w.  j a v a 2s  .c o m
    return buf.toString("UTF-8");
}

From source file:thrift.demo.userservice.serialization.ThriftSerialization.java

License:Apache License

private static void simpleJson() throws TException {
    User originUser = UserInstance.INSTANCE.getUser().deepCopy();
    //serialize/*w  w  w  .  ja va  2  s.  c  o  m*/
    OutputStream baos = new ByteArrayOutputStream();
    TProtocol oprot = new TSimpleJSONProtocol(new TIOStreamTransport(baos));
    originUser.write(oprot);

    System.out.println("simple json ret: "
            + new String((((ByteArrayOutputStream) baos).toByteArray()), Charset.forName("UTF-8")));
}