示例#1
0
 /// <summary>
 /// Overrides the default UTF-7 encoding and uses the specified encoding instead when serializing. The used encoding
 /// is put in a header, so you don't necessarily need to specify the same encoding in order to be able to deserialize
 /// properly.
 /// </summary>
 public JsonSerializationOptions SpecifyEncoding(Encoding encoding)
 {
     if (encoding == null)
     {
         throw new ArgumentNullException("encoding");
     }
     jsonMessageSerializer.SpecifyEncoding(encoding);
     return(this);
 }
示例#2
0
        public void WorksWithCustomEncodingAsWell(string encodingWebName)
        {
            // arrange
            var encoding = Encoding.GetEncoding(encodingWebName);

            serializer.SpecifyEncoding(encoding);

            // act
            var transportMessageToSend = serializer.Serialize(new Message {
                Messages = new object[] { "hej!" }
            });

            // assert
            transportMessageToSend.Headers.ShouldContainKeyAndValue(Headers.Encoding, encoding.WebName);
            transportMessageToSend.Headers.ShouldContainKeyAndValue(Headers.ContentType, "text/json");

            encoding.GetString(transportMessageToSend.Body)
            .Replace("\r", "")
            .Replace("\n", "")
            .Replace(" ", "")
            .ShouldBe(@"{""$type"":""System.Object[],mscorlib"",""$values"":[""hej!""]}");
        }