TJSONProtocol writing support in Java
Summary: TJSONProtocol for Java with write support and a TSerializer utility for easier conversion of Thrift objects into byte[] or strings.
Reviewed By: dreiss
Test Plan: Included a basic piece of this in test/ client for Java.
Revert: OK
DiffCamp Revision: 3890
git-svn-id: https://svn.apache.org/repos/asf/incubator/thrift/trunk@665367 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/test/java/src/TestClient.java b/test/java/src/TestClient.java
index 778bb16..87f3971 100644
--- a/test/java/src/TestClient.java
+++ b/test/java/src/TestClient.java
@@ -4,12 +4,14 @@
import thrift.test.*;
import com.facebook.thrift.TApplicationException;
+import com.facebook.thrift.TSerializer;
import com.facebook.thrift.transport.TTransport;
import com.facebook.thrift.transport.TSocket;
import com.facebook.thrift.transport.THttpClient;
import com.facebook.thrift.transport.TFramedTransport;
import com.facebook.thrift.transport.TTransportException;
import com.facebook.thrift.protocol.TBinaryProtocol;
+import com.facebook.thrift.protocol.TJSONProtocol;
import java.util.AbstractMap;
import java.util.HashMap;
@@ -39,7 +41,7 @@
if (args[i].equals("-h")) {
String[] hostport = (args[++i]).split(":");
host = hostport[0];
- port = Integer.valueOf(hostport[1]);
+ port = Integer.valueOf(hostport[1]);
} else if (args[i].equals("-f") || args[i].equals("-framed")) {
framed = true;
} else if (args[i].equals("-fo")) {
@@ -54,9 +56,9 @@
} catch (Exception x) {
x.printStackTrace();
}
-
+
TTransport transport;
-
+
if (url != null) {
transport = new THttpClient(url);
} else {
@@ -74,6 +76,7 @@
new TBinaryProtocol(transport);
ThriftTest.Client testClient =
new ThriftTest.Client(binaryProtocol);
+ Insanity insane = new Insanity();
long timeMin = 0;
long timeMax = 0;
@@ -93,7 +96,7 @@
}
long start = System.nanoTime();
-
+
/**
* VOID TEST
*/
@@ -118,7 +121,7 @@
System.out.print("testByte(1)");
byte i8 = testClient.testByte((byte)1);
System.out.print(" = " + i8 + "\n");
-
+
/**
* I32 TEST
*/
@@ -307,7 +310,7 @@
/**
* INSANITY TEST
*/
- Insanity insane = new Insanity();
+ insane = new Insanity();
insane.userMap = new HashMap<Integer, Long>();
insane.userMap.put(Numberz.FIVE, (long)5000);
Xtruct truck = new Xtruct();
@@ -369,14 +372,18 @@
}
long timeAvg = timeTot / numTests;
-
+
System.out.println("Min time: " + timeMin/1000 + "us");
System.out.println("Max time: " + timeMax/1000 + "us");
System.out.println("Avg time: " + timeAvg/1000 + "us");
-
+
+ String json = (new TSerializer(new TJSONProtocol.Factory())).toString(insane);
+
+ System.out.println("\nFor good meausre here is some JSON:\n" + json);
+
} catch (Exception x) {
x.printStackTrace();
- }
+ }
}