Protoman icon indicating copy to clipboard operation
Protoman copied to clipboard

The enum type under proto3 will report an error.

Open freshcn opened this issue 5 years ago • 7 comments

The enum type under proto3 will report an error.

Error: Error while parsing the JSON representation of the protobuf message:
Expected 'number', but got 'string'

freshcn avatar Jul 26 '20 16:07 freshcn

Hmm that's strange. To best of my knowledge, enum values in protobuf are serialized as numbers rather than strings. Could you provide me a snippet of the .proto file and how you're constructing your message?

spluxx avatar Jul 27 '20 03:07 spluxx

I have two .proto file

backend/server/status/get.proto

syntax = "proto3";
package backend.server.status;

option go_package = "backend/app/pb/server/status";

import "backend/public/responseHead.proto";
import "backend/public/platform.proto";

message GetResponse {
    backend.public.ResponseHead head = 1;
    backend.public.Platform platform = 2;
}

backend/public/platform.proto

syntax = "proto3";
package backend.public;

option go_package = "backend/app/pb/public";

enum Platform {
    PLATFORM_EMAIL = 0;
    PLATFORM_WXMINI = 1;
    PLATFORM_WXH5 = 2;
    PLATFORM_MOBILE = 3;
}

An error occurred on the platform in GetResponse

freshcn avatar Jul 27 '20 03:07 freshcn

Hmm that's strange. I'll double check to see what's going on. Thank you!

spluxx avatar Jul 30 '20 04:07 spluxx

@spluxx any updates on this ? I am facing the same issue.

codingforeternity avatar Oct 31 '20 03:10 codingforeternity

Same here

ahmad-pepperstone avatar May 31 '22 19:05 ahmad-pepperstone

@spluxx any updates on this ? I am facing the same issue.

got the solution?

umarfarooq-del avatar Sep 27 '22 05:09 umarfarooq-del

I'm running into this issue too (v0.4.0 on Windows 10). Even an enum with a single option will cause issues:

syntax = "proto3";
package enumtest;

message MyObject {
  enum MessageType {
    MY_MESSAGE_TYPE = 0;
  }
  MessageType message_type = 1;
}

Here I encoded { messageType: 0 }:

image

I noticed if messageType is out of range, it will use the enum default (here MY_MESSAGE_TYPE) with no error. Here I encoded { messageType: 15 }:

image

Going to look into this a bit later, but at least the data can be verified in the readout window below the error message for now.

benjaminwilsonvirbela avatar Oct 12 '22 18:10 benjaminwilsonvirbela