JsonFormat.printer().print(MessageOrBuilder) throws java.lang.NoSuchMethodError: com.google.protobuf.Any.getDescriptor()Lcom/google/protobuf/Descriptors$Descriptor;

75 views
Skip to first unread message

Milan Konzal

unread,
Oct 31, 2020, 6:34:13 PM10/31/20
to Protocol Buffers
Hi,
I try to print my protocol-buffer message as a Json, but I get allways an exception

java.lang.NoSuchMethodError: com.google.protobuf.Any.getDescriptor()Lcom/google/protobuf/Descriptors$Descriptor;
    at com.google.protobuf.util.JsonFormat$PrinterImpl.buildWellKnownTypePrinters(JsonFormat.java:783)
    at com.google.protobuf.util.JsonFormat$PrinterImpl.<clinit>(JsonFormat.java:777)
    at com.google.protobuf.util.JsonFormat$Printer.appendTo(JsonFormat.java:362)
    at com.google.protobuf.util.JsonFormat$Printer.print(JsonFormat.java:382)
    ...

My protocol-buffer message classes are generated by protoc version 3.13.0.
My protocol-buffer message classes are compiled with protobuf-java 3.13.0 and I use protobuf-util 3.13.0

My code:
Message msg = ConcreteMessage.newBuilder().build();
JsonFormat.printer().print(msg);

What is going wrong?

Thanks.

Milan Konzal

unread,
Nov 2, 2020, 10:50:28 PM11/2/20
to Protocol Buffers
In the project also protobuf-javalite was used by some library (in protobuf-javalite the class Any is from the same package, but it doesn't have the getDescriptor() method).

When protobuf-javalite was removed from classpath then everything works as expected.

It should be possible to use both (classic protobuf-java and lite protobuf-javalite) in one project (when class names from protobuf-javalite are different like MessageLite or the name of the package is different).
Reply all
Reply to author
Forward
0 new messages