@SuppressWarnings("unchecked")
public <T extends Message> T convertJsonToProto(T prototype, String json, String extensionName) {
try {
Builder builder = prototype.newBuilderForType();
JsonFormat.parser().merge(json, builder);
return (T) builder.build();
} catch (InvalidProtocolBufferException ex) {
diagCollector.addDiag(
Diag.error(
new SimpleLocation(extensionName),
"Extension %s cannot be converted into proto type %s. Details: %s",
extensionName,
prototype.getDescriptorForType().getFullName(),
ex.getMessage()));
return prototype;
}
}
VendorExtensionProtoConverter.java 文件源码
java
阅读 26
收藏 0
点赞 0
评论 0
项目:api-compiler
作者:
评论列表
文章目录