You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository was archived by the owner on Dec 15, 2025. It is now read-only.
Repository navigation
This repository was archived by the owner on Dec 15, 2025. It is now read-only.
Marshal / Unmarshal - time.Time to timestamppb #694
Here is an example of what I'm facing as problem, some others have said to use protojson to unmarshall into a proto message but that is not what I need.
package main
import (
"fmt"
"time"
jsoniter "github.com/json-iterator/go"
"google.golang.org/protobuf/runtime/protoimpl"
"google.golang.org/protobuf/types/known/timestamppb"
)
type Test struct {
Id string `json:"id,omitempty"`
ExpiresOn time.Time `json:"expiresOn,omitempty"`
}
type TestPB struct {
state protoimpl.MessageState
sizeCache protoimpl.SizeCache
unknownFields protoimpl.UnknownFields
Id string `protobuf:"bytes,1,opt,name=id,proto3" json:"id,omitempty"`
ExpiresOn *timestamppb.Timestamp `protobuf:"bytes,2,opt,name=expiresOn,proto3" json:"expiresOn,omitempty"`
}
func main() {
u := Test{Id: "123", ExpiresOn: time.Now()}
b, err := jsoniter.Marshal(u)
if err != nil {
panic(err)
}
var m TestPB
err = jsoniter.Unmarshal(b, &m)
if err != nil {
panic(err)
}
fmt.Printf("PB is %v", m)
}
Activity
[-]Marshal / Unmarshal - time.Time to timestamppb[/-][-]Marshal / Unmarshal - time.Time[/-]go-aegian commentedon Feb 16, 2024
Here is an example of what I'm facing as problem, some others have said to use protojson to unmarshall into a proto message but that is not what I need.