Andrew Sinclair - 268 - May 20, 2014

I am using JsonSerializer.SerializeToString to serialize an object.
The object contains some properties which are byte arrays and for some reason these byte arrays are not being serialized as expected.

For example, byte[255,13,82,136] is being serialized as /w1SiA==

Any ideas what is going on?

Andrew Sinclair:

Is there any way I can prevent the automatic base64 encoding? I just want to use SerializeToString and DeserializeFromString on objects that have some byte array properties.

That’s not going to work on a text stream. There’s a reason why binary data is encoded in Base64 in the first place, i.e. so it can be safely transported with different text encodings. 

The Base64 encoding should be a transparent impl detail that should happily de/serialize objects to and from JSON. Do you have an example that doesn’t work?

byte[] are automatically base64 encoded.