diff --git a/lib/v2/encoder.js b/lib/v2/encoder.js index be7dcc6..b2b8102 100644 --- a/lib/v2/encoder.js +++ b/lib/v2/encoder.js @@ -142,7 +142,7 @@ proto.writeInt = function (val) { * ``` */ proto.writeLong = function (val) { - if (typeof val !== 'number' && utility.isSafeNumberString(val)) { + if (typeof val !== 'number' && utility.isSafeNumberString(val + '')) { val = Number(val); } diff --git a/test/long.test.js b/test/long.test.js index 1ce594f..c43a517 100644 --- a/test/long.test.js +++ b/test/long.test.js @@ -46,6 +46,10 @@ describe('long.test.js', function () { hessian.encode(java.long(0)), new Buffer(['L'.charCodeAt(0), 0, 0, 0, 0, 0, 0, 0, 0]) ); + assert.deepEqual( + hessian.encode(Long.fromNumber(0)), + new Buffer(['L'.charCodeAt(0), 0, 0, 0, 0, 0, 0, 0, 0]) + ); }); it('should write and read equal java impl', function () {