Page MenuHomeFeedback Tracker

JsonSerializer not checking actual Class type
Assigned, UrgentPublic

Description

When using the JsonSerializer and want to serialize a polimorph class, then it will only include the fields of the parent object and does not check if the object isn't of a more specific type and which fields it has.
I know this cannot be fixed for reading the json data and expecting DayZ to know which class this could be, but it would be really useful when it would do that for writing to json (or add an option to enabled it, because of performance etc)
So my suggestion would be to change
proto bool WriteToString(void variable_out, bool nice, out string result); in the Json Serializer to proto bool WriteToString(void variable_out, bool nice, out string result, bool includeExtendingClassFields = false);.
Currently I would need to make a Cast for each possible child class and then invoke the WriteToString method with the casted object, which is pretty annoying when having a lot of classes inheriting the base class.

Just a quick exmaple to make clear what I mean:

class LB_BaseResponse {
	string status = "ok";
}

class LB_StatusResponse : LB_BaseResponse  {
	int players = 0; // Filled from somewhere
	string world = ""; // Filled from somewhere
}
class LB_NotFoundResponse : LB_BaseResponse  {

	void LB_NotFoundResponse() {
		this.status = "not-found";
	}
}
class LB_PlayerInfoResponse : LB_BaseResponse {
	string steamid, name, guid;
}

I just want to do

array<ref LB_BaseResponse> responses = ...;
JsonSerializer serial = new JsonSerializer();
string json;
serial.WriteToString(responses, false, json);
// Do something with the Json

Instead of looping through the entries and checking the class type for each of them etc.

Details

Severity
Feature
Resolution
Open
Reproducibility
Always
Operating System
Windows 7
Category
General

Event Timeline

LBmaster updated the task description. (Show Details)Jun 23 2023, 10:30 AM
Geez changed the task status from New to Assigned.Jun 28 2023, 11:57 AM