Cannot find type for url when using JSONFormat.printer()

2,892 views
Skip to first unread message

Michael Lindenmayer

unread,
Jan 12, 2017, 12:01:18 PM1/12/17
to Protocol Buffers
I am having some trouble creating a message and printing it to JSON using the any type. Below is the code that is run:


      Any any = Any.pack(myMessage);
      
      String jsonFormat = JsonFormat.printer().print(any);

This thrown an exception: Cannot find type for url: type.googleapis.com/org.apache.activemq.recipies.messages.MyMessage

I feel like the mistake is simple, but I can't seem to figure it out.

Any help would be appreciated!!!

Michael

Feng Xiao

unread,
Jan 12, 2017, 1:54:20 PM1/12/17
to Michael Lindenmayer, Protocol Buffers
To print Any in JSON, you need to provide a TypeRegistry including the descriptor of all types that may be included in the Any field. See an example here:

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

Michael Lindenmayer

unread,
Jan 12, 2017, 5:21:15 PM1/12/17
to Protocol Buffers, mikeli...@gmail.com
Thanks, that did the trick, I didn't see anything about that in the proto guides, thank you!!!

Mike


On Thursday, January 12, 2017 at 1:54:20 PM UTC-5, Feng Xiao wrote:
To print Any in JSON, you need to provide a TypeRegistry including the descriptor of all types that may be included in the Any field. See an example here:
On Thu, Jan 12, 2017 at 9:01 AM, Michael Lindenmayer <mikeli...@gmail.com> wrote:
I am having some trouble creating a message and printing it to JSON using the any type. Below is the code that is run:


      Any any = Any.pack(myMessage);
      
      String jsonFormat = JsonFormat.printer().print(any);

This thrown an exception: Cannot find type for url: type.googleapis.com/org.apache.activemq.recipies.messages.MyMessage

I feel like the mistake is simple, but I can't seem to figure it out.

Any help would be appreciated!!!

Michael

--
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+u...@googlegroups.com.

Srinivasa Rao Chirathanagandla

unread,
Jul 24, 2019, 6:13:21 PM7/24/19
to Protocol Buffers
Thank you Feng, that solved my issue as well.


On Thursday, January 12, 2017 at 10:54:20 AM UTC-8, Feng Xiao wrote:
To print Any in JSON, you need to provide a TypeRegistry including the descriptor of all types that may be included in the Any field. See an example here:
On Thu, Jan 12, 2017 at 9:01 AM, Michael Lindenmayer <mikeli...@gmail.com> wrote:
I am having some trouble creating a message and printing it to JSON using the any type. Below is the code that is run:


      Any any = Any.pack(myMessage);
      
      String jsonFormat = JsonFormat.printer().print(any);

This thrown an exception: Cannot find type for url: type.googleapis.com/org.apache.activemq.recipies.messages.MyMessage

I feel like the mistake is simple, but I can't seem to figure it out.

Any help would be appreciated!!!

Michael

--
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 prot...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages