protobuf.js
protobuf.js copied to clipboard
fromObject force assign unset array field with empty array
protobuf.js version: 6.11.2
when transfer a JSON payload to message object using fromObject, message force assign unset array field with empty array.
expected unset field no change.
const protobuf = require('protobufjs');
const root = protobuf.loadSync('test.proto');
const Type = root.lookupType('TestArray');
const request = {name: 'test'};
const message = Type.fromObject(request)
console.log(message) // --> output: TestArray { allowed: [], name: 'test' } --> expected: TestArray{name:'test}
console.log(message.name === request.name)// --> output:true
console.log(request.allowed === undefined)// --> output:true
console.log(message.allowed.length === 0)// --> output: true
--- test.proto
message TestArray {
string name = 1;
repeated Allowed allowed = 2;
}
message Allowed {
optional string content = 1;
}
Did you solve this problem? I found fromObject will push data to prototype like this
I think i could delete it to solve this problem