liubiao4123 / servicestack

Automatically exported from code.google.com/p/servicestack
0 stars 0 forks source link

Serializing byte[] cannot be Deserialized. #60

Open GoogleCodeExporter opened 8 years ago

GoogleCodeExporter commented 8 years ago
What steps will reproduce the problem?
1. Serialize a byte[] with JsonSerializer.SerializeToString
2. Deserialize the JSON string with JsonSerializer.DeserializeFromString

What is the expected output? What do you see instead?

Unit Test:

            var rnd = new Random();
            var data = new byte[100];
            rnd.NextBytes(data);
            var json = JsonSerializer.SerializeToString(data);
            var data2 = (byte[])JsonSerializer.DeserializeFromString(json, typeof (byte[]));
            CollectionAssert.AreEqual(data, data2);

Expected: Pass

Actual: 
The input is not a valid Base-64 string as it contains a non-base 64 character, 
more than two padding characters, or a non-white space character among the 
padding characters.
   at System.Convert.FromBase64String(String s)
   at ServiceStack.Text.Common.DeserializeArray`2.ParseByteArray(String value)
   at ServiceStack.Text.JsonSerializer.DeserializeFromString(String value, Type type)

What version of the product are you using? On what operating system?

OS: Windows 7
ServiceStack.Text Version: 2.0.9.42099

Please provide any additional information below.

Original issue reported on code.google.com by andrew.f...@gmail.com on 2 Jun 2011 at 4:03