Settings controlling JSON formatting.
        private static void AssertWriteValue(object value, string expectedJson, JsonFormatter.Settings settings = null)
        {
            var writer = new StringWriter();

            new JsonFormatter(settings ?? JsonFormatter.Settings.Default).WriteValue(writer, value);
            string actual = writer.ToString();

            AssertJson(expectedJson, actual);
        }
Example #2
0
    public async Task <ServiceReply> CallService(ServiceRequest request)
    {
        Google.Protobuf.JsonFormatter.Settings settings = new Google.Protobuf.JsonFormatter.Settings(true).WithFormatEnumsAsIntegers(true);
        string              requestJSON = new Google.Protobuf.JsonFormatter(settings).Format(request);
        StringContent       content     = new StringContent(requestJSON, Encoding.UTF8, "application/json");
        HttpResponseMessage response    = await this.httpClient.PostAsync(this.serviceURL, content);

        string responseJSON = await response.Content.ReadAsStringAsync();

        //TODO: this is a stupid hack for the Google.Protobuf.JsonParser as the server JSON response includes an identifier for the
        // protocol buffer oneof field "type" that would result in an error

        /*string responseCleaned = Regex.Replace(responseJSON, ",\"type\":\".*\"", "");
         * responseCleaned = Regex.Replace(responseCleaned, "\"type\":\".*\"", "");*/

        ServiceReply serviceReply = Google.Protobuf.JsonParser.Default.Parse <ServiceReply>(responseJSON);

        return(serviceReply);

        //return new ServiceReply { Error = new Ubii.General.Error { Message = "not implemented" } };
    }