File tree Expand file tree Collapse file tree 2 files changed +35
-0
lines changed
Expand file tree Collapse file tree 2 files changed +35
-0
lines changed Original file line number Diff line number Diff line change @@ -416,6 +416,7 @@ proto.writeType = function (type) {
416416 var ref = this . _typeRefs . indexOf ( type ) ;
417417 if ( ref >= 0 ) {
418418 var TYPE_REF = 0x75 ; // 'u'
419+ this . byteBuffer . put ( TYPE_REF ) ;
419420 this . writeInt ( ref ) ;
420421 } else {
421422 this . _typeRefs . push ( type ) ;
Original file line number Diff line number Diff line change @@ -88,5 +88,39 @@ describe('test/special_cases.test', function() {
8888 ensureValidIdentifier ( 'a+c' ) ;
8989 } , / i n v a l i d i d e n t i f i e r \: a \+ c / ) ;
9090 } ) ;
91+
92+ it ( 'should write type with ref for the second time' , function ( ) {
93+ const encoder = hessian . encoderV2 . reset ( ) ;
94+ // writeObject
95+ encoder . _writeObjectBegin ( 'org.bson.Document' ) ;
96+ encoder . writeInt ( 2 ) ;
97+ encoder . writeString ( 'key1' ) ;
98+ encoder . writeString ( 'key2' ) ;
99+ encoder . _writeObjectBegin ( 'org.bson.Document' ) ;
100+ // writeMap key1
101+ encoder . byteBuffer . put ( 0x4d ) ;
102+ encoder . writeType ( 'org.bson.Column' ) ;
103+ encoder . byteBuffer . put ( 0x7a ) ;
104+ // writeMap key2
105+ encoder . byteBuffer . put ( 0x4d ) ;
106+ encoder . writeType ( 'org.bson.Column' ) ;
107+ encoder . byteBuffer . put ( 0x7a ) ;
108+
109+ const buf = encoder . get ( ) ;
110+ const res = hessian . decode ( buf , '2.0' , { withType : true } ) ;
111+ assert . deepEqual ( res , {
112+ $class : 'org.bson.Document' ,
113+ $ : {
114+ key1 : {
115+ $class : 'org.bson.Column' ,
116+ $ : { } ,
117+ } ,
118+ key2 : {
119+ $class : 'org.bson.Column' ,
120+ $ : { } ,
121+ } ,
122+ } ,
123+ } ) ;
124+ } ) ;
91125 } ) ;
92126} ) ;
You can’t perform that action at this time.
0 commit comments