Skip to content

discussion: should we de-serialize null to empty List/Map in response #3134

@weidongxu-microsoft

Description

@weidongxu-microsoft

Current code

    private List<FailoverPolicy> failoverPolicies;

                } else if ("failoverPolicies".equals(fieldName)) {
                    List<FailoverPolicy> failoverPolicies
                        = reader.readArray(reader1 -> FailoverPolicy.fromJson(reader1));
                    deserializedDatabaseAccountGetProperties.failoverPolicies = failoverPolicies;

If backend returns null or the property is not included in response, the failoverPolicies would be null.

Should we instead set the failoverPolicies to be empty list, in such case?

PS: I think we don't want to affect serialization. If user does not set the property, we should not send an empty JSON array to backend.


My concern on this, is that the model class generally reflect what service's response payload. (we can and does have convenience API to wrap this and return empty list, but this would be another story)

Service could use "this property not in response" and "this property in response and is []" to signify different scenario (so far, I am not aware of service does this -- but this could just due to my ignorance).
And SDK may not want to override the service payload.

The only safe case is that the property is "required". But this is not true in cosmos-db Swagger.

Metadata

Metadata

Assignees

No one assigned

    Labels

    DPGMgmtThis issue is related to a management-plane library.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions