Page MenuHomeFeedback Tracker

JSON Deserialization of map fails if first member in value class is not a string.
Closed, ResolvedPublic

Description

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

Details

Severity
Crash
Resolution
Open
Reproducibility
Always
Operating System
Windows 10 x64
Category
General
Steps To Reproduce
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);
}

Event Timeline

antihax created this task.Oct 22 2020, 11:54 PM
Geez changed the task status from New to Assigned.Oct 23 2020, 10:29 AM
komer added a subscriber: komer.Oct 25 2020, 1:36 AM

@Geez, this has been an issue for years and also the same with json file size limits. Please give us an update as we have already went through this process of marking it assigned and waited years. Please and thank you, friend.

They probably are intending you to use the new JSONApi from now on.

ukulelekid713 added a comment.EditedOct 26 2020, 10:15 PM

@Jacob_Mango, it's complete garbage, and most if not all modders haven't used it and continued to use the buggy shit we have had for years. I don't feel like anyone wishes to have a completely new system, just fix the serializer, or find a new one.

Geez closed this task as Resolved.May 27 2022, 11:27 AM
Geez claimed this task.

Hello antihax.
The problem has been fixed internally and the fix will appear in one of the upcoming updates.
Regards,
Geez