Class ProtoRestSerializer<RequestT extends com.google.protobuf.Message>


  • @BetaApi
    public class ProtoRestSerializer<RequestT extends com.google.protobuf.Message>
    extends java.lang.Object
    This class serializes/deserializes protobuf Message for REST interactions. It serializes requests protobuf messages into REST messages, splitting the message into the JSON request body, URL path parameters, and query parameters. It deserializes JSON responses into response protobuf message.
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      static <RequestT extends com.google.protobuf.Message>
      ProtoRestSerializer<RequestT>
      create()
      Creates a new instance of ProtoRestSerializer.
      void putPathParam​(java.util.Map<java.lang.String,​java.lang.String> fields, java.lang.String fieldName, java.lang.Object fieldValue)
      Puts a message field in fields map which will be used to populate URL path of a request.
      void putQueryParam​(java.util.Map<java.lang.String,​java.util.List<java.lang.String>> fields, java.lang.String fieldName, java.lang.Object fieldValue)
      Puts a message field in fields map which will be used to populate query parameters of a request.
      java.lang.String toBody​(java.lang.String fieldName, RequestT fieldValue)
      Serializes a message to a request body in a form of JSON-encoded string.
      java.lang.String toBody​(java.lang.String fieldName, RequestT fieldValue, boolean numericEnum)
      Serializes a message to a request body in a form of JSON-encoded string.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Method Detail

      • create

        public static <RequestT extends com.google.protobuf.Message> ProtoRestSerializer<RequestT> create()
        Creates a new instance of ProtoRestSerializer.
      • putPathParam

        public void putPathParam​(java.util.Map<java.lang.String,​java.lang.String> fields,
                                 java.lang.String fieldName,
                                 java.lang.Object fieldValue)
        Puts a message field in fields map which will be used to populate URL path of a request.
        Parameters:
        fields - a map with serialized fields
        fieldName - a field name
        fieldValue - a field value
      • putQueryParam

        public void putQueryParam​(java.util.Map<java.lang.String,​java.util.List<java.lang.String>> fields,
                                  java.lang.String fieldName,
                                  java.lang.Object fieldValue)
        Puts a message field in fields map which will be used to populate query parameters of a request.
        Parameters:
        fields - a map with serialized fields
        fieldName - a field name
        fieldValue - a field value
      • toBody

        public java.lang.String toBody​(java.lang.String fieldName,
                                       RequestT fieldValue)
        Serializes a message to a request body in a form of JSON-encoded string.
        Parameters:
        fieldName - a name of a request message field this message belongs to
        fieldValue - a field value to serialize
      • toBody

        public java.lang.String toBody​(java.lang.String fieldName,
                                       RequestT fieldValue,
                                       boolean numericEnum)
        Serializes a message to a request body in a form of JSON-encoded string.
        Parameters:
        fieldName - a name of a request message field this message belongs to
        fieldValue - a field value to serialize
        numericEnum - a boolean flag that determine if enum values should be serialized to number