A list as a 'value type' in not supported for map. I have not worked with 
JavaScript and protobuf but I believe in the other languages, it will be a 
code generation error.

In general, I have had the similar problems you have when you need to come 
up with a particular json format which protobuf does not support. For 
example, you can not have a list of list. The 'workaround' in this scenario 
is to use

https://github.com/google/protobuf/blob/master/src/google/protobuf/struct.proto 

The library has special support the above proto file. I mention special 
support because even if you make a verbatim copy of the above proto message 
and use it, your json format would end up being different. 

For your use case, you'd want to set the oneof in the Value protobuf to the 
list. 


On Wednesday, July 5, 2017 at 8:06:23 AM UTC-7, al...@nvent.nl wrote:
>
> Hi everyone,
>
> I'm trying to produce a specific response format and I'm struggling with 
> the protobuf syntax to generate it. Worth mentioning, I'm new to protobuf 
> and am struggling a bit with the docs, so it's likely that I missed 
> something.
>
> The format I'm trying to produce, in json:
>
> {
>   success: false
>   errors: {
>     field1: ["error message 1", "error message 2"]
>     field2: []
>     ...fields
>   }
> }
>
> The proto syntax that I came up with looks like this:
> message ResponseSubmit {
>   bool success = 1
>   map<string, ErrorList> errors = 2
> }
>
> message ErrorList {
>   repeated string error = 1
> }
>
> Then, using the generated javascript libraries:
>
> const response = new ResponseSubmit();
> const errorsMap = response.getErrorsMap();
> const valid = true;
> const errors ={ field1: [], field2: ['Dummy error message'] };
>
> response.setSuccess(valid); // this works ok
>
> forEachObjIndexed((fieldErrors, fieldName) => {
>   errorsMap.set(fieldName, fieldErrors); // this blows up 
> });
>
> Adding a field to the map via the set method crashes with a TypeError: 
> b.toArray is not a function.
>
> Can anyone lend a hand and point me to what I'm doing wrong here?
>
> Thank you!
>
> Alex
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"Protocol Buffers" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to protobuf+unsubscr...@googlegroups.com.
To post to this group, send email to protobuf@googlegroups.com.
Visit this group at https://groups.google.com/group/protobuf.
For more options, visit https://groups.google.com/d/optout.

Reply via email to