-Added reading and writing binary JSON (BSON) support - work in progress
-Added BsonReader, BsonWriter -Added support for reading and writing byte arrays to JsonReader, JsonWriter and LINQ to JSON classes -Added ReadAsBytes to JsonReader -Changed Silverlight build serializer to look for a TypeConverter -Changed .NET build to not rely on System.ComponentModel.DataAnnotations assembly to support .NET 4.0 client profile -Remove DateTimeOffset stand-in from Compact Framework build -Fixed .NET 2.0 build to run on environments without .NET 2.0 SP1 -Fixed deserialization to always use a new value created from a JsonConverter -Fixed XmlNodeConverter to support converting comments in JSON
This commit is contained in:
@@ -65,12 +65,9 @@ namespace Newtonsoft.Json.Converters
|
||||
return;
|
||||
}
|
||||
|
||||
byte[] data = value as byte[];
|
||||
byte[] data = GetByteArray(value);
|
||||
|
||||
if (data == null)
|
||||
data = GetByteArray(value);
|
||||
|
||||
writer.WriteValue(Convert.ToBase64String(data));
|
||||
writer.WriteValue(data);
|
||||
}
|
||||
|
||||
private byte[] GetByteArray(object value)
|
||||
@@ -113,19 +110,17 @@ namespace Newtonsoft.Json.Converters
|
||||
if (reader.TokenType != JsonToken.String)
|
||||
throw new Exception("Unexpected token parsing binary. Expected String, got {0}.".FormatWith(CultureInfo.InvariantCulture, reader.TokenType));
|
||||
|
||||
// current token is already at base64 string
|
||||
// unable to call ReadAsBytes so do it the old fashion way
|
||||
string encodedData = reader.Value.ToString();
|
||||
|
||||
byte[] data = Convert.FromBase64String(encodedData);
|
||||
|
||||
if (t == typeof(byte[]))
|
||||
return data;
|
||||
|
||||
#if !SILVERLIGHT && !PocketPC && !NET20
|
||||
if (t.AssignableToTypeName(BinaryTypeName))
|
||||
return Activator.CreateInstance(t, data);
|
||||
#endif
|
||||
#if !SILVERLIGHT
|
||||
if (typeof(SqlBinary).IsAssignableFrom(t))
|
||||
if (t == typeof(SqlBinary))
|
||||
return new SqlBinary(data);
|
||||
#endif
|
||||
throw new Exception("Unexpected object type when writing binary: {0}".FormatWith(CultureInfo.InvariantCulture, objectType));
|
||||
@@ -144,15 +139,12 @@ namespace Newtonsoft.Json.Converters
|
||||
? Nullable.GetUnderlyingType(objectType)
|
||||
: objectType;
|
||||
|
||||
if (t == typeof(byte[]))
|
||||
return true;
|
||||
|
||||
#if !SILVERLIGHT && !PocketPC && !NET20
|
||||
if (t.AssignableToTypeName(BinaryTypeName))
|
||||
return true;
|
||||
#endif
|
||||
#if !SILVERLIGHT
|
||||
if (typeof(SqlBinary).IsAssignableFrom(t))
|
||||
if (t == typeof(SqlBinary))
|
||||
return true;
|
||||
#endif
|
||||
return false;
|
||||
|
||||
Reference in New Issue
Block a user