I have a fairly complex json string that I can successfully parse under preview 3 but when I move the code to preview 4 I’m getting an unhandled null reference exception. I have narrowed the issue down to creating the instance with a custom array object ( daily[] ) in the root of the object, the name and length properties are null, and -1 no matter what I try. If I use a native type (string[]) it initialized as expected.
I have created a ready to run test project that includes working code for preview firmware 3 and the same example with firmware 4 that fails. Any advice anyone might have to get this code working under preview 4 would be greatly appreciated.
static void Main()
{
string validJson = "[see test project for full string and custom objects]";
Debug.WriteLine(validJson); // This is valid JSON. Checked on a couple differnt websites.
var jsonResponse = (WeatherResponse)JsonConverter.DeserializeObject(validJson, typeof(WeatherResponse), CreateInstance);
Debug.WriteLine($"Temp: {jsonResponse.current.temp}");
}
private static object CreateInstance(string path, JToken root, Type baseType, string name, int length)
{
if (path == "/" & name == "daily")
return new Daily[length];
else if (path == "//daily" & name == null)
return new Daily();
else if (path == "//daily" & name == "weather")
return new Weather[length];
else if (path == "//daily/weather" & name == null)
return new Weather();
else if (path == "/current" & name == "weather")
return new Weather[length];
else if (path == "/current/weather" & name == null)
return new Weather();
else
return null;
}