Consider the following class:
public class ImageDataModel
{
public JsonObject CaptureResultData { get; }
public SmartphoneCommand SmartphoneCommand { get; }
public LightStageCommand LightStageCommand { get; }
public string TimeStamp { get; }
public ImageDataModel(string _captureResultData, LightStageCommand _lightStageCommand, SmartphoneCommand _smartphoneCommand)
{
CaptureResultData = JsonObject.Parse(_captureResultData);
SmartphoneCommand = _smartphoneCommand;
LightStageCommand = _lightStageCommand;
TimeStamp = DateTime.Now.ToString("HH:mm.ss, dd. MM. yyyy");
}
}
SmartphoneCommand
and LightStageCommand
are serializable objects, no problem with those. However, in the constructor, _captureResultData
is already a serialized JSON string of type JsonObject
. Since I want the data in the this string to show up as serialized object data instead of a single string within my JSON file, I made it into a JsonObject
.
The problem is, after serialization, the CaptureResult data shows up in the JSON file as follows:
"CaptureResultData": {
"android.control.afMode": {
"ValueType": 2
},
"android.colorCorrection.gains": {
"ValueType": 3
},
"android.control.awbMode": {
"ValueType": 2
},
"android.lens.focalLength": {
"ValueType": 2
},
"android.lens.focusDistance": {
"ValueType": 2
},
"android.control.aeMode": {
"ValueType": 2
},
"android.colorCorrection.mode": {
"ValueType": 2
},
"android.colorCorrection.transform": {
"ValueType": 3
},
"android.lens.aperture": {
"ValueType": 2
},
"android.sensor.sensitivity": {
"ValueType": 2
},
"android.sensor.exposureTime": {
"ValueType": 2
}
},
The original string contains the correct data. How can I force the serialization to show the actual data, instead of ValueType
?
For completeness, here is how the serialization is done:
using (StreamWriter jsonFile = File.CreateText(uniqueFilePaths[2]))
{
JsonSerializer serializer = new JsonSerializer
{
Formatting = Formatting.Indented,
ReferenceLoopHandling = ReferenceLoopHandling.Ignore
};
serializer.Serialize(jsonFile, new ImageDataModel(captureResultString, lightStageCommand, cameraCommand));
}