go-kratos / kratos

Your ultimate Go microservices framework for the cloud-native era.
https://go-kratos.dev
MIT License
23.41k stars 4.01k forks source link

[Question] kratos generation pb file with omitempty tag #3427

Closed yyfyfyang closed 1 month ago

yyfyfyang commented 2 months ago
image

kratos proto client生成的pb文件带有omitempty标签导致序列化的时候会忽略空值和默认值,怎么样可以在生成pb文件的时候不带这个标签

kratos-ci-bot commented 2 months ago

Bot detected the issue body's language is not English, translate it automatically. 👯👭🏻🧑‍🤝‍🧑👫🧑🏿‍🤝‍🧑🏻👩🏾‍🤝‍👨🏿👬🏿


image

The pb file generated by kratos proto client has the omitempty tag, which causes the null value and default value to be ignored during serialization. How can I generate the pb file without this tag?

shenqidebaozi commented 1 month ago

This has nothing to do with kratos, it is the default behavior after compiling with protoc-gen-go, and it should not be removed. `protojson supports keeping null values.

shenqidebaozi commented 1 month ago

If you forcefully nested non proto structures outside the proto structure yourself, please refer to #1952