[ https://issues.apache.org/jira/browse/THRIFT-2476?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]
Xiaodong Ma updated THRIFT-2476: -------------------------------- Component/s: C++ - Library C++ - Compiler Description: Currently TJSONProtocol generate private json format, while in many use case, a standard json format is required in order to talk with external software modules. For example: If you have thrift IDL like this: struct example { 1: required string field1, 2: optional list<string> field2, } With TJSONProtocol, you will get: {"1":{"str":"field1-value"},"2":{"lst":["str",2,"field2-value1","field2-value2"]}} With TSimpleJSONProtocol, you will get: {"field1":"field1-value","field2":["field2-value1","field2-value2"]} Attached patch provide support on this. Test passed: ama@ubuntu:~/thrift/test/cpp$ ./TestServer --protocol simplejson Starting "simple" server (buffered/simplejson) listen on: 9090 testVoid() testString("Test") testByte(1) testI32(-1) testI64(-34359738368) testDouble(-5.209852) testStruct({"Zero", 1, -3, -5}) testNest({1, {"Zero", 1, -3, -5}, 5}) testMap({0 => -10, 1 => -9, 2 => -8, 3 => -7, 4 => -6}) testSet({-2, -1, 0, 1, 2}) testList({-2, -1, 0, 1, 2}) testEnum(1) testEnum(2) testEnum(3) testEnum(5) testEnum(8) testTypedef(309858235082523) testMapMap(1) testInsanity() return = {1 => {2 => {{5 => 5, 8 => 8, }, {{"Goodbye4", 4, 4, 4}, {"Hello2", 2, 2, 2}, }}, 3 => {{5 => 5, 8 => 8, }, {{"Goodbye4", 4, 4, 4}, {"Hello2", 2, 2, 2}, }}, }, 2 => {6 => {{}, {}}, }, } testException(Xception) testException(TException) testException(success) testMultiException(Xception, test 1) testMultiException(Xception2, test 2) testMultiException(success, test 3) testOneway(1): Sleeping... testOneway(1): done sleeping! testI32(-1) ama@ubuntu:~/thrift/test/cpp$ ./TestClient --protocol simplejson Connecting (buffered/simplejson) to: localhost:9090 Test #1, connect localhost:9090 testVoid() = void testString("Test") = "Test" testByte(1) = 1 testI32(-1) = -1 testI64(-34359738368) = -34359738368 testDouble(-5.2098523) = -5.209852 testStruct({"Zero", 1, -3, -5}) = {"Zero", 1, -3, -5} testNest({1, {"Zero", 1, -3, -5}), 5} = {1, {"Zero", 1, -3, -5}, 5} testMap({0 => -10, 1 => -9, 2 => -8, 3 => -7, 4 => -6}) = {0 => -10, 1 => -9, 2 => -8, 3 => -7, 4 => -6} testSet({-2, -1, 0, 1, 2}) = {-2, -1, 0, 1, 2} testList({-2, -1, 0, 1, 2}) = {-2, -1, 0, 1, 2} testEnum(ONE) = 1 testEnum(TWO) = 2 testEnum(THREE) = 3 testEnum(FIVE) = 5 testEnum(EIGHT) = 8 testTypedef(309858235082523) = 309858235082523 testMapMap(1) = {-4 => {-4 => -4, -3 => -3, -2 => -2, -1 => -1, }, 4 => {1 => 1, 2 => 2, 3 => 3, 4 => 4, }, } testInsanity() = {1 => {2 => {{5 => 5, 8 => 8, }, {{"Goodbye4", 4, 4, 4}, {"Hello2", 2, 2, 2}, }}, 3 => {{5 => 5, 8 => 8, }, {{"Goodbye4", 4, 4, 4}, {"Hello2", 2, 2, 2}, }}, }, 2 => {6 => {{}, {}}, }, } testClient.testException("Xception") => {1001, "Xception"} testClient.testException("TException") => Caught TException : Default TException. testClient.testException("success") => void testClient.testMultiException("Xception", "test 1") => {1001, "This is an Xception"} testClient.testMultiException("Xception2", "test 2") => {2002, {"This is an Xception2"}} testClient.testMultiException("success", "test 3") => {{"test 3"}} testClient.testOneway(1) => success - took 0.01 ms re-test testI32(-1) = -1 Total time: 1009072 us All tests done. Min time: 1009072 us Max time: 1009072 us Avg time: 1009072 us Patch Info: Patch Available Issue Type: New Feature (was: Bug) > Thrift SimpleJSON protocol support for cpp > ------------------------------------------- > > Key: THRIFT-2476 > URL: https://issues.apache.org/jira/browse/THRIFT-2476 > Project: Thrift > Issue Type: New Feature > Components: C++ - Compiler, C++ - Library > Reporter: Xiaodong Ma > Attachments: cpp_simplejson.diff > > > Currently TJSONProtocol generate private json format, while in many use case, > a standard json format is required in order to talk with external software > modules. > For example: > If you have thrift IDL like this: > struct example { > 1: required string field1, > 2: optional list<string> field2, > } > With TJSONProtocol, you will get: > > {"1":{"str":"field1-value"},"2":{"lst":["str",2,"field2-value1","field2-value2"]}} > With TSimpleJSONProtocol, you will get: > {"field1":"field1-value","field2":["field2-value1","field2-value2"]} > Attached patch provide support on this. > Test passed: > ama@ubuntu:~/thrift/test/cpp$ ./TestServer --protocol simplejson > Starting "simple" server (buffered/simplejson) listen on: 9090 > testVoid() > testString("Test") > testByte(1) > testI32(-1) > testI64(-34359738368) > testDouble(-5.209852) > testStruct({"Zero", 1, -3, -5}) > testNest({1, {"Zero", 1, -3, -5}, 5}) > testMap({0 => -10, 1 => -9, 2 => -8, 3 => -7, 4 => -6}) > testSet({-2, -1, 0, 1, 2}) > testList({-2, -1, 0, 1, 2}) > testEnum(1) > testEnum(2) > testEnum(3) > testEnum(5) > testEnum(8) > testTypedef(309858235082523) > testMapMap(1) > testInsanity() > return = {1 => {2 => {{5 => 5, 8 => 8, }, {{"Goodbye4", 4, 4, 4}, {"Hello2", > 2, 2, 2}, }}, 3 => {{5 => 5, 8 => 8, }, {{"Goodbye4", 4, 4, 4}, {"Hello2", 2, > 2, 2}, }}, }, 2 => {6 => {{}, {}}, }, } > testException(Xception) > testException(TException) > testException(success) > testMultiException(Xception, test 1) > testMultiException(Xception2, test 2) > testMultiException(success, test 3) > testOneway(1): Sleeping... > testOneway(1): done sleeping! > testI32(-1) > ama@ubuntu:~/thrift/test/cpp$ ./TestClient --protocol simplejson > Connecting (buffered/simplejson) to: localhost:9090 > Test #1, connect localhost:9090 > testVoid() = void > testString("Test") = "Test" > testByte(1) = 1 > testI32(-1) = -1 > testI64(-34359738368) = -34359738368 > testDouble(-5.2098523) = -5.209852 > testStruct({"Zero", 1, -3, -5}) = {"Zero", 1, -3, -5} > testNest({1, {"Zero", 1, -3, -5}), 5} = {1, {"Zero", 1, -3, -5}, 5} > testMap({0 => -10, 1 => -9, 2 => -8, 3 => -7, 4 => -6}) = {0 => -10, 1 => -9, > 2 => -8, 3 => -7, 4 => -6} > testSet({-2, -1, 0, 1, 2}) = {-2, -1, 0, 1, 2} > testList({-2, -1, 0, 1, 2}) = {-2, -1, 0, 1, 2} > testEnum(ONE) = 1 > testEnum(TWO) = 2 > testEnum(THREE) = 3 > testEnum(FIVE) = 5 > testEnum(EIGHT) = 8 > testTypedef(309858235082523) = 309858235082523 > testMapMap(1) = {-4 => {-4 => -4, -3 => -3, -2 => -2, -1 => -1, }, 4 => {1 => > 1, 2 => 2, 3 => 3, 4 => 4, }, } > testInsanity() = {1 => {2 => {{5 => 5, 8 => 8, }, {{"Goodbye4", 4, 4, 4}, > {"Hello2", 2, 2, 2}, }}, 3 => {{5 => 5, 8 => 8, }, {{"Goodbye4", 4, 4, 4}, > {"Hello2", 2, 2, 2}, }}, }, 2 => {6 => {{}, {}}, }, } > testClient.testException("Xception") => {1001, "Xception"} > testClient.testException("TException") => Caught TException : Default > TException. > testClient.testException("success") => void > testClient.testMultiException("Xception", "test 1") => {1001, "This is an > Xception"} > testClient.testMultiException("Xception2", "test 2") => {2002, {"This is an > Xception2"}} > testClient.testMultiException("success", "test 3") => {{"test 3"}} > testClient.testOneway(1) => success - took 0.01 ms > re-test testI32(-1) = -1 > Total time: 1009072 us > All tests done. > Min time: 1009072 us > Max time: 1009072 us > Avg time: 1009072 us -- This message was sent by Atlassian JIRA (v6.2#6252)