|
1 | | -using System.Collections.Generic; |
| 1 | +using System; |
| 2 | +using System.Collections.Generic; |
2 | 3 | using Exceptionless.Models; |
3 | 4 | using Exceptionless.Models.Data; |
4 | 5 | using MessagePack; |
5 | 6 | using MessagePack.Formatters; |
6 | 7 |
|
7 | 8 | namespace Exceptionless.MessagePack { |
8 | 9 | internal class DataDictionaryFormatter : IMessagePackFormatter<DataDictionary?> { |
| 10 | + private const string RawJsonPrefix = "\u001Eexceptionless:raw-json:"; |
| 11 | + |
9 | 12 | public void Serialize(ref MessagePackWriter writer, DataDictionary? value, MessagePackSerializerOptions options) { |
10 | 13 | if (value == null) { |
11 | 14 | writer.WriteNil(); |
@@ -58,8 +61,13 @@ public void Serialize(ref MessagePackWriter writer, DataDictionary? value, Messa |
58 | 61 | writer.Write((string)item.Value); |
59 | 62 | break; |
60 | 63 | default: |
61 | | - options.Resolver.GetFormatter<object>() |
62 | | - .Serialize(ref writer, item.Value, options); |
| 64 | + if (value.IsRawJson(item.Key) && item.Value is string rawJson) { |
| 65 | + writer.Write(RawJsonPrefix + rawJson); |
| 66 | + } else { |
| 67 | + options.Resolver.GetFormatter<object>() |
| 68 | + .Serialize(ref writer, item.Value, options); |
| 69 | + } |
| 70 | + |
63 | 71 | break; |
64 | 72 | } |
65 | 73 | } |
@@ -138,7 +146,10 @@ public void Serialize(ref MessagePackWriter writer, DataDictionary? value, Messa |
138 | 146 | #endif |
139 | 147 | default: { |
140 | 148 | var value = options.Resolver.GetFormatter<object>().Deserialize(ref reader, options); |
141 | | - dic.Add(key, value); |
| 149 | + if (value is string rawJson && rawJson.StartsWith(RawJsonPrefix, StringComparison.Ordinal)) |
| 150 | + dic.SetRawJson(key, rawJson.Substring(RawJsonPrefix.Length)); |
| 151 | + else |
| 152 | + dic.Add(key, value); |
142 | 153 | break; |
143 | 154 | } |
144 | 155 | } |
|
0 commit comments