ackerball / 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

(valid) empty object throws a ParseException #48

Open GoogleCodeExporter opened 8 years ago

GoogleCodeExporter commented 8 years ago
What steps will reproduce the problem?

1. download pjfeoi.tgz
2. extract it (tar -xzvf pjfeoi.tgz)
3. cd pjf_empty_object
4. make clean && make && make run

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

expected:

textJson: {"text":"foo"}
textPdu: {"text": "foo"}
authAckJson: {"authAck":{}}
authAckPdu: {"authAck": {}}

actual:

textJson: {"text":"foo"}
textPdu: {"text": "foo"}
authAckJson: {"authAck":{}}
com.googlecode.protobuf.format.JsonFormat$ParseException: 1:13: Expected 
identifier. -}
    at com.googlecode.protobuf.format.JsonFormat$Tokenizer.parseException(JsonFormat.java:765)
    at com.googlecode.protobuf.format.JsonFormat$Tokenizer.consumeIdentifier(JsonFormat.java:575)
    at com.googlecode.protobuf.format.JsonFormat.handleMissingField(JsonFormat.java:970)
    at com.googlecode.protobuf.format.JsonFormat.mergeField(JsonFormat.java:936)
    at com.googlecode.protobuf.format.JsonFormat.merge(JsonFormat.java:870)
    at com.googlecode.protobuf.format.JsonFormat.merge(JsonFormat.java:818)
    at com.chrisdew.Main.main(Main.java:26)
authAckPdu: {}

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

$ ls libs/protobuf*
libs/protobuf-2.5.0.jar  libs/protobuf-java-format-1.2.jar

$ java -version
java version "1.6.0_45"
Java(TM) SE Runtime Environment (build 1.6.0_45-b06)
Java HotSpot(TM) 64-Bit Server VM (build 20.45-b01, mixed mode)

$ cat /etc/lsb-release 
DISTRIB_ID=Ubuntu
DISTRIB_RELEASE=12.04
DISTRIB_CODENAME=precise
DISTRIB_DESCRIPTION="Ubuntu 12.04.2 LTS"

$ uname -a
Linux chris-work 3.2.0-45-generic #70-Ubuntu SMP Wed May 29 20:12:06 UTC 2013 
x86_64 x86_64 x86_64 GNU/Linux

Please provide any additional information below.

pjfeoi.proto:

package com.chrisdew.pjfeoi;

message Pdu {
  optional string  text     = 4;
  optional AuthAck auth_ack = 5;
}
message AuthAck {
}

Main.java:

package com.chrisdew;

import com.google.protobuf.UninitializedMessageException;
import com.googlecode.protobuf.format.JsonFormat;
import com.chrisdew.pjfeoi.Pjfeoi;

public class Main {
        public static void main(String[] args) {
                String textJson = "{\"text\":\"foo\"}";
                System.out.println("textJson: " + textJson);

                Pjfeoi.Pdu.Builder builderForText = Pjfeoi.Pdu.newBuilder();
                try {
                        JsonFormat.merge(textJson, builderForText);
                } catch (JsonFormat.ParseException e) {
                        e.printStackTrace();
                }
                Pjfeoi.Pdu textPdu = builderForText.build();
                System.out.println("textPdu: " + JsonFormat.printToString(textPdu));

                String authAckJson = "{\"authAck\":{}}";
                System.out.println("authAckJson: " + authAckJson);

                Pjfeoi.Pdu.Builder builderForAuthAck = Pjfeoi.Pdu.newBuilder();
                try {
                        JsonFormat.merge(authAckJson, builderForAuthAck);
                } catch (JsonFormat.ParseException e) {
                        e.printStackTrace();
                }
                Pjfeoi.Pdu authAckPdu = builderForAuthAck.build();
                System.out.println("authAckPdu: " + JsonFormat.printToString(authAckPdu));
        }
}

Original issue reported on code.google.com by cms...@gmail.com on 7 Aug 2013 at 8:51

Attachments:

GoogleCodeExporter commented 8 years ago
Sorry, wrong tgz name:

What steps will reproduce the problem?

1. download pjf_empty_object.tgz
2. extract it (tar -xzvf pjf_empty_object.tgz)
3. cd pjf_empty_object
4. make clean && make && make run

Original comment by cms...@gmail.com on 7 Aug 2013 at 8:55

GoogleCodeExporter commented 8 years ago
This is not a bug, it's an incompatibility between the Javascript generated by 
protobuf for NodeJS - https://github.com/chrisdew/protobuf/ and the parser 
here, if you use the recommended snake_case field names.

protobuf for NodeJS generates camelCase field names from the snake_case field 
names recommended by the protobuf docs.

You can work around it by ignoring the protobuf recommendations for field names 
and using camelCase in the .proto files.

I've raised this as 
https://code.google.com/p/protobuf-java-format/issues/detail?id=49

Please close this ticket.

Original comment by cms...@gmail.com on 7 Aug 2013 at 10:48