protobuf-net / protobuf-net.Grpc

GRPC bindings for protobuf-net and grpc-dotnet
Other
846 stars 106 forks source link

Empty List converted to null? #315

Closed Roy-se7en closed 8 months ago

Roy-se7en commented 8 months ago

if the server return the data (include the empty list), the client receive the list is null?

mgravell commented 8 months ago

In the protobuf wire format, there is no distinction between "null" and "empty", nor any concept of "null" at all. By default, then, protobuf-net:

This means that by default, your collection will be whatever your type initializes it as. A common approach is to initialize as empty:

[ProtoMember(42)]
public List<Foo> Foos {get;} = new();

For explicit null support, allowing nulls to be represented separately to empty (for both elements and the collection, separately), see: https://protobuf-net.github.io/protobuf-net/nullwrappers

Roy-se7en commented 8 months ago

Thanks for your reply!