@@ -161,6 +161,23 @@ describe('map.test.js', function () {
161161 } ) ;
162162 } ) ;
163163
164+ it ( 'should write es6 Map to java.util.Map' , function ( ) {
165+ var map = new Map ( ) ;
166+ map . set ( { '$class' : 'java.lang.Long' , '$' : 123 } , 123456 ) ;
167+ map . set ( { '$class' : 'java.lang.Long' , '$' : 123456 } , 123 ) ;
168+ var buf = hessian . encode ( map ) ;
169+ buf . should . eql ( utils . bytes ( 'v1/map/generic' ) ) ;
170+
171+ buf = hessian . encode ( { '$class' : 'java.util.HashMap' , '$' : map } ) ;
172+ buf . should . eql ( utils . bytes ( 'v1/map/generic' ) ) ;
173+
174+ // decode auto transfer key to string
175+ hessian . decode ( utils . bytes ( 'v1/map/generic' ) , '1.0' ) . should . eql ( {
176+ '123' : 123456 ,
177+ '123456' : 123
178+ } ) ;
179+ } ) ;
180+
164181 describe ( 'v2.0' , function ( ) {
165182 // map = new HashMap();
166183 // map.put(new Integer(1), "fee");
@@ -330,4 +347,24 @@ describe('map.test.js', function () {
330347 var rv = hessian . decode ( data ) ;
331348 rv . should . eql ( { null : 'null' } ) ;
332349 } ) ;
350+
351+ it ( 'should write es6 Map to java.util.Map' , function ( ) {
352+ var map = new Map ( ) ;
353+ map . set ( { '$class' : 'java.lang.Long' , '$' : 123 } , 123456 ) ;
354+ map . set ( { '$class' : 'java.lang.Long' , '$' : 123456 } , 123 ) ;
355+ var encoder = new hessian . EncoderV2 ( ) ;
356+ var buf = encoder . write ( map ) . get ( ) ;
357+ buf . should . eql ( utils . bytes ( 'v2/map/generic' ) ) ;
358+
359+ encoder . reset ( ) ;
360+
361+ buf = encoder . write ( { '$class' : 'java.util.HashMap' , '$' : map } ) . get ( ) ;
362+ buf . should . eql ( utils . bytes ( 'v2/map/generic' ) ) ;
363+
364+ // decode auto transfer key to string
365+ hessian . decode ( utils . bytes ( 'v2/map/generic' ) , '2.0' ) . should . eql ( {
366+ '123' : 123456 ,
367+ '123456' : 123
368+ } ) ;
369+ } ) ;
333370} ) ;
0 commit comments