File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -529,10 +529,7 @@ proto.readList = proto.readArray;
529529proto . readRef = function ( withType ) {
530530 var rid = this . readRefId ( ) ;
531531 var obj = this . refMap [ rid ] ;
532- if ( ! withType && obj && utils . hasOwnProperty ( obj , '$' ) ) {
533- obj = obj . $ ;
534- }
535- return obj ;
532+ return handle ( obj , withType ) ;
536533} ;
537534
538535/**
Original file line number Diff line number Diff line change @@ -67,6 +67,32 @@ describe('utils.test.js', function () {
6767 assert . deepEqual ( output , { value : '100.06' } ) ;
6868 } ) ;
6969
70+ it ( 'should decode with custom handler if has ref' , function ( ) {
71+ hessian . registerDecodeHandler ( 'java.math.BigDecimal' , function ( result ) {
72+ return {
73+ $class : result . $class ,
74+ $ : result . $ . value ,
75+ } ;
76+ } ) ;
77+ var o = { $class : 'java.math.BigDecimal' , $ : { value : '100.06' } } ;
78+ var map = new Map ( ) ;
79+ map . set ( 1 , o ) ;
80+ map . set ( 2 , o ) ;
81+ var buf = hessian . encode ( {
82+ $class : 'java.util.HashMap' ,
83+ $ : map
84+ } , '2.0' ) ;
85+ var output = hessian . decode ( buf , '2.0' ) ;
86+ /**
87+ * fix problem like ref object reuse
88+ */
89+ assert ( output [ 1 ] === '100.06' ) ;
90+ assert ( output [ 2 ] === '100.06' ) ;
91+ hessian . deregisterDecodeHandler ( 'java.math.BigDecimal' ) ;
92+ output = hessian . decode ( buf , '2.0' ) ;
93+ assert . deepEqual ( output , { '1' : { value : '100.06' } , '2' : { value : '100.06' } } ) ;
94+ } ) ;
95+
7096 if ( ! supportES6Map ) {
7197 return ;
7298 }
You can’t perform that action at this time.
0 commit comments