@@ -161,12 +161,35 @@ describe('map.test.js', function () {
161161 } ) ;
162162 } ) ;
163163
164+ it ( 'should decode successful when key is null' , function ( ) {
165+ var data = new Buffer ( [ 77 , 116 , 0 , 0 , 78 , 83 , 0 , 4 , 110 , 117 , 108 , 108 , 122 ] ) ;
166+ var rv = hessian . decode ( data ) ;
167+ rv . should . eql ( { null : 'null' } ) ;
168+ } ) ;
169+
164170 it ( 'should write es6 Map to java.util.Map' , function ( ) {
165171 if ( typeof Map !== 'function' ) {
166172 // pass if not support es6 Map
167173 return ;
168174 }
169175
176+ var map = new Map ( ) ;
177+ map . set ( { '$class' : 'java.lang.Long' , '$' : 123 } , 123456 ) ;
178+ map . set ( { '$class' : 'java.lang.Long' , '$' : 123456 } , 123 ) ;
179+ var buf = hessian . encode ( { '$class' : 'java.util.Map' , '$' : map } ) ;
180+ // decode auto transfer key to string
181+ hessian . decode ( buf ) . should . eql ( {
182+ '123' : 123456 ,
183+ '123456' : 123
184+ } ) ;
185+ } ) ;
186+
187+ it ( 'should write es6 Map to java.util.HashMap' , function ( ) {
188+ if ( typeof Map !== 'function' ) {
189+ // pass if not support es6 Map
190+ return ;
191+ }
192+
170193 var map = new Map ( ) ;
171194 map . set ( { '$class' : 'java.lang.Long' , '$' : 123 } , 123456 ) ;
172195 map . set ( { '$class' : 'java.lang.Long' , '$' : 123456 } , 123 ) ;
@@ -344,37 +367,49 @@ describe('map.test.js', function () {
344367 } ) ;
345368
346369 } ) ;
347-
348- } ) ;
349370
350- it ( 'should decode successful when key is null' , function ( ) {
351- var data = new Buffer ( [ 77 , 116 , 0 , 0 , 78 , 83 , 0 , 4 , 110 , 117 , 108 , 108 , 122 ] ) ;
352- var rv = hessian . decode ( data ) ;
353- rv . should . eql ( { null : 'null' } ) ;
354- } ) ;
371+ it ( 'should write es6 Map to java.util.Map' , function ( ) {
372+ if ( typeof Map !== 'function' ) {
373+ // pass if not support es6 Map
374+ return ;
375+ }
376+
377+ var map = new Map ( ) ;
378+ map . set ( { '$class' : 'java.lang.Long' , '$' : 123 } , 123456 ) ;
379+ map . set ( { '$class' : 'java.lang.Long' , '$' : 123456 } , 123 ) ;
380+ var buf = hessian . encode ( { '$class' : 'java.util.Map' , '$' : map } , '2.0' ) ;
381+ // decode auto transfer key to string
382+ hessian . decode ( buf , '2.0' ) . should . eql ( {
383+ '123' : 123456 ,
384+ '123456' : 123
385+ } ) ;
386+ } ) ;
355387
356- it ( 'should write es6 Map to java.util.Map ' , function ( ) {
357- if ( typeof Map !== 'function' ) {
358- // pass if not support es6 Map
359- return ;
360- }
388+ it ( 'should write es6 Map to java.util.HashMap ' , function ( ) {
389+ if ( typeof Map !== 'function' ) {
390+ // pass if not support es6 Map
391+ return ;
392+ }
361393
362- var map = new Map ( ) ;
363- map . set ( { '$class' : 'java.lang.Long' , '$' : 123 } , 123456 ) ;
364- map . set ( { '$class' : 'java.lang.Long' , '$' : 123456 } , 123 ) ;
365- var encoder = new hessian . EncoderV2 ( ) ;
366- var buf = encoder . write ( map ) . get ( ) ;
367- buf . should . eql ( utils . bytes ( 'v2/map/generic' ) ) ;
394+ var map = new Map ( ) ;
395+ map . set ( { '$class' : 'java.lang.Long' , '$' : 123 } , 123456 ) ;
396+ map . set ( { '$class' : 'java.lang.Long' , '$' : 123456 } , 123 ) ;
397+ var encoder = new hessian . EncoderV2 ( ) ;
398+ var buf = encoder . write ( map ) . get ( ) ;
399+ buf . should . eql ( utils . bytes ( 'v2/map/generic' ) ) ;
368400
369- encoder . reset ( ) ;
401+ encoder . reset ( ) ;
370402
371- buf = encoder . write ( { '$class' : 'java.util.HashMap' , '$' : map } ) . get ( ) ;
372- buf . should . eql ( utils . bytes ( 'v2/map/generic' ) ) ;
403+ buf = encoder . write ( { '$class' : 'java.util.HashMap' , '$' : map } ) . get ( ) ;
404+ buf . should . eql ( utils . bytes ( 'v2/map/generic' ) ) ;
373405
374- // decode auto transfer key to string
375- hessian . decode ( utils . bytes ( 'v2/map/generic' ) , '2.0' ) . should . eql ( {
376- '123' : 123456 ,
377- '123456' : 123
406+ // decode auto transfer key to string
407+ hessian . decode ( utils . bytes ( 'v2/map/generic' ) , '2.0' ) . should . eql ( {
408+ '123' : 123456 ,
409+ '123456' : 123
410+ } ) ;
378411 } ) ;
412+
379413 } ) ;
414+
380415} ) ;
0 commit comments