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


  • @BetaApi
    public class ProtoRestSerializer<RequestT extends com.google.protobuf.Message>
    extends 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 Detail

      • create

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

        public void putPathParam​(Map<String,​String> fields,
                                 String fieldName,
                                 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​(Map<String,​List<String>> fields,
                                  String fieldName,
                                  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 String toBody​(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