Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/v2/encoder.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 + '')) {
Copy link
Member

@fengmk2 fengmk2 Aug 2, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

detect val is not equal string first.

if (typeof val !== 'number') {
  if (typeof val !== 'string') {
    val = val + '';
  }
  if (utility.isSafeNumberString(val)) {
    val = Number(val);
  }
}

val = Number(val);
}

Expand Down
4 changes: 4 additions & 0 deletions test/long.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 () {
Expand Down