Page MenuHomeFeedback Tracker

BaseSerializationLoadContext::SerializationLoad unable to handle object that starts with array read
Closed, ResolvedPublic

Description

If you try to read an array as the first property of a child object in JSON it fails. Putting any other primitive value before that makes the array read afterward work. I suspect some read mode is not set up until a normal non-collection value is read from the section.

class MyTestObject
{
	protected bool SerializationSave(BaseSerializationSaveContext saveContext)
	{
		saveContext.WriteValue("dataLayoutVersion", 1);
		saveContext.WriteValue("id", "5A0CD41A-0000-0001-0000-00004ED19D80");
		saveContext.WriteValue("prefab", "F649585ABB3706C4");
		
		saveContext.StartObject("components");
			
		//saveContext.WriteValue("somestring", "hello world");		
		
		array<string> componentTypesInOrder = {"Transformation", "HitZoneContainer", "FuelManager"};
		saveContext.WriteValue("order", componentTypesInOrder);
		
		saveContext.EndObject();
		
		return true;
	}
	
	protected bool SerializationLoad(BaseSerializationLoadContext loadContext)
	{
		int dataLayoutVersion;
		Print("Read_dataLayoutVersion: " + loadContext.ReadValue("dataLayoutVersion", dataLayoutVersion));
		Print(dataLayoutVersion);
		
		string id;
		Print("Read_id: " + loadContext.ReadValue("id", id));
		Print(id);
		
		string prefab;
		Print("Read_id: " + loadContext.ReadValue("prefab", prefab));
		Print(prefab);
		
		loadContext.StartObject("components");
		
		//string somestring;
		//Print("somestring_id: " + loadContext.ReadValue("somestring", somestring));
		//Print(somestring);
		
		array<string> componentTypesInOrder();
		Print("order_Read: " + loadContext.ReadValue("order", componentTypesInOrder));
		Print(componentTypesInOrder);
		
		loadContext.EndObject();
		
		return true;
	}
}
MyTestObject input();
SCR_JsonSaveContext writer();
writer.WriteValue("entity", input);

string dataString = writer.ExportToString();
Print(dataString);

MyTestObject output();
SCR_JsonLoadContext reader();
reader.ImportFromString(dataString);
reader.ReadValue("entity", output);

SCRIPT : string dataString = '{"entity":{"dataLayoutVersion":1,"id":"5A0CD41A-0000-0001-0000-00004ED19D80","prefab":"F649585ABB3706C4","components":{"order":["Transformation","HitZoneContainer","FuelManager"]}}}'
SCRIPT : Read_dataLayoutVersion: true
SCRIPT : int dataLayoutVersion = 1
SCRIPT : Read_id: true
SCRIPT : string id = '5A0CD41A-0000-0001-0000-00004ED19D80'
SCRIPT : Read_id: true
SCRIPT : string prefab = 'F649585ABB3706C4'
SCRIPT : order_Read: false
SCRIPT : array<string> componentTypesInOrder = 0x0000016F17D41A38 {}

Details

Severity
Minor
Resolution
Open
Reproducibility
Always
Operating System
Windows 10 x64
Category
General
Steps To Reproduce
  1. Execute above code, notice how the output shows read fail on the array.
  2. Uncomment the somestring write and read property and run again. Now it works

Event Timeline

Arkensor created this task.Aug 6 2022, 3:44 PM
Geez changed the task status from New to Assigned.Aug 8 2022, 11:04 PM
Geez closed this task as Resolved.Apr 19 2023, 3:16 PM
Geez claimed this task.
Geez added a subscriber: Geez.

should be fixed