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,7 +529,10 @@ proto.readList = proto.readArray;
529529proto . readRef = function ( withType ) {
530530 var rid = this . readRefId ( ) ;
531531 var obj = this . refMap [ rid ] ;
532- return handle ( obj , withType ) ;
532+ if ( ! withType && obj && utils . hasOwnProperty ( obj , '$' ) ) {
533+ return handle ( obj , withType ) ;
534+ }
535+ return obj ;
533536} ;
534537
535538/**
Original file line number Diff line number Diff line change @@ -93,6 +93,34 @@ describe('utils.test.js', function () {
9393 assert . deepEqual ( output , { '1' : { value : '100.06' } , '2' : { value : '100.06' } } ) ;
9494 } ) ;
9595
96+ it ( 'should decode with custom handler if has ref and has circular ref' , function ( ) {
97+ var circularObj = { value : '100.06' } ;
98+ circularObj . ref = circularObj ;
99+ hessian . registerDecodeHandler ( 'java.test.circular' , function ( result ) {
100+ // must modify result in place to avoid circular problem
101+ return {
102+ $class : result . $class ,
103+ $ : result . $ ,
104+ } ;
105+ } ) ;
106+ var o = { $class : 'java.test.circular' , $ : circularObj } ;
107+ var map = new Map ( ) ;
108+ map . set ( 1 , o ) ;
109+ map . set ( 2 , o ) ;
110+ var buf = hessian . encode ( {
111+ $class : 'java.util.HashMap' ,
112+ $ : map
113+ } , '2.0' ) ;
114+ var output = hessian . decode ( buf , '2.0' ) ;
115+ /**
116+ * fix problem like ref object reuse
117+ */
118+ assert ( output [ 1 ] . value === '100.06' ) ;
119+ assert ( output [ 2 ] . value === '100.06' ) ;
120+ assert ( output [ 1 ] . ref . ref . ref . ref . value === '100.06' ) ;
121+ hessian . deregisterDecodeHandler ( 'java.test.circular' ) ;
122+ } ) ;
123+
96124 if ( ! supportES6Map ) {
97125 return ;
98126 }
You can’t perform that action at this time.
0 commit comments