Problem when deserializing null values to properties of type JObject

Jun 3, 2014 at 9:24 AM
Hi,

With the latest version of the Newtonsoft.Json library(v 6.0.0.0) I get an error when deserializing a null value to a property of type JObject.

Here is a sample code that fails(just overwrite Program.cs in a new Console Application project):
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;

namespace ConsoleApplication1 {
    class Program {
        static void Main(string[] args) {
            var js = new JsonSerializer();
            var tt = JsonConvert.DeserializeObject(
                "{ \"Value\": null }",
                typeof(TestClass)
            );
        }
    }

    public class TestClass {
        public JObject Value {
            get;
            set;
        }
    }
}
The error is:
Unable to cast object of type 'Newtonsoft.Json.Linq.JValue' to type 'Newtonsoft.Json.Linq.JObject'.

The same code worked with a previous version. I think it should work. Can you please advise?

Thanks.
Oct 15, 2014 at 9:09 AM
Hi,

I met the exact same problem. I am using version 6.0.5.

Could anybody shed some light on this?

Thanks,
Karl