Uploaded image for project: 'Thrift'
  1. Thrift
  2. THRIFT-5474

TSimpleJsonProtocol serialization on string with inner quotes does not produce valid JSON.

VotersWatch issueWatchersLinkCloneUpdate Comment AuthorReplace String in CommentUpdate Comment VisibilityDelete Comments
    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Minor
    • Resolution: Cannot Reproduce
    • None
    • None
    • Java - Library
    • None

    Description

      There is an issue in the generation of JSON from the TSimpleJSONProtocol, where if there are quotes inside of a string, then those quotes will not be serialized correctly. These quotes need one more layer of escaping to produce valid JSON.

       

      For instance, if you have the Thrift structure defined by:

       

      struct MyThriftStruct {
          1: required string my_string
      }
      

       

      And, I then define an object of that type in Java:

      MyThriftStruct t = new MyThriftStruct();
      t.my_string = "I said: \"this is a fairly nice string.\""

       

      And, if I then serialize this using the TSimpleJsonProtocol in this manner:

      TSerializer thriftJsonSer = new TSerializer(new TSimpleJSONProtocol.Factory());
      String myThriftStructJsonString = return thriftJsonSer.toString(t);
      

       

      This will result in JSON that cannot be deserialized because the quotes inside of the string were not escaped properly. 

      Attachments

        Activity

          This comment will be Viewable by All Users Viewable by All Users
          Cancel

          People

            Unassigned Unassigned
            thealmightygrant Grant Sherrick
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Time Tracking

                Estimated:
                Original Estimate - Not Specified
                Not Specified
                Remaining:
                Remaining Estimate - 0h
                0h
                Logged:
                Time Spent - 0.5h
                0.5h

                Slack

                  Issue deployment