Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Feb 3, 2026

google.protobuf.Any types were marshaling to JSON without the required @type field, causing deserialization failures. The deprecated github.com/golang/protobuf/jsonpb package doesn't emit this field per spec.

Changes

Migrated JSON codecs to google.golang.org/protobuf/encoding/protojson:

  • codec/json/marshaler.go - Use protojson.MarshalOptions
  • codec/json/json.go - Use protojson.Marshal/Unmarshal for proto messages
  • server/grpc/codec.go - Use protojson for JSON codec operations

Binary proto codec unchanged:

  • codec/proto/* - Retained github.com/golang/protobuf/proto for backward compatibility
  • Binary serialization doesn't involve Any type JSON issues

Example

After fix, Any types produce spec-compliant JSON:

anyMsg, _ := anypb.New(wrapperspb.String("test"))
data, _ := json.Marshaler{}.Marshal(anyMsg)
// Before: {"value":"test"}  ❌ missing @type
// After:  {"@type":"type.googleapis.com/google.protobuf.StringValue","value":"test"}  ✓

The @type field enables proper type identification during unmarshaling.

Warning

Firewall rules blocked me from connecting to one or more addresses (expand for details)

I tried to connect to the following addresses, but was blocked by firewall rules:

  • 224.0.0.251
    • Triggering command: REDACTED, pid is -1 (packet block)

If you need me to access, download, or install something from one of these locations, you can either:

Original prompt

This section details on the original issue you should resolve

<issue_title>[BUG] protoc use google.protobuf.Any error</issue_title>
<issue_description>## Describe the bug

using resp protoc is google.protobuf.Any

error:Any JSON doesn't have '@type'

How to reproduce the bug

Any JSON doesn't have '@type'

Environment

Go Version: 1.24.0

set GOHOSTARCH=amd64
set GOHOSTOS=windows

</issue_description>

<agent_instructions>---
using resp protoc is google.protobuf.Any

error:Any JSON doesn't have '@type'

Is there a fix for this?</agent_instructions>

Comments on the Issue (you are @copilot in this section)

@asim Is there a solution to this?

💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

Copilot AI and others added 2 commits February 3, 2026 16:03
Co-authored-by: asim <17530+asim@users.noreply.github.com>
Co-authored-by: asim <17530+asim@users.noreply.github.com>
Copilot AI changed the title [WIP] Fix error for protoc with google.protobuf.Any Fix google.protobuf.Any JSON marshaling missing @type field Feb 3, 2026
Copilot AI requested a review from asim February 3, 2026 16:09
Co-authored-by: asim <17530+asim@users.noreply.github.com>
@asim asim marked this pull request as ready for review February 4, 2026 09:33
@asim asim merged commit a100a47 into master Feb 4, 2026
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[BUG] protoc use google.protobuf.Any error

2 participants