Closed
Description
When we have a union type with null
and a default value of null
, the serialisation
causes error at run time.
The schema. Here in we can see that we have union type with null
and default value null
.
{
"namespace": "atherenergy.vcu_cloud_connect",
"type": "record",
"name": "common",
"fields" : [
{"name": "can_id", "type": ["null", "string"], "default": null},
{"name": "data", "type": ["null", "string"], "default": null},
{"name": "value", "type": ["null", "string"], "default": null},
{"name": "key", "type": ["null", "string"], "default": null},
{"name": "timestamp", "type": ["null", "double"], "default": null},
{"name": "start_timestamp", "type": ["null", "string"],"default": null },
{"name": "end_timestamp", "type": ["null", "string"], "default": null},
{"name": "release_name", "type": ["null", "string"], "default": null},
{"name": "bms_version", "type":["null", "string"], "default": null},
{"name": "charger_version", "type":["null","string"], "default": null},
{"name": "sim_ccid", "type":["null", "string"], "default": null},
{"name": "sim_cimi", "type":["null", "string"], "default": null},
{"name":"mender_artifact_ver", "type":["null", "string"], "default": null},
{"name":"mcu_version", "type": ["null","string"], "default": null},
{"name": "vin", "type": ["null","string"], "default": null},
{"name": "bike_type", "type": ["null","string"], "default": null},
{"name": "motor_version", "type": ["null","string"], "default": null},
{"name": "system_boot_time", "type": ["null","string"], "default": null},
{"name": "mode", "type": ["null","int"], "default": null},
{"name": "ttff_s", "type": ["null","float"], "default": null},
{"name": "error_code", "type": ["null","string"], "default": null},
{"name": "is_valid", "type": ["null","int"], "default": null},
{"name": "ACC_X_MPS2", "type": ["null","float"], "default": null},
{"name": "ACC_Y_MPS2", "type": ["null","float"], "default": null},
{"name": "ACC_Z_MPS2", "type": ["null","float"], "default": null},
{"name": "GYR_X_DEG", "type": ["null","float"], "default": null},
{"name": "GYR_Y_DEG", "type": ["null","float"], "default": null},
{"name": "GYR_Z_DEG", "type": ["null","float"], "default": null}
]
}
let sample_data = r#"{
"ACC_X_MPS2": "33213.322",
"ACC_Y_MPS2": "323.909803",
"ACC_Z_MPS2": "2121.443",
"GYR_X_DEG": "2323.111",
"GYR_Y_DEG": "223.11274",
"GYR_Z_DEG": "3434.2211"
}"#;
let sample_imu = serde_json::from_str(imu_data).unwrap();
println!("{:?}", sample_imu);
let rec = Rr::from_json(sample_imu, &ss).unwrap();
This serialisation results in Err` value: DefaultValueParse