I am trying to deserialize some json into some simple objects that inherit from Reactive UI's ReactiveObject class. For some reason the properties will never get filled there. Using a POCO instead works without any problems.
class Program
{
class Profile
{
public string Name { get; set; }
}
class ReactiveProfile : ReactiveObject
{
private string _name;
public string Name
{
get => _name;
set => this.RaiseAndSetIfChanged(ref _name, value);
}
}
static void Main(string[] args)
{
var profiles = new List<Profile>()
{
new Profile() {Name = "Foo"},
new Profile() {Name = "Bar"}
};
var path = @"C:\temp\profiles.json";
File.WriteAllText(path,
JsonConvert.SerializeObject(profiles.ToArray(),
Formatting.Indented,
new StringEnumConverter()),
Encoding.UTF8);
// works
var pocoProfiles = (Profile[])JsonConvert.DeserializeObject(
File.ReadAllText(path, Encoding.UTF8),
typeof(Profile[]));
// properties not filled
var reactiveProfiles = (ReactiveProfile[])JsonConvert.DeserializeObject(
File.ReadAllText(path, Encoding.UTF8),
typeof(ReactiveProfile[]));
if (File.Exists(path))
{
File.Delete(path);
}
}
}