Skip to content
This repository was archived by the owner on Sep 9, 2026. It is now read-only.

Fix JSON encoding of Any - #60

Merged
jhernand merged 1 commit into
osac-project:mainfrom
jhernand:fix_json_encoding_of_any
Jul 7, 2025
Merged

jhernand merged 1 commit into
osac-project:mainfrom
jhernand:fix_json_encoding_of_any

Conversation

@jhernand

@jhernand jhernand commented Jul 4, 2025

Copy link
Copy Markdown
Contributor

The protobuf Any type should be converted to the corresponding JSON type, but our custom encoder doesn't do that, instead it converts its fields. For example, an object created like this:

object, err := anypb.New(wrapperspb.Bool(true))

Results in the following JSON:

{
  "type_url": "type.googleapis.com/google.protobuf.BoolValue"
  "value": "CAE=",
}

But it should instead produce this:

{
  "@type": "type.googleapis.com/google.protobuf.BoolValue"
  "value": true
}

This patch fixes that issue modifying our encoder so that it calls the protobuf one for well known types like Any and Timestamp.

The protobuf `Any` type should be converted to the corresponding JSON
type, but our custom encoder doesn't do that, instead it converts its
fields. For example, an object created like this:

```go
object, err := anypb.New(wrapperspb.Bool(true))
```

Results in the following JSON:

```json
{
  "type_url": "type.googleapis.com/google.protobuf.BoolValue"
  "value": "CAE=",
}
```

But it should instead produce this:

```json
{
  "@type": "type.googleapis.com/google.protobuf.BoolValue"
  "value": true
}
```

This patch fixes that issue modifying our encoder so that it calls the
protobuf one for well known types like `Any` and `Timestamp`.

Signed-off-by: Juan Hernandez <juan.hernandez@redhat.com>
@jhernand
jhernand merged commit 31cc180 into osac-project:main Jul 7, 2025
@jhernand
jhernand deleted the fix_json_encoding_of_any branch July 7, 2025 08:21
@rgolangh rgolangh mentioned this pull request Jun 18, 2026
8 tasks done
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants