Esempio n. 1
0
        public override void Write(Utf8JsonWriter writer, IDictionary <string, object> value, JsonSerializerOptions options)
        {
            writer.WriteStartObject();

            foreach (var kvp in value)
            {
                writer.WritePropertyName(SnakeCaseJsonNamingPolicy.ToSnakeCase(kvp.Key));
                var t = kvp.Value.GetType();

                //TODO prevent reentry and cache get converters
                System.Text.Json.JsonSerializer.Serialize(writer, kvp.Value, t, options);
            }

            writer.WriteEndObject();
        }
Esempio n. 2
0
        public override void Write(Utf8JsonWriter writer, IDictionary <string, object> value, JsonSerializerOptions options)
        {
            writer.WriteStartObject();

            foreach (var kvp in value)
            {
                var propertyName = SnakeCaseJsonNamingPolicy.ToSnakeCase(kvp.Key);
                writer.WritePropertyName(propertyName);

                if (kvp.Value == null)
                {
                    writer.WriteNullValue();
                }
                else
                {
                    var inputType = kvp.Value.GetType();
                    //TODO prevent reentry and cache get converters
                    JsonSerializer.Serialize(writer, kvp.Value, inputType, options);
                }
            }

            writer.WriteEndObject();
        }