Skip to content

Commit 8fdf9f8

Browse files
authored
Remove deprecated Parameterizable interface (#1248)
JAVA-5143
1 parent 4b79188 commit 8fdf9f8

File tree

7 files changed

+6
-168
lines changed

7 files changed

+6
-168
lines changed

bson/src/main/org/bson/codecs/Parameterizable.java

-49
This file was deleted.

bson/src/main/org/bson/codecs/configuration/CodecRegistry.java

-1
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,6 @@ public interface CodecRegistry extends CodecProvider {
6464
* @throws CodecConfigurationException if no codec can be found for the given class and type arguments.
6565
* @throws AssertionError by default, if the implementation does not override this method, or if no codec can be found
6666
* for the given class and type arguments.
67-
* @see org.bson.codecs.Parameterizable
6867
* @since 4.8
6968
*/
7069
default <T> Codec<T> get(Class<T> clazz, List<Type> typeArguments) {

bson/src/main/org/bson/codecs/configuration/OverridableUuidRepresentationCodecProvider.java

+1-2
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@
2525
import java.util.List;
2626

2727
import static org.bson.assertions.Assertions.notNull;
28-
import static org.bson.internal.ProvidersCodecRegistry.getFromCodecProvider;
2928

3029
final class OverridableUuidRepresentationCodecProvider implements CodecProvider {
3130

@@ -44,7 +43,7 @@ public <T> Codec<T> get(final Class<T> clazz, final CodecRegistry registry) {
4443

4544
@Override
4645
public <T> Codec<T> get(final Class<T> clazz, final List<Type> typeArguments, final CodecRegistry registry) {
47-
Codec<T> codec = getFromCodecProvider(wrapped, clazz, typeArguments, registry);
46+
Codec<T> codec = wrapped.get(clazz, typeArguments, registry);
4847
if (codec instanceof OverridableUuidRepresentationCodec) {
4948
@SuppressWarnings("unchecked")
5049
Codec<T> codecWithUuidRepresentation = ((OverridableUuidRepresentationCodec<T>) codec).withUuidRepresentation(uuidRepresentation);

bson/src/main/org/bson/internal/ProvidersCodecRegistry.java

+2-17
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@
2222
import org.bson.codecs.configuration.CodecRegistry;
2323
import org.bson.internal.CodecCache.CodecCacheKey;
2424

25-
import javax.annotation.Nullable;
2625
import java.lang.reflect.Type;
2726
import java.util.ArrayList;
2827
import java.util.Collections;
@@ -67,7 +66,7 @@ public <T> Codec<T> get(final Class<T> clazz, final CodecRegistry registry) {
6766
@Override
6867
public <T> Codec<T> get(final Class<T> clazz, final List<Type> typeArguments, final CodecRegistry registry) {
6968
for (CodecProvider provider : codecProviders) {
70-
Codec<T> codec = getFromCodecProvider(provider, clazz, typeArguments, registry);
69+
Codec<T> codec = provider.get(clazz, typeArguments, registry);
7170
if (codec != null) {
7271
return codec;
7372
}
@@ -79,7 +78,7 @@ public <T> Codec<T> get(final ChildCodecRegistry<T> context) {
7978
CodecCacheKey codecCacheKey = new CodecCacheKey(context.getCodecClass(), context.getTypes().orElse(null));
8079
return codecCache.<T>get(codecCacheKey).orElseGet(() -> {
8180
for (CodecProvider provider : codecProviders) {
82-
Codec<T> codec = getFromCodecProvider(provider, context.getCodecClass(), context.getTypes().orElse(emptyList()), context);
81+
Codec<T> codec = provider.get(context.getCodecClass(), context.getTypes().orElse(emptyList()), context);
8382
if (codec != null) {
8483
return codecCache.putIfAbsent(codecCacheKey, codec);
8584
}
@@ -88,20 +87,6 @@ public <T> Codec<T> get(final ChildCodecRegistry<T> context) {
8887
});
8988
}
9089

91-
@Nullable
92-
@SuppressWarnings("deprecation")
93-
public static <T> Codec<T> getFromCodecProvider(final CodecProvider provider,
94-
final Class<T> clazz, final List<Type> typeArguments, final CodecRegistry registry) {
95-
Codec<T> codec = provider.get(clazz, typeArguments, registry);
96-
// `Parameterizable` is deprecated, but we still have to support it until it is removed
97-
if (codec instanceof org.bson.codecs.Parameterizable && !typeArguments.isEmpty()) {
98-
@SuppressWarnings("unchecked")
99-
Codec<T> parameterizedCodec = (Codec<T>) ((org.bson.codecs.Parameterizable) codec).parameterize(registry, typeArguments);
100-
codec = parameterizedCodec;
101-
}
102-
return codec;
103-
}
104-
10590
@Override
10691
public boolean equals(final Object o) {
10792
if (this == o) {

bson/src/test/unit/org/bson/internal/ProvidersCodecRegistrySpecification.groovy

-93
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,7 @@ import org.bson.ByteBufNIO
2525
import org.bson.codecs.Codec
2626
import org.bson.codecs.DecoderContext
2727
import org.bson.codecs.EncoderContext
28-
import org.bson.codecs.IntegerCodec
2928
import org.bson.codecs.MinKeyCodec
30-
import org.bson.codecs.Parameterizable
31-
import org.bson.codecs.ValueCodecProvider
3229
import org.bson.codecs.configuration.CodecConfigurationException
3330
import org.bson.codecs.configuration.CodecProvider
3431
import org.bson.codecs.configuration.CodecRegistry
@@ -38,12 +35,9 @@ import org.bson.types.MaxKey
3835
import org.bson.types.MinKey
3936
import spock.lang.Specification
4037

41-
import java.lang.reflect.Type
4238
import java.nio.ByteBuffer
4339

4440
import static java.util.Arrays.asList
45-
import static org.bson.codecs.ContainerCodecHelper.getCodec
46-
import static org.bson.codecs.configuration.CodecRegistries.fromCodecs
4741

4842
class ProvidersCodecRegistrySpecification extends Specification {
4943

@@ -169,93 +163,6 @@ class ProvidersCodecRegistrySpecification extends Specification {
169163
expect:
170164
((SimpleCodec) provider.get(Simple, registry)).registry.is(registry)
171165
}
172-
173-
def 'should parameterize codec'() {
174-
given:
175-
def registry = new ProvidersCodecRegistry([fromCodecs(new CollectionCodec()), new ValueCodecProvider()])
176-
177-
when:
178-
def codec = registry.get(Collection, [Integer])
179-
180-
then:
181-
codec instanceof ParameterizedCollectionCodec
182-
(codec as ParameterizedCollectionCodec).getCodec() instanceof IntegerCodec
183-
184-
when:
185-
def secondCodec = registry.get(Collection, [Integer])
186-
187-
then:
188-
codec == secondCodec
189-
}
190-
191-
def 'should parameterize codec with cycles'() {
192-
given:
193-
def registry = new ProvidersCodecRegistry([fromCodecs(new CollectionCodec()), new ValueCodecProvider()])
194-
195-
when:
196-
def codec = registry.get(Collection, [Holder.getField('c').getGenericType()])
197-
198-
then:
199-
codec instanceof ParameterizedCollectionCodec
200-
(codec as ParameterizedCollectionCodec).getCodec() instanceof LazyCodec
201-
202-
when:
203-
def secondCodec = registry.get(Collection, [Holder.getField('c').getGenericType()])
204-
205-
then:
206-
codec == secondCodec
207-
}
208-
}
209-
210-
class CollectionCodec implements Codec<Collection<?>>, Parameterizable {
211-
212-
@Override
213-
Collection<?> decode(BsonReader reader, DecoderContext decoderContext) {
214-
throw new UnsupportedOperationException()
215-
}
216-
217-
@Override
218-
void encode(BsonWriter writer, Collection<?> value, EncoderContext encoderContext) {
219-
throw new UnsupportedOperationException()
220-
}
221-
222-
@Override
223-
Class<Collection<?>> getEncoderClass() {
224-
Collection
225-
}
226-
227-
@Override
228-
Codec<?> parameterize(CodecRegistry codecRegistry, List<Type> types) {
229-
new ParameterizedCollectionCodec(getCodec(codecRegistry, types.get(0)))
230-
}
231-
}
232-
233-
class ParameterizedCollectionCodec<T> implements Codec<Collection<T>> {
234-
235-
private final Codec<T> codec
236-
237-
ParameterizedCollectionCodec(Codec<T> codec) {
238-
this.codec = codec
239-
}
240-
241-
Codec<T> getCodec() {
242-
codec
243-
}
244-
245-
@Override
246-
Collection<T> decode(BsonReader reader, DecoderContext decoderContext) {
247-
throw new UnsupportedOperationException()
248-
}
249-
250-
@Override
251-
void encode(BsonWriter writer, Collection<T> value, EncoderContext encoderContext) {
252-
throw new UnsupportedOperationException()
253-
}
254-
255-
@Override
256-
Class<Collection<T>> getEncoderClass() {
257-
Collection
258-
}
259166
}
260167

261168
class SingleCodecProvider implements CodecProvider {

driver-core/src/main/com/mongodb/Jep395RecordCodecProvider.java

+1-2
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@
2727
import java.util.List;
2828

2929
import static com.mongodb.internal.VisibleForTesting.AccessModifier.PRIVATE;
30-
import static org.bson.internal.ProvidersCodecRegistry.getFromCodecProvider;
3130

3231

3332
/**
@@ -66,7 +65,7 @@ public <T> Codec<T> get(final Class<T> clazz, final CodecRegistry registry) {
6665
@Override
6766
@Nullable
6867
public <T> Codec<T> get(final Class<T> clazz, final List<Type> typeArguments, final CodecRegistry registry) {
69-
return RECORD_CODEC_PROVIDER != null ? getFromCodecProvider(RECORD_CODEC_PROVIDER, clazz, typeArguments, registry) : null;
68+
return RECORD_CODEC_PROVIDER != null ? RECORD_CODEC_PROVIDER.get(clazz, typeArguments, registry) : null;
7069
}
7170

7271
/**

driver-core/src/main/com/mongodb/KotlinCodecProvider.java

+2-4
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,6 @@
2626
import java.util.Collections;
2727
import java.util.List;
2828

29-
import static org.bson.internal.ProvidersCodecRegistry.getFromCodecProvider;
30-
3129
/**
3230
* A CodecProvider for Kotlin data classes.
3331
* Delegates to {@code org.bson.codecs.kotlinx.KotlinSerializerCodecProvider}
@@ -76,11 +74,11 @@ public <T> Codec<T> get(final Class<T> clazz, final CodecRegistry registry) {
7674
public <T> Codec<T> get(final Class<T> clazz, final List<Type> typeArguments, final CodecRegistry registry) {
7775
Codec<T> codec = null;
7876
if (KOTLIN_SERIALIZABLE_CODEC_PROVIDER != null) {
79-
codec = getFromCodecProvider(KOTLIN_SERIALIZABLE_CODEC_PROVIDER, clazz, typeArguments, registry);
77+
codec = KOTLIN_SERIALIZABLE_CODEC_PROVIDER.get(clazz, typeArguments, registry);
8078
}
8179

8280
if (codec == null && DATA_CLASS_CODEC_PROVIDER != null) {
83-
codec = getFromCodecProvider(DATA_CLASS_CODEC_PROVIDER, clazz, typeArguments, registry);
81+
codec = DATA_CLASS_CODEC_PROVIDER.get(clazz, typeArguments, registry);
8482
}
8583
return codec;
8684
}

0 commit comments

Comments
 (0)