Skip to content

Commit 4b79188

Browse files
authored
Remove deprecated record annotations (#1249)
JAVA-5141
1 parent 554aa93 commit 4b79188

File tree

7 files changed

+24
-235
lines changed

7 files changed

+24
-235
lines changed

bson-record-codec/src/main/org/bson/codecs/record/RecordCodec.java

Lines changed: 20 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,13 @@
2525
import org.bson.codecs.RepresentationConfigurable;
2626
import org.bson.codecs.configuration.CodecConfigurationException;
2727
import org.bson.codecs.configuration.CodecRegistry;
28-
import org.bson.codecs.record.annotations.BsonId;
29-
import org.bson.codecs.record.annotations.BsonProperty;
30-
import org.bson.codecs.record.annotations.BsonRepresentation;
28+
import org.bson.codecs.pojo.annotations.BsonCreator;
29+
import org.bson.codecs.pojo.annotations.BsonDiscriminator;
30+
import org.bson.codecs.pojo.annotations.BsonExtraElements;
31+
import org.bson.codecs.pojo.annotations.BsonId;
32+
import org.bson.codecs.pojo.annotations.BsonIgnore;
33+
import org.bson.codecs.pojo.annotations.BsonProperty;
34+
import org.bson.codecs.pojo.annotations.BsonRepresentation;
3135
import org.bson.diagnostics.Logger;
3236
import org.bson.diagnostics.Loggers;
3337

@@ -84,7 +88,6 @@ Object getValue(final Record record) throws InvocationTargetException, IllegalAc
8488
return component.getAccessor().invoke(record);
8589
}
8690

87-
@SuppressWarnings("deprecation")
8891
private static Codec<?> computeCodec(final List<Type> typeParameters, final RecordComponent component,
8992
final CodecRegistry codecRegistry) {
9093
var rawType = toWrapper(resolveComponentType(typeParameters, component));
@@ -94,11 +97,9 @@ private static Codec<?> computeCodec(final List<Type> typeParameters, final Reco
9497
: codecRegistry.get(rawType);
9598
BsonType bsonRepresentationType = null;
9699

97-
if (component.isAnnotationPresent(BsonRepresentation.class)) {
98-
bsonRepresentationType = component.getAnnotation(BsonRepresentation.class).value();
99-
} else if (isAnnotationPresentOnField(component, org.bson.codecs.pojo.annotations.BsonRepresentation.class)) {
100+
if (isAnnotationPresentOnField(component, BsonRepresentation.class)) {
100101
bsonRepresentationType = getAnnotationOnField(component,
101-
org.bson.codecs.pojo.annotations.BsonRepresentation.class).value();
102+
BsonRepresentation.class).value();
102103
}
103104
if (bsonRepresentationType != null) {
104105
if (codec instanceof RepresentationConfigurable<?> representationConfigurable) {
@@ -142,16 +143,11 @@ private static int getIndexOfTypeParameter(final String typeParameterName, final
142143
recordClass.getName(), typeParameterName));
143144
}
144145

145-
@SuppressWarnings("deprecation")
146146
private static String computeFieldName(final RecordComponent component) {
147-
if (component.isAnnotationPresent(BsonId.class)) {
147+
if (isAnnotationPresentOnField(component, BsonId.class)) {
148148
return "_id";
149-
} else if (isAnnotationPresentOnField(component, org.bson.codecs.pojo.annotations.BsonId.class)) {
150-
return "_id";
151-
} else if (component.isAnnotationPresent(BsonProperty.class)) {
152-
return component.getAnnotation(BsonProperty.class).value();
153-
} else if (isAnnotationPresentOnField(component, org.bson.codecs.pojo.annotations.BsonProperty.class)) {
154-
return getAnnotationOnField(component, org.bson.codecs.pojo.annotations.BsonProperty.class).value();
149+
} else if (isAnnotationPresentOnField(component, BsonProperty.class)) {
150+
return getAnnotationOnField(component, BsonProperty.class).value();
155151
}
156152
return component.getName();
157153
}
@@ -179,14 +175,14 @@ private static <T extends Annotation> T getAnnotationOnField(final RecordCompone
179175
}
180176

181177
private static void validateAnnotations(final RecordComponent component, final int index) {
182-
validateAnnotationNotPresentOnType(component.getDeclaringRecord(), org.bson.codecs.pojo.annotations.BsonDiscriminator.class);
183-
validateAnnotationNotPresentOnConstructor(component.getDeclaringRecord(), org.bson.codecs.pojo.annotations.BsonCreator.class);
184-
validateAnnotationNotPresentOnMethod(component.getDeclaringRecord(), org.bson.codecs.pojo.annotations.BsonCreator.class);
185-
validateAnnotationNotPresentOnFieldOrAccessor(component, org.bson.codecs.pojo.annotations.BsonIgnore.class);
186-
validateAnnotationNotPresentOnFieldOrAccessor(component, org.bson.codecs.pojo.annotations.BsonExtraElements.class);
187-
validateAnnotationOnlyOnField(component, index, org.bson.codecs.pojo.annotations.BsonId.class);
188-
validateAnnotationOnlyOnField(component, index, org.bson.codecs.pojo.annotations.BsonProperty.class);
189-
validateAnnotationOnlyOnField(component, index, org.bson.codecs.pojo.annotations.BsonRepresentation.class);
178+
validateAnnotationNotPresentOnType(component.getDeclaringRecord(), BsonDiscriminator.class);
179+
validateAnnotationNotPresentOnConstructor(component.getDeclaringRecord(), BsonCreator.class);
180+
validateAnnotationNotPresentOnMethod(component.getDeclaringRecord(), BsonCreator.class);
181+
validateAnnotationNotPresentOnFieldOrAccessor(component, BsonIgnore.class);
182+
validateAnnotationNotPresentOnFieldOrAccessor(component, BsonExtraElements.class);
183+
validateAnnotationOnlyOnField(component, index, BsonId.class);
184+
validateAnnotationOnlyOnField(component, index, BsonProperty.class);
185+
validateAnnotationOnlyOnField(component, index, BsonRepresentation.class);
190186
}
191187

192188
private static <T extends Annotation> void validateAnnotationNotPresentOnType(final Class<?> clazz,

bson-record-codec/src/main/org/bson/codecs/record/annotations/BsonId.java

Lines changed: 0 additions & 36 deletions
This file was deleted.

bson-record-codec/src/main/org/bson/codecs/record/annotations/BsonProperty.java

Lines changed: 0 additions & 42 deletions
This file was deleted.

bson-record-codec/src/main/org/bson/codecs/record/annotations/BsonRepresentation.java

Lines changed: 0 additions & 44 deletions
This file was deleted.

bson-record-codec/src/main/org/bson/codecs/record/annotations/package-info.java

Lines changed: 0 additions & 20 deletions
This file was deleted.

bson-record-codec/src/test/unit/org/bson/codecs/record/RecordCodecTest.java

Lines changed: 4 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@
3030
import org.bson.codecs.configuration.CodecRegistry;
3131
import org.bson.codecs.record.samples.TestRecordEmbedded;
3232
import org.bson.codecs.record.samples.TestRecordParameterized;
33-
import org.bson.codecs.record.samples.TestRecordWithDeprecatedAnnotations;
3433
import org.bson.codecs.record.samples.TestRecordWithIllegalBsonCreatorOnConstructor;
3534
import org.bson.codecs.record.samples.TestRecordWithIllegalBsonCreatorOnMethod;
3635
import org.bson.codecs.record.samples.TestRecordWithIllegalBsonDiscriminatorOnRecord;
@@ -66,34 +65,6 @@
6665

6766
public class RecordCodecTest {
6867

69-
@Test
70-
public void testRecordWithDeprecatedAnnotations() {
71-
var codec = createRecordCodec(TestRecordWithDeprecatedAnnotations.class, Bson.DEFAULT_CODEC_REGISTRY);
72-
var identifier = new ObjectId();
73-
var testRecord = new TestRecordWithDeprecatedAnnotations("Lucas", 14, List.of("soccer", "basketball"), identifier.toHexString());
74-
75-
var document = new BsonDocument();
76-
var writer = new BsonDocumentWriter(document);
77-
78-
// when
79-
codec.encode(writer, testRecord, EncoderContext.builder().build());
80-
81-
// then
82-
assertEquals(
83-
new BsonDocument("_id", new BsonObjectId(identifier))
84-
.append("name", new BsonString("Lucas"))
85-
.append("hobbies", new BsonArray(List.of(new BsonString("soccer"), new BsonString("basketball"))))
86-
.append("a", new BsonInt32(14)),
87-
document);
88-
assertEquals("_id", document.getFirstKey());
89-
90-
// when
91-
var decoded = codec.decode(new BsonDocumentReader(document), DecoderContext.builder().build());
92-
93-
// then
94-
assertEquals(testRecord, decoded);
95-
}
96-
9768
@Test
9869
public void testRecordWithPojoAnnotations() {
9970
var codec = createRecordCodec(TestRecordWithPojoAnnotations.class, Bson.DEFAULT_CODEC_REGISTRY);
@@ -302,9 +273,9 @@ public void testRecordWithNestedParameterizedRecordWithDifferentlyOrderedTypePar
302273

303274
@Test
304275
public void testRecordWithNulls() {
305-
var codec = createRecordCodec(TestRecordWithDeprecatedAnnotations.class, Bson.DEFAULT_CODEC_REGISTRY);
276+
var codec = createRecordCodec(TestRecordWithPojoAnnotations.class, Bson.DEFAULT_CODEC_REGISTRY);
306277
var identifier = new ObjectId();
307-
var testRecord = new TestRecordWithDeprecatedAnnotations(null, 14, null, identifier.toHexString());
278+
var testRecord = new TestRecordWithPojoAnnotations(null, 14, null, identifier.toHexString());
308279

309280
var document = new BsonDocument();
310281
var writer = new BsonDocumentWriter(document);
@@ -327,9 +298,9 @@ public void testRecordWithNulls() {
327298

328299
@Test
329300
public void testRecordWithExtraData() {
330-
var codec = createRecordCodec(TestRecordWithDeprecatedAnnotations.class, Bson.DEFAULT_CODEC_REGISTRY);
301+
var codec = createRecordCodec(TestRecordWithPojoAnnotations.class, Bson.DEFAULT_CODEC_REGISTRY);
331302
var identifier = new ObjectId();
332-
var testRecord = new TestRecordWithDeprecatedAnnotations("Felix", 13, List.of("rugby", "badminton"), identifier.toHexString());
303+
var testRecord = new TestRecordWithPojoAnnotations("Felix", 13, List.of("rugby", "badminton"), identifier.toHexString());
333304

334305
var document = new BsonDocument("_id", new BsonObjectId(identifier))
335306
.append("nationality", new BsonString("British"))

bson-record-codec/src/test/unit/org/bson/codecs/record/samples/TestRecordWithDeprecatedAnnotations.java

Lines changed: 0 additions & 36 deletions
This file was deleted.

0 commit comments

Comments
 (0)