@@ -20,6 +20,7 @@ package org.bson.codecs
20
20
import org.bson.BsonDocument
21
21
import org.bson.BsonDocumentReader
22
22
import org.bson.BsonDocumentWriter
23
+ import org.bson.types.Binary
23
24
import spock.lang.Specification
24
25
25
26
import static org.bson.BsonDocument.parse
@@ -85,10 +86,10 @@ class IterableCodecSpecification extends Specification {
85
86
iterable == [' 1' , ' 2' , ' 3' ]
86
87
}
87
88
88
- def ' should decode a BSON Binary with subtype of UIID_LEGACY to a UUID' () {
89
+ def ' should decode binary subtypes for UUID' () {
89
90
given :
90
91
def codec = new IterableCodec (REGISTRY , new BsonTypeClassMap (), null )
91
- def reader = new BsonDocumentReader (parse(' {array : [{ "$binary" : "D0dqZ20GeYvWzXdt0gkSlA==", "$type" : "3" }]} ' ))
92
+ def reader = new BsonDocumentReader (parse(document ))
92
93
93
94
when :
94
95
reader. readStartDocument()
@@ -97,22 +98,14 @@ class IterableCodecSpecification extends Specification {
97
98
reader. readEndDocument()
98
99
99
100
then :
100
- iterable == [UUID . fromString(' 8b79066d-676a-470f-9412-09d26d77cdd6' )]
101
+ iterable == value
102
+
103
+ where :
104
+ document | value
105
+ ' {"array": [{ "$binary" : "c3QL", "$type" : "3" }]}' | [new Binary ((byte ) 0x03 , (byte []) [115 , 116 , 11 ])]
106
+ ' {"array": [{ "$binary" : "c3QL", "$type" : "4" }]}' | [new Binary ((byte ) 0x04 , (byte []) [115 , 116 , 11 ])]
107
+ ' {"array": [{ "$binary" : "AQIDBAUGBwgJCgsMDQ4PEA==", "$type" : "3" }]}' | [UUID . fromString(' 08070605-0403-0201-100f-0e0d0c0b0a09' )]
108
+ ' {"array": [{ "$binary" : "CAcGBQQDAgEQDw4NDAsKCQ==", "$type" : "3" }]}' | [UUID . fromString(' 01020304-0506-0708-090a-0b0c0d0e0f10' )]
101
109
}
102
110
103
- def ' should decode a BSON Binary with subtype of UIID_STANDARD to a UUID' () {
104
- given :
105
- def codec = new IterableCodec (REGISTRY , new BsonTypeClassMap (), null )
106
- def reader = new BsonDocumentReader (parse(' {array : [{ "$binary" : "i3kGbWdqRw+UEgnSbXfN1g==", "$type" : "4" }]}' ))
107
-
108
- when :
109
- reader. readStartDocument()
110
- reader. readName(' array' )
111
- def iterable = codec. decode(reader, DecoderContext . builder(). build())
112
- reader. readEndDocument()
113
-
114
- then :
115
- iterable == [UUID . fromString(' 8b79066d-676a-470f-9412-09d26d77cdd6' )]
116
- }
117
-
118
- }
111
+ }
0 commit comments