anydoby / protobuf-java-format

Automatically exported from code.google.com/p/protobuf-java-format
BSD 3-Clause "New" or "Revised" License
0 stars 0 forks source link

Using protobuf extensions generates invalid JSON #17

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?
1. Create an extensible message
2. Create an extension
3. Instantiate both and initialize the extensible instance with an extension 
instance
4. Serialize to JSON.

What is the expected output? What do you see instead?

Using this .proto descriptor:

message Foo {
  required uint32 foo = 1;
  extensions 100 to max;
}

message Bar {
  required uint32 bar = 1;
  extend Foo {
    optional Bar bar_ext = 100;
  }
}

Instantiate and serialize:

FooBar.Bar bar = FooBar.Bar.newBuilder().setBar(42).build();
JsonFormat.printToString(
  FooBar.Foo.newBuilder()
    .setFoo(4)
    .setExtension(FooBar.Bar.barExt, 
       FooBar.Bar.newBuilder()
        .setBar(42).build()
    )
);

Expected:
{"foo": 4,"Bar.bar_ext": {"bar": 42}}

Actual:
{"foo": 4,["Bar.bar_ext"]: {"bar": 42}}

What version of the product are you using? On what operating system?

protobuf-java-format-1.1

Please provide any additional information below.

Original issue reported on code.google.com by philippe...@gmail.com on 6 Jul 2010 at 8:12

Attachments:

GoogleCodeExporter commented 9 years ago
Ooops... there's an unnecessary FooBar.Bar instance and missing build() call in 
the example above. Use this to reproduce:

JsonFormat.printToString(
  FooBar.Foo.newBuilder()
    .setFoo(4)
    .setExtension(FooBar.Bar.barExt, 
       FooBar.Bar.newBuilder()
        .setBar(42).build()
    ).build()
);

Original comment by philippe...@gmail.com on 6 Jul 2010 at 8:15

GoogleCodeExporter commented 9 years ago

Original comment by eliran.bivas on 21 Apr 2011 at 2:35

GoogleCodeExporter commented 9 years ago
Fixed by r47.

Original comment by philippe...@gmail.com on 26 Apr 2011 at 8:20