If the first member of a class is not a string, and is used in a map of any type where the class is the value; the JSONFileLoader will crash when deserializing.
class TestData { int credit; float standing; [NonSerialized()] void TestData() { credit = 50; standing = 1.0; } } void testJSONSerializer() { auto test = new map<string, ref TestData>; test.Insert("broke", new TestData()); test.Insert("broke2", new TestData()); Print("saving"); JsonFileLoader<map<string, ref TestData>>.JsonSaveFile("$profile:test.json", test); Print("reloading"); ref map<string, ref TestData> test2; JsonFileLoader<map<string, ref TestData>>.JsonLoadFile("$profile:test.json", test2); Print(test2.Get("broke").credit); }
Results in:
SCRIPT : saving SCRIPT : reloading SCRIPT (E): JSON ERROR: Reading variable: data Expecting map Expecting instance Reading variable: credit Expecting key Cannot convert key to int
However the following:
class TestData { string justbecause; int credit; float standing; [NonSerialized()] void TestData() { credit = 50; standing = 1.0; } } void testJSONSerializer() { auto test = new map<string, ref TestData>; test.Insert("broke", new TestData()); test.Insert("broke2", new TestData()); Print("saving"); JsonFileLoader<map<string, ref TestData>>.JsonSaveFile("$profile:test.json", test); Print("reloading"); ref map<string, ref TestData> test2; JsonFileLoader<map<string, ref TestData>>.JsonLoadFile("$profile:test.json", test2); Print(test2.Get("broke").credit); }
Works and results in
SCRIPT : saving SCRIPT : reloading SCRIPT : int credit = 50