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

Union is not serialized correctly by Thrift C Glib

VotersWatch issueWatchersLinkCloneUpdate Comment AuthorReplace String in CommentUpdate Comment VisibilityDelete Comments
    XMLWordPrintableJSON

    Details

    • Type: Bug
    • Status: Closed
    • Priority: Major
    • Resolution: Duplicate
    • Affects Version/s: 0.9.3
    • Fix Version/s: 0.10.0
    • Component/s: C glib - Library
    • Labels:
      None

      Description

      I am trying to serialize Thrift union in C and then deserialize in Java. On Java side I always get serialized only first field of union. The following code works correctly with structs but not with union only.

      Thrift 0.9.3

      messages.thrift:

      struct JLException {
      ...
      }
      
      struct JLFrame {
      ...
      }
      
      union JLMessage {
          1: JLException exc,
          2: JLFrame frame
      }
      

      Serialization code in C (I replaced with "..." unnecessary parts):

      JLException* jlExeption = g_object_new(TYPE_J_L_EXCEPTION, ... , NULL);
      
      if (jlExeption) {
          JLMessage* jlMessage = g_object_new(TYPE_J_L_MESSAGE, "exc", jlExeption, NULL);
      
          serialize_and_send_thrift_message((ThriftStruct*) jlMessage,
              THRIFT_STRUCT_CLASS(J_L_MESSAGE_GET_CLASS(jlMessage)));
      
          g_object_unref(jlExeption);
          g_object_unref(jlMessage);
      }
      
      JLFrame* jlFrame = g_object_new(TYPE_J_L_FRAME, ... , NULL);
      
      if (jlFrame) {
          JLMessage* jlMessage = g_object_new(TYPE_J_L_MESSAGE, "frame", jlFrame,
              NULL);
      
          serialize_and_send_thrift_message((ThriftStruct*) jlMessage,
              THRIFT_STRUCT_CLASS(J_L_MESSAGE_GET_CLASS(jlMessage)));
      
          g_object_unref(jlFrame);
          g_object_unref(jlMessage);
      }
      

      Deserialization code in Java:

      TDeserializer deserializer = new TDeserializer();
      JLMessage message = new JLMessage();
      
      try {
          byte[] binData = tuple.getBinary(0);
          deserializer.deserialize(message, binData);
      } catch (TException e) {
          _logger.error(e);
      }
      
      if (JLMessage._Fields.EXC.equals(message.getSetField())) {
          _logger.info("Received EXCEPTION message");
      } else if (JLMessage._Fields.FRAME.equals(message.getSetField())) {
          _logger.info("Received FRAME message");
      }
      

      As a result on Java side only "Received EXCEPTION message" is logged. For JLFrame messages it receives empty JLException message.

        Attachments

        Issue Links

          Activity

            People

            • Assignee:
              jensg Jens Geyer
              Reporter:
              alexandr.rewa@gmail.com Alexandr Rewa

              Dates

              • Created:
                Updated:
                Resolved:

                Issue deployment