4343import org .bson .codecs .configuration .CodecProvider ;
4444import org .bson .codecs .configuration .CodecRegistry ;
4545
46- import java .util .Collections ;
4746import java .util .HashMap ;
4847import java .util .Map ;
4948
5352 * @since 3.0
5453 */
5554public class BsonValueCodecProvider implements CodecProvider {
56- private static final Map < BsonType , Class <? extends BsonValue >> DEFAULT_BSON_TYPE_CLASS_MAP ;
55+ private static final BsonTypeClassMap DEFAULT_BSON_TYPE_CLASS_MAP ;
5756
5857 private final Map <Class <?>, Codec <?>> codecs = new HashMap <Class <?>, Codec <?>>();
5958
@@ -69,8 +68,19 @@ public BsonValueCodecProvider() {
6968 * @param bsonType the BsonType
7069 * @return the class associated with the given type
7170 */
71+ @ SuppressWarnings ("unchecked" )
7272 public static Class <? extends BsonValue > getClassForBsonType (final BsonType bsonType ) {
73- return DEFAULT_BSON_TYPE_CLASS_MAP .get (bsonType );
73+ return (Class <? extends BsonValue >) DEFAULT_BSON_TYPE_CLASS_MAP .get (bsonType );
74+ }
75+
76+ /**
77+ * Gets the BsonTypeClassMap used by this provider.
78+ *
79+ * @return the non-null BsonTypeClassMap
80+ * @since 3.3
81+ */
82+ public static BsonTypeClassMap getBsonTypeClassMap () {
83+ return DEFAULT_BSON_TYPE_CLASS_MAP ;
7484 }
7585
7686 @ Override
@@ -132,7 +142,7 @@ private <T extends BsonValue> void addCodec(final Codec<T> codec) {
132142 }
133143
134144 static {
135- Map <BsonType , Class <? extends BsonValue >> map = new HashMap <BsonType , Class <? extends BsonValue >>();
145+ Map <BsonType , Class <?>> map = new HashMap <BsonType , Class <?>>();
136146
137147 map .put (BsonType .NULL , BsonNull .class );
138148 map .put (BsonType .ARRAY , BsonArray .class );
@@ -155,6 +165,6 @@ private <T extends BsonValue> void addCodec(final Codec<T> codec) {
155165 map .put (BsonType .TIMESTAMP , BsonTimestamp .class );
156166 map .put (BsonType .UNDEFINED , BsonUndefined .class );
157167
158- DEFAULT_BSON_TYPE_CLASS_MAP = Collections . unmodifiableMap (map );
168+ DEFAULT_BSON_TYPE_CLASS_MAP = new BsonTypeClassMap (map );
159169 }
160170}
0 commit comments