File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff 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 ) {
Original file line number Diff line number Diff line change 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+ } ) ;
You can’t perform that action at this time.
0 commit comments