json - 在 protobuf 中使用空括号验证对象
问题描述
我有一个 json 文件转换为 protobuf 格式,在某些对象中有空括号。您能帮我识别 protobuf 中的空对象(第一种情况)吗?我尝试使用字节大小,但对于一个好的对象,大小为 0,就像一个空的。
加载数据
val json = // readFromJson
val protobufBuilder = Converted.newBuilder()
JsonFormat.parser.ignoringUnknownFields.merge(json, protobufBuilder)
val converted = protobufBuilder.build()
输入
{
“a”: 0,
“someObject”: {}
}
代码
println(converted.hasSomeObject) // true
converted.getSomeObjectBytes.size() // 0
输入
{
“a”: 0,
“someObject”: {
“type”: 1,
“name”: “”Jack
}
}
斯卡拉
println(converted.hasSomeObject) // true
converted.getSomeObjectBytes.size() // 0
输入
{
“a”: 0
}
斯卡拉
println(converted.hasSomeObject) // false
converted.getSomeObjectBytes.size() // 0
解决方案
推荐阅读
- kubernetes - 无法确保 ip set: &{{KUBE-NODE-PORT-TCP ...} 存在,错误:创建 ipset KUBE-NODE-PORT-TCP 时出错,错误:退出状态 2
- webpack - 如何使用来自 AWS Lambda 的 webpack 提供一个缩小的 express 应用程序
- javascript - 根据是否存在下拉菜单在 bootstrap4 下拉菜单上显示或隐藏插入符号图标
- c# - 是否可以通过在运行时选择不同的 .net 框架在单台机器上运行应用程序?
- mysql - 查询两个具有相同列名的表的匹配记录
- xml - XSLT for-each 循环遍历 2 个具有相同名称但不同属性的元素
- c# - 无法解析 JSON Schema 并解析引用
- configuration - ALSA:asound.conf 文件已读取但未与 arecord 一起使用
- asp.net - ASP NET WebForms 中的 AJAX 字段验证器
- sql-server - SQL中的while循环替换