diff --git a/src/node/src/protobuf_js_6_common.js b/src/node/src/protobuf_js_6_common.js index cac0f711451..21eddabaa8a 100644 --- a/src/node/src/protobuf_js_6_common.js +++ b/src/node/src/protobuf_js_6_common.js @@ -77,11 +77,11 @@ exports.serializeCls = function serializeCls(cls) { * @return {Buffer} The serialized object */ return function serialize(arg) { - var message = cls.fromObject(arg); - var errMsg = cls.verify(message); + var errMsg = cls.verify(arg); if (errMsg) { throw Error(errMsg); } + var message = cls.create(arg); return cls.encode(message).finish(); }; }; diff --git a/src/node/test/common_test.js b/src/node/test/common_test.js index 39ff6a5f1fc..e1ce864f975 100644 --- a/src/node/test/common_test.js +++ b/src/node/test/common_test.js @@ -176,7 +176,7 @@ describe('Proto message oneof serialize and deserialize', function() { var test_message2 = {oneof_choice: 'string_choice', string_choice: 'abc'}; var serialized2 = oneofSerialize(test_message2); var deserialized2 = oneofDeserialize(serialized2); - assert.equal(deserialized2.oneof_choice, 'int_choice'); + assert.equal(deserialized2.oneof_choice, 'string_choice'); }); }); describe('Proto message enum serialize and deserialize', function() {