Skip to content
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

jsonpb doesn't decode proto3 string enums #59

Closed
maxhawkins opened this issue Aug 11, 2015 · 5 comments
Closed

jsonpb doesn't decode proto3 string enums #59

maxhawkins opened this issue Aug 11, 2015 · 5 comments
Assignees

Comments

@maxhawkins
Copy link

Using the jsonpb package, I can marshal a proto3 message to JSON with enums as strings.

However, I cannot go in the reverse direction. The Unmarshal function returns an error when I try to unmarshal JSON with string enums.

I expected this to work how it does with proto2 messages.

Failing round-trip example here:

package main

import (
    "github.com/golang/protobuf/jsonpb"
    pb "github.com/golang/protobuf/proto/proto3_proto"
)

func main() {
    msg := &pb.Message{Hilarity: pb.Message_SLAPSTICK}

    marshaller := jsonpb.Marshaller{EnumsAsString: true}
    data, _ := marshaller.MarshalToString(msg)

    if err := jsonpb.UnmarshalString(data, msg); err != nil {
        panic(err)
    }
}

This code panics with json: cannot unmarshal string into Go value of type proto3_proto.Message_Humour.

@dsymonds
Copy link
Contributor

In the (unpublished) spec, only the symbolic names are supported, but we should definitely permit round-tripping what we can produce.

@marcinwyszynski
Copy link

I believe this is still happening for repeated enum fields.

@dsymonds
Copy link
Contributor

Can you please file a new issue for that, preferably with a reproduction case?

@marcinwyszynski
Copy link

Will do. I think I can spend some time on a fix, too.

@dinowernli
Copy link

FYI, I've opened #163 to fix the repeated enum thing.

@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

No branches or pull requests

4 participants