https://spec.matrix.org/v1.17/client-server-api/#get_matrixclientv3devices_response-200_device
Fields not listed as required in the spec generally must be absent from the response when they are optional. In this case if a display_name is not set, it should be missing from the JSON, instead of being returned as a null value.
Incorrect
{
"device_id": "ABCDEF123",
"display_name": null,
"last_seen_ip": "127.0.0.1",
"last_seen_ts": 0
},
Correct
{
"device_id": "ABCDEF123",
"last_seen_ip": "127.0.0.1",
"last_seen_ts": 0
},
Wherever null is an allowed value, it is explicitly defined as part of the type, such as in this example.
Yeah the spec is a bit problematic
If following the spec, there is no documented way to remove a device name after it is set. Clients must effectively treat undefined (never set) and empty string as "no display name". During an update, omitting display_name results in no change.
Suggestion for compatibility
Start omitting display_name from the GET /_matrix/client/v3/devices response where it is currently null today, but still accept null in the PUT /_matrix/client/v3/devices/{deviceId} request for clients that may be relying on using null to unset the display_name in a non-compliant way.
E.g. if a client sends null for display_name, translate this to omitting display_name when GET /_matrix/client/v3/devices is called.
https://spec.matrix.org/v1.17/client-server-api/#get_matrixclientv3devices_response-200_device
Fields not listed as required in the spec generally must be absent from the response when they are optional. In this case if a display_name is not set, it should be missing from the JSON, instead of being returned as a null value.
Incorrect
Correct
Wherever null is an allowed value, it is explicitly defined as part of the type, such as in this example.
Yeah the spec is a bit problematic
If following the spec, there is no documented way to remove a device name after it is set. Clients must effectively treat
undefined(never set) and empty string as "no display name". During an update, omitting display_name results in no change.Suggestion for compatibility
Start omitting
display_namefrom theGET /_matrix/client/v3/devicesresponse where it is currentlynulltoday, but still accept null in thePUT /_matrix/client/v3/devices/{deviceId}request for clients that may be relying on usingnullto unset thedisplay_namein a non-compliant way.E.g. if a client sends
nullfordisplay_name, translate this to omittingdisplay_namewhenGET /_matrix/client/v3/devicesis called.