protobuf对象不能直接使用jsonlib去转,因为protobuf生成的对象的get方法返回的类型有byte[],而只有String类型可以作为json的key,protobuf提供方法进行转换。
引用maven依赖:
?
|
1
2
3
4
5
|
<dependency>
<groupId>com.googlecode.protobuf-java-format</groupId>
<artifactId>protobuf-java-format</artifactId>
<version>1.2</version>
</dependency>
|
?
|
1
|
String jsonFormat = JsonFormat.printToString(SomeProto);
|

