Skip to content

Commit

Permalink
Make deprecated IterableCodec package-private
Browse files Browse the repository at this point in the history
It's still used by IterableCodecProvider, so it can't be removed entirely.
(Though IterableCodecProvider is almost entirely supplanted by CollectionCodecProvider,
it was not itself deprecated because it provides a codec for any Iterable, while
CollectionCodecProvider only provides one for any Collection, which is not quite the
same thing).

JAVA-5142
  • Loading branch information
jyemin committed Dec 4, 2023
1 parent 1a84aaa commit 7b3312a
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 29 deletions.
25 changes: 2 additions & 23 deletions bson/src/main/org/bson/codecs/IterableCodec.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,37 +31,16 @@

/**
* Encodes and decodes {@code Iterable} objects.
*
* @since 3.3
* @deprecated Prefer {@link CollectionCodecProvider}
*/
@Deprecated
@SuppressWarnings("rawtypes")
public class IterableCodec implements Codec<Iterable>, OverridableUuidRepresentationCodec<Iterable> {
class IterableCodec implements Codec<Iterable>, OverridableUuidRepresentationCodec<Iterable> {

private final CodecRegistry registry;
private final BsonTypeCodecMap bsonTypeCodecMap;
private final Transformer valueTransformer;
private final UuidRepresentation uuidRepresentation;

/**
* Construct a new instance with the given {@code CodecRegistry} and {@code BsonTypeClassMap}.
*
* @param registry the non-null codec registry
* @param bsonTypeClassMap the non-null BsonTypeClassMap
*/
public IterableCodec(final CodecRegistry registry, final BsonTypeClassMap bsonTypeClassMap) {
this(registry, bsonTypeClassMap, null);
}

/**
* Construct a new instance with the given {@code CodecRegistry} and {@code BsonTypeClassMap}.
*
* @param registry the non-null codec registry
* @param bsonTypeClassMap the non-null BsonTypeClassMap
* @param valueTransformer the value Transformer
*/
public IterableCodec(final CodecRegistry registry, final BsonTypeClassMap bsonTypeClassMap, final Transformer valueTransformer) {
IterableCodec(final CodecRegistry registry, final BsonTypeClassMap bsonTypeClassMap, final Transformer valueTransformer) {
this(registry, new BsonTypeCodecMap(notNull("bsonTypeClassMap", bsonTypeClassMap), registry), valueTransformer,
UuidRepresentation.UNSPECIFIED);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,15 +43,15 @@ class IterableCodecSpecification extends Specification {

def 'should have Iterable encoding class'() {
given:
def codec = new IterableCodec(REGISTRY, new BsonTypeClassMap())
def codec = new IterableCodec(REGISTRY, new BsonTypeClassMap(), null)

expect:
codec.getEncoderClass() == Iterable
}

def 'should encode an Iterable to a BSON array'() {
given:
def codec = new IterableCodec(REGISTRY, new BsonTypeClassMap())
def codec = new IterableCodec(REGISTRY, new BsonTypeClassMap(), null)
def writer = new BsonDocumentWriter(new BsonDocument())

when:
Expand All @@ -66,7 +66,7 @@ class IterableCodecSpecification extends Specification {

def 'should decode a BSON array to an Iterable'() {
given:
def codec = new IterableCodec(REGISTRY, new BsonTypeClassMap())
def codec = new IterableCodec(REGISTRY, new BsonTypeClassMap(), null)
def reader = new BsonDocumentReader(parse('{array : [1, 2, 3, null]}'))

when:
Expand All @@ -81,7 +81,7 @@ class IterableCodecSpecification extends Specification {

def 'should decode a BSON array of arrays to an Iterable of Iterables'() {
given:
def codec = new IterableCodec(REGISTRY, new BsonTypeClassMap())
def codec = new IterableCodec(REGISTRY, new BsonTypeClassMap(), null)
def reader = new BsonDocumentReader(parse('{array : [[1, 2], [3, 4, 5]]}'))

when:
Expand Down Expand Up @@ -116,7 +116,7 @@ class IterableCodecSpecification extends Specification {
def 'should decode binary subtype 3 for UUID'() {
given:
def reader = new BsonDocumentReader(parse(document))
def codec = new IterableCodec(fromCodecs(new UuidCodec(representation), new BinaryCodec()), new BsonTypeClassMap())
def codec = new IterableCodec(fromCodecs(new UuidCodec(representation), new BinaryCodec()), new BsonTypeClassMap(), null)
.withUuidRepresentation(representation)

when:
Expand All @@ -142,7 +142,7 @@ class IterableCodecSpecification extends Specification {
def 'should decode binary subtype 4 for UUID'() {
given:
def reader = new BsonDocumentReader(parse(document))
def codec = new IterableCodec(fromCodecs(new UuidCodec(representation), new BinaryCodec()), new BsonTypeClassMap())
def codec = new IterableCodec(fromCodecs(new UuidCodec(representation), new BinaryCodec()), new BsonTypeClassMap(), null)
.withUuidRepresentation(representation)

when:
Expand Down

0 comments on commit 7b3312a

Please sign in to comment.