How to set null value in map type

34 views
Skip to first unread message

Shenghe Wang

unread,
May 30, 2024, 10:40:45 AMMay 30
to Protocol Buffers
Hi,

I want to set an int field to 'null' when user want to clear some choice but nullpointerexception was threw. I use map<string, string> to store the data which will be updated. But map do not accept null value. Is there any way to store the null value into a map? 

Thanks a lot

Jeff Sawatzky

unread,
May 31, 2024, 10:11:19 AMMay 31
to Protocol Buffers
As far as I am aware, a string is a scalar so you can't set it to null.

So if you have a map<string, string> then both the keys and values can not be null.

You may be able to try using the StringValue type from the Well-Known Types:

using a map<string, StringValue>, and most integrations will convert the StringValue to a simple nullable string.
Reply all
Reply to author
Forward
0 new messages