On Tue, Dec 20, 2016 at 9:31 AM, Ryan Oswald <[email protected]> wrote:

> The object keys used in generated 'toObject' methods are not consistent
> with field names.
>
>
> message ExampleMessage {
>   repeated OtherMessage *identifier *= 1;
> }
>
> The generated js toObject function produces an object with this form:
> {  *identifierList *: [...] }
>
>
> JSON parsing utilities (for example JsonFormat.parser().merge) expect
> something of this form:
> {  *identifier *: [...] }
>
>
> Superficially, the existing behavior may seem correct because key name is
> consistent with the generated js accessor function.  I would argue that
> this behavior is wrong.   Proto accessor functions vary significantly from
> language to language.  JSON (like proto) is actually a language-independent
> format. It makes much more sense to have a single cannonical
> language-independent JSON representation for proto objects.
>
The Java JsonFormat class implements proto3 JSON spec, whereas the
toObject() method in Javascript is just a legacy functionality that exists
before proto3 JSON, i.e., right now there is no proper proto3 JSON support
in Javascript. It's not feasible to change toObject() because it will break
existing toObject() users. I think we probably should introduce a
toJsonObject(). The timeline for proto3 JSON support in Javascript is TBD
though.


> --
> 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 [email protected].
> To post to this group, send email to [email protected].
> Visit this group at https://groups.google.com/group/protobuf.
> For more options, visit https://groups.google.com/d/optout.
>

-- 
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 [email protected].
To post to this group, send email to [email protected].
Visit this group at https://groups.google.com/group/protobuf.
For more options, visit https://groups.google.com/d/optout.

Reply via email to