-Fix issue when deserializing string to byte data
-Fix converting a JValue to a compatible type -Allow JsonConverterAttribute to be added to interfaces/structs/enums
This commit is contained in:
@@ -10,7 +10,7 @@ namespace Newtonsoft.Json
|
||||
/// <summary>
|
||||
/// Instructs the <see cref="JsonSerializer"/> to use the specified <see cref="JsonConverter"/> when serializing the member or class.
|
||||
/// </summary>
|
||||
[AttributeUsage(AttributeTargets.Field | AttributeTargets.Property | AttributeTargets.Class, AllowMultiple = false)]
|
||||
[AttributeUsage(AttributeTargets.Field | AttributeTargets.Property | AttributeTargets.Class | AttributeTargets.Struct | AttributeTargets.Interface | AttributeTargets.Enum, AllowMultiple = false)]
|
||||
public sealed class JsonConverterAttribute : Attribute
|
||||
{
|
||||
private readonly Type _converterType;
|
||||
|
||||
@@ -267,6 +267,9 @@ namespace Newtonsoft.Json.Linq
|
||||
if (value == null)
|
||||
throw new InvalidCastException("Cannot cast {0} to {1}.".FormatWith(CultureInfo.InvariantCulture, token.GetType(), typeof(T)));
|
||||
|
||||
if (value.Value is U)
|
||||
return (U)value.Value;
|
||||
|
||||
Type targetType = typeof(U);
|
||||
|
||||
if (ReflectionUtils.IsNullableType(targetType))
|
||||
|
||||
@@ -214,8 +214,8 @@ namespace Newtonsoft.Json.Serialization
|
||||
{
|
||||
switch (reader.TokenType)
|
||||
{
|
||||
// populate a typed object or generic dictionary/array
|
||||
// depending upon whether an objectType was supplied
|
||||
// populate a typed object or generic dictionary/array
|
||||
// depending upon whether an objectType was supplied
|
||||
case JsonToken.StartObject:
|
||||
return CreateObject(reader, objectType, contract, member, existingValue);
|
||||
case JsonToken.StartArray:
|
||||
@@ -233,6 +233,10 @@ namespace Newtonsoft.Json.Serialization
|
||||
ReflectionUtils.IsNullableType(objectType))
|
||||
return null;
|
||||
|
||||
// string that needs to be returned as a byte array should be base 64 decoded
|
||||
if (objectType == typeof(byte[]))
|
||||
return Convert.FromBase64String((string)reader.Value);
|
||||
|
||||
return EnsureType(reader.Value, objectType);
|
||||
case JsonToken.StartConstructor:
|
||||
case JsonToken.EndConstructor:
|
||||
|
||||
Reference in New Issue
Block a user