Skip to content

jsonpb: does not support FieldMask #745

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
nodirt opened this issue Nov 7, 2018 · 6 comments
Closed

jsonpb: does not support FieldMask #745

nodirt opened this issue Nov 7, 2018 · 6 comments

Comments

@nodirt
Copy link

nodirt commented Nov 7, 2018

Go implementation of JSONPB does not support well-known proto type FieldMask, which has special JSON encoding.

What version of protobuf and what language are you using?
Version: ddf2292

What did you do?

package main

import (
	"fmt"

	"google.golang.org/genproto/protobuf/field_mask"

	"github.com/golang/protobuf/jsonpb"
)

func main() {
	fm := &field_mask.FieldMask{Paths: []string{"a", "b"}}
	m := &jsonpb.Marshaler{}
	marshaled, _ := m.MarshalToString(fm)
	fmt.Println(marshaled)
	// expected: "a,b"
	// actual: {paths: ["a", "b"]}

	fm = &field_mask.FieldMask{}
	marshaled = "a,b"
	err := jsonpb.UnmarshalString(marshaled, fm)
	fmt.Println("error:", err)
}

What did you expect to see?

"a,b"
nil

What did you see instead?

{"paths":["a","b"]}
error: invalid character 'a' looking for beginning of value
@dsnet dsnet changed the title FieldMask jsonpb marshalling/unmarshalling are incorrect jsonpb: does not support FieldMask Nov 7, 2018
@dsnet
Copy link
Member

dsnet commented Nov 7, 2018

Thanks for filing. I marked with with "api-v2" since I rewrote the jsonpb package and the new implementation handles this.

See https://go-review.googlesource.com/c/protobuf/+/134495/1/encoding/jsonpb/known.go#94

@peats-bond
Copy link

Can we get a status update on this? I think this may be better suited under a bug rather than an enhancement request.

@cybrcodr
Copy link
Contributor

This is implemented in v2, which we're not quite ready for a release yet. v1 will get the change when we update it to use v2 underneath. The release may take a while though.

@peats-bond
Copy link

Do you have any public documents discussing v2 timelines/details?

@cybrcodr
Copy link
Contributor

#364 (comment) provides links to v2 design details. We don't have published timelines. You can follow updates on our repo at https://go.googlesource.com/protobuf.

@dsnet
Copy link
Member

dsnet commented Mar 3, 2020

The new protojson package addresses this issue and has been released as part of google.golang.org/protobuf@v1.20.0. There are no plans to backport support of FieldMask to the older jsonpb implementation. Fixing it sadly breaks too many users who assume the incorrect behavior for FieldMask.

@dsnet dsnet closed this as completed Mar 3, 2020
@golang golang locked as resolved and limited conversation to collaborators Jun 26, 2020
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 a pull request may close this issue.

4 participants