Skip to content

Commit fc2ca82

Browse files
author
tangyao
committed
fix: array encode can be null
1 parent 657896b commit fc2ca82

2 files changed

Lines changed: 53 additions & 0 deletions

File tree

lib/v1/encoder.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -394,6 +394,9 @@ proto.writeArray = function (arr) {
394394
var className = ''; // empty string meaning: `javaObject.DEFAULT_CLASSNAME.list`
395395
var realArray = arr;
396396
if (!isSimpleArray) {
397+
if (is.object(arr) && is.nullOrUndefined(arr.$)) {
398+
return this.writeNull();
399+
}
397400
var isComplexArray = is.object(arr) &&
398401
is.string(arr.$class) && is.array(arr.$);
399402
if (!isComplexArray) {

test/array.test.js

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
/**!
2+
* hessian.js - test/array.test.js
3+
*
4+
* Copyright(c) 2014-2015
5+
* MIT Licensed
6+
*
7+
* Authors:
8+
* 汤尧 <tangyao@gmail.com> (http://tangyao.me)
9+
*/
10+
11+
"use strict";
12+
13+
/**
14+
* Module dependencies.
15+
*/
16+
17+
var should = require('should');
18+
var hessian = require('../');
19+
20+
describe('array.test.js', function () {
21+
it('should write null v1', function () {
22+
var b = hessian.encode([
23+
{
24+
$class: '[java.lang.Integer',
25+
$: null
26+
},
27+
{
28+
$class: '[java.lang.Integer',
29+
$: [1]
30+
}
31+
]);
32+
var a = hessian.decode(b);
33+
a.should.eql([null, [1]]);
34+
});
35+
36+
it('should write null v2', function () {
37+
var b = hessian.encode([
38+
{
39+
$class: '[java.lang.Integer',
40+
$: null
41+
},
42+
{
43+
$class: '[java.lang.Integer',
44+
$: [1]
45+
}
46+
], '2.0');
47+
var a = hessian.decode(b, '2.0');
48+
a.should.eql([null, [1]]);
49+
});
50+
});

0 commit comments

Comments
 (0)