Skip to content

Commit 6c8cf12

Browse files
committed
DATAMONGO-2156 - Remove dependency to javax.xml.bind.
We now no longer use DatatypeConverter to convert byte[] to its Base64-representation but use Spring Framework's Base64 utils.
1 parent 68d6e91 commit 6c8cf12

File tree

3 files changed

+12
-15
lines changed

3 files changed

+12
-15
lines changed

spring-data-mongodb/src/main/java/org/springframework/data/mongodb/repository/query/ExpressionEvaluatingParameterBinder.java

+7-8
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,6 @@
3333
import java.util.regex.Matcher;
3434
import java.util.regex.Pattern;
3535

36-
import javax.xml.bind.DatatypeConverter;
37-
3836
import org.bson.codecs.BinaryCodec;
3937
import org.bson.codecs.Codec;
4038
import org.bson.codecs.UuidCodec;
@@ -48,6 +46,7 @@
4846
import org.springframework.expression.spel.standard.SpelExpressionParser;
4947
import org.springframework.lang.Nullable;
5048
import org.springframework.util.Assert;
49+
import org.springframework.util.Base64Utils;
5150
import org.springframework.util.CollectionUtils;
5251
import org.springframework.util.StringUtils;
5352

@@ -571,15 +570,15 @@ static class BinaryValue extends EncodableValue {
571570

572571
private final byte[] value;
573572

574-
/*
573+
/*
575574
* (non-Javadoc)
576575
* @see org.springframework.data.mongodb.repository.query.ExpressionEvaluatingParameterBinder.EncodableValue#encode(org.springframework.data.mongodb.CodecRegistryProvider, boolean)
577576
*/
578577
@Override
579578
public String encode(CodecRegistryProvider provider, boolean quoted) {
580579

581580
if (quoted) {
582-
return DatatypeConverter.printBase64Binary(this.value);
581+
return Base64Utils.encodeToString(this.value);
583582
}
584583

585584
return encode(provider, new Binary(this.value), BinaryCodec::new);
@@ -595,7 +594,7 @@ static class BinaryCollectionValue extends EncodableValue {
595594

596595
private final Collection<byte[]> value;
597596

598-
/*
597+
/*
599598
* (non-Javadoc)
600599
* @see org.springframework.data.mongodb.repository.query.ExpressionEvaluatingParameterBinder.EncodableValue#encode(org.springframework.data.mongodb.CodecRegistryProvider, boolean)
601600
*/
@@ -613,7 +612,7 @@ static class UuidValue extends EncodableValue {
613612

614613
private final UUID value;
615614

616-
/*
615+
/*
617616
* (non-Javadoc)
618617
* @see org.springframework.data.mongodb.repository.query.ExpressionEvaluatingParameterBinder.EncodableValue#encode(org.springframework.data.mongodb.CodecRegistryProvider, boolean)
619618
*/
@@ -637,7 +636,7 @@ static class UuidCollection extends EncodableValue {
637636

638637
private final Collection<UUID> value;
639638

640-
/*
639+
/*
641640
* (non-Javadoc)
642641
* @see org.springframework.data.mongodb.repository.query.ExpressionEvaluatingParameterBinder.EncodableValue#encode(org.springframework.data.mongodb.CodecRegistryProvider, boolean)
643642
*/
@@ -655,7 +654,7 @@ static class ObjectValue extends EncodableValue {
655654

656655
private final @Nullable Object value;
657656

658-
/*
657+
/*
659658
* (non-Javadoc)
660659
* @see org.springframework.data.mongodb.repository.query.ExpressionEvaluatingParameterBinder.EncodableValue#encode(org.springframework.data.mongodb.CodecRegistryProvider, boolean)
661660
*/

spring-data-mongodb/src/test/java/org/springframework/data/mongodb/repository/query/ReactiveStringBasedMongoQueryUnitTests.java

+2-3
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,6 @@
2727
import java.util.Collections;
2828
import java.util.Map;
2929

30-
import javax.xml.bind.DatatypeConverter;
31-
3230
import org.bson.BSON;
3331
import org.bson.Document;
3432
import org.junit.Before;
@@ -53,6 +51,7 @@
5351
import org.springframework.data.repository.core.support.DefaultRepositoryMetadata;
5452
import org.springframework.data.repository.query.QueryMethodEvaluationContextProvider;
5553
import org.springframework.expression.spel.standard.SpelExpressionParser;
54+
import org.springframework.util.Base64Utils;
5655

5756
/**
5857
* Unit tests for {@link ReactiveStringBasedMongoQuery}.
@@ -219,7 +218,7 @@ public void shouldSupportNonQuotedBinaryDataReplacement() throws Exception {
219218

220219
org.springframework.data.mongodb.core.query.Query query = mongoQuery.createQuery(accesor);
221220
org.springframework.data.mongodb.core.query.Query reference = new BasicQuery("{'lastname' : { '$binary' : '"
222-
+ DatatypeConverter.printBase64Binary(binaryData) + "', '$type' : '" + BSON.B_GENERAL + "'}}");
221+
+ Base64Utils.encodeToString(binaryData) + "', '$type' : '" + BSON.B_GENERAL + "'}}");
223222

224223
assertThat(query.getQueryObject().toJson(), is(reference.getQueryObject().toJson()));
225224
}

spring-data-mongodb/src/test/java/org/springframework/data/mongodb/repository/query/StringBasedMongoQueryUnitTests.java

+3-4
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,6 @@
2929
import java.util.Map;
3030
import java.util.UUID;
3131

32-
import javax.xml.bind.DatatypeConverter;
33-
3432
import org.bson.BSON;
3533
import org.bson.Document;
3634
import org.junit.Before;
@@ -56,6 +54,7 @@
5654
import org.springframework.data.repository.core.support.DefaultRepositoryMetadata;
5755
import org.springframework.data.repository.query.QueryMethodEvaluationContextProvider;
5856
import org.springframework.expression.spel.standard.SpelExpressionParser;
57+
import org.springframework.util.Base64Utils;
5958

6059
/**
6160
* Unit tests for {@link StringBasedMongoQuery}.
@@ -318,7 +317,7 @@ public void shouldSupportNonQuotedBinaryDataReplacement() {
318317

319318
org.springframework.data.mongodb.core.query.Query query = mongoQuery.createQuery(accessor);
320319
org.springframework.data.mongodb.core.query.Query reference = new BasicQuery("{'lastname' : { '$binary' : '"
321-
+ DatatypeConverter.printBase64Binary(binaryData) + "', '$type' : '" + BSON.B_GENERAL + "'}}");
320+
+ Base64Utils.encodeToString(binaryData) + "', '$type' : '" + BSON.B_GENERAL + "'}}");
322321

323322
assertThat(query.getQueryObject().toJson(), is(reference.getQueryObject().toJson()));
324323
}
@@ -333,7 +332,7 @@ public void shouldSupportNonQuotedBinaryCollectionDataReplacement() {
333332

334333
org.springframework.data.mongodb.core.query.Query query = mongoQuery.createQuery(accessor);
335334
org.springframework.data.mongodb.core.query.Query reference = new BasicQuery("{'lastname' : { $in: [{'$binary' : '"
336-
+ DatatypeConverter.printBase64Binary(binaryData) + "', '$type' : '" + BSON.B_GENERAL + "'}] }}");
335+
+ Base64Utils.encodeToString(binaryData) + "', '$type' : '" + BSON.B_GENERAL + "'}] }}");
337336

338337
assertThat(query.getQueryObject().toJson(), is(reference.getQueryObject().toJson()));
339338
}

0 commit comments

Comments
 (0)