The following class will roundtrip (serialize to string, then deserialize to object) just fine:
public class FoobarObject
{
public readonly IFileLocation File1;
public readonly IFileLocation File2;
public readonly IFileLocation File3;
public FoobarObject(IFileLocation file1, IFileLocation file2, IFileLocation file3)
{
File1 = file1;
File2 = file2;
File3 = file3;
}
}
However, if I change it to the following, it will fail (the fields are returned as null
):
public class FoobarObject
{
//[JsonProperty("SomeFile1")]
public readonly IFileLocation SomeFile1;
public readonly IFileLocation File2;
public readonly IFileLocation File3;
public FoobarObject(IFileLocation file1, IFileLocation file2, IFileLocation file3)
{
SomeFile1 = file1;
File2 = file2;
File3 = file3;
}
}
But, by uncommenting the JsonProperty
line, the object will roundtrip properly.
The serialized string appears to be correct ("{\"SomeFile1\":\"C:\\\\vibwd541.u2q\\\\Foobar1\", \"File2\":\"C:\\\\vibwd541.u2q\\\\Foobar2\", \"File3\":null}"
, but the deserializing does not happen.
What is going on?