问题描述
我有一个 json 文件转换为 protobuf 格式,在某些对象中带有空括号。你能帮我识别 protobuf 中的空对象(第一种情况)吗?我尝试使用字节大小,但对于一个好的对象,大小为 0,就像一个空。
加载数据
val json = // readFromJson
val protobufBuilder = Converted.newBuilder()
JsonFormat.parser.ignoringUnkNownFields.merge(json,protobufBuilder)
val converted = protobufBuilder.build()
输入
{
“a”: 0,“someObject”: {}
}
scala 代码
println(converted.hasSomeObject) // true
converted.getSomeObjectBytes.size() // 0
输入
{
“a”: 0,“someObject”: {
“type”: 1,“name”: “”Jack
}
}
scala
println(converted.hasSomeObject) // true
converted.getSomeObjectBytes.size() // 0
输入
{
“a”: 0
}
scala
println(converted.hasSomeObject) // false
converted.getSomeObjectBytes.size() // 0
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)