public async Task ConvertAsync()

in src/Microsoft.Azure.WebJobs.Extensions.Dapr/Bindings/Converters/DaprStateConverter.cs [53:79]


        public async Task<byte[]> ConvertAsync(
            DaprStateAttribute input,
            CancellationToken cancellationToken)
        {
            string content = await this.GetStringContentAsync(input, cancellationToken);
            if (string.IsNullOrEmpty(content))
            {
                return Array.Empty<byte>();
            }

            // Per Yaron, Dapr only supports JSON payloads over HTTP.
            // By default we assume that the payload is a JSON-serialized base64 string of bytes
            JsonElement json = JsonDocument.Parse(content).RootElement;
            byte[]? bytes;

            try
            {
                bytes = JsonSerializer.Deserialize<byte[]>(json);
            }
            catch (JsonException)
            {
                // Looks like it's not actually JSON - just return the raw bytes
                bytes = Encoding.UTF8.GetBytes(JsonSerializer.Serialize(json, JsonUtils.DefaultSerializerOptions));
            }

            return bytes ?? Array.Empty<byte>();
        }